Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Added poupload command
Browse files Browse the repository at this point in the history
  • Loading branch information
Getty committed Jun 11, 2013
1 parent 77942a5 commit 5f529b3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
61 changes: 61 additions & 0 deletions 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;
12 changes: 12 additions & 0 deletions lib/App/DuckPAN/DDG.pm
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions lib/App/DuckPAN/Help.pm
Expand Up @@ -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]
Expand Down

0 comments on commit 5f529b3

Please sign in to comment.