Skip to content
Browse files

Added poupload command

  • Loading branch information...
1 parent 77942a5 commit 5f529b31c87c354395acac3ee376e4ccfc8f862a @Getty Getty committed
Showing with 77 additions and 0 deletions.
  1. +61 −0 lib/App/DuckPAN/Cmd/Poupload.pm
  2. +12 −0 lib/App/DuckPAN/DDG.pm
  3. +4 −0 lib/App/DuckPAN/Help.pm
View
61 lib/App/DuckPAN/Cmd/Poupload.pm
@@ -0,0 +1,61 @@
+package App::DuckPAN::Cmd::Poupload;
+# ABSTRACT: Command for uploading .po files to the DuckDuckGo Community Platform
+
+use Moo;
+with qw( App::DuckPAN::Cmd );
+
+use MooX::Options;
+use HTTP::Request::Common qw(POST);
+use LWP::UserAgent;
+use Path::Class;
+use Dist::Zilla::Util;
+
+option domain => (
+ is => 'ro',
+ format => 's',
+ predicate => 1,
+);
+
+option upload_uri => (
+ is => 'ro',
+ format => 's',
+ lazy => 1,
+ builder => 1,
+);
+
+sub _build_upload_uri { 'https://dukgo.com/translate/po/upload' }
+
+sub get_request {
+ my ( $self, $file ) = @_;
+ my ( $user, $pass ) = $self->app->ddg->get_dukgo_user_pass;
+ my $req = POST(
+ $self->upload_uri,
+ Content_Type => 'form-data',
+ Content => {
+ CAN_MULTIPART => 1,
+ HIDDENNAME => $user,
+ po_upload => [ $file ],
+ $self->has_domain ? ( token_domain => $self->domain ) : (),
+ },
+ );
+ $req->authorization_basic($user, $pass);
+ return $req;
+}
+
+sub run {
+ my ( $self, @args ) = @_;
+ for (@args) {
+ $self->upload($_);
+ }
+}
+
+sub upload {
+ my ( $self, $file ) = @_;
+ die "File not found" unless -f $file;
+ print "Uploading ".$file."... ";
+ my $response = $self->app->http->request($self->get_request($file));
+ die "Error: ".$response->code if $response->is_error || $response->is_redirect;
+ print "success!\n";
+}
+
+1;
View
12 lib/App/DuckPAN/DDG.pm
@@ -7,6 +7,18 @@ with 'App::DuckPAN::HasApp';
use Module::Pluggable::Object;
use Class::Load ':all';
+sub get_dukgo_user_pass {
+ my ( $self ) = @_;
+ my $config = $self->app->perl->get_dzil_config;
+ unless (defined $config->{'%DUKGO'}) {
+ shift->app->print_text(
+ "[ERROR] No configuration found for your https://dukgo.com/ username and password, please use: 'dzil setup' first!",
+ );
+ exit 1;
+ }
+ return $config->{'%DUKGO'}->{username}, $config->{'%DUKGO'}->{password};
+}
+
sub get_blocks_from_current_dir {
my ( $self, @args ) = @_;
unless ($self->app->get_local_ddg_version) {
View
4 lib/App/DuckPAN/Help.pm
@@ -48,6 +48,10 @@ duckpan env rm <name>
---------------------
Remove an environment variable from duckpan
+duckpan poupload
+---------------
+ Upload a po file to the Community Platform (Translation manager only)
+
duckpan release
---------------
Release the project of the current directory to DuckPAN [TODO]

0 comments on commit 5f529b3

Please sign in to comment.
Something went wrong with that request. Please try again.