Skip to content

Instantly share code, notes, and snippets.

@phillipoertel
Last active November 29, 2019 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipoertel/533b9bc49c06f8a4838ae2d9fd7e45e1 to your computer and use it in GitHub Desktop.
Save phillipoertel/533b9bc49c06f8a4838ae2d9fd7e45e1 to your computer and use it in GitHub Desktop.
Perl script to submit Omegametrix' test results to Cerascreen
sub sendFTPs($) {
my $lftpfile = shift;
# apt install liblwp-protocol-https-perl libfile-slurp-perl
use HTTP::Request qw();
use HTTP::Headers qw();
use LWP::UserAgent ();
use File::Slurp qw(read_file);
# Cerascreen hostnames:
# Production: https://my.cerascreen.de
# Staging: https://staging.cerascreen.njiuko.com
# Local dev: http://localhost:3000
my $host = 'https://my.cerascreen.de';
my $headers = HTTP::Headers->new;
# Set content type
$headers->header('Content-Type' => 'text/csv');
# Set POST data
my $post_body = read_file($lftpfile);
# Set authorization
my $username = 'TODO-SET-USERNAME';
my $password = 'TODO-SET-PASSWORD';
$headers->authorization_basic($username, $password);
# Do request
my $request = HTTP::Request->new('PUT', "$host/api/v1/lab_results/omegametrix.csv", $headers, $post_body);
my $user_agent = LWP::UserAgent->new;
my $response = $user_agent->request($request);
# use Data::Dumper;
# die Dumper($response);
# Print response
#
# Example:
# {
# "succeeded": [
# "BE7VUZ"
# ],
# "errors": {
# "VIQTRE": "not_found",
# "A1Z6K9": "not_found",
# "TC478Q": "not_found",
# "U3IXQN": "not_found"
# }
# }
print $response->decoded_content . "\n";
}
# Example usage
#sendFTPs('/Users/work/Downloads/omegametrix.csv');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment