| 1 | #!/usr/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use WWW::Shopify::Tools::Themer; | ||
| 6 | |||
| 7 | package Padre::Plugin::Shopify::Themer; | ||
| 8 | use parent 'WWW::Shopify::Tools::Themer'; | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my ($package, $task, $settings) = @_; | ||
| 12 | my $self = $package->SUPER::new($settings); | ||
| 13 | $self->{task} = $task; | ||
| 14 | return $self; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub log { | ||
| 18 | my ($self, $message) = @_; | ||
| 19 | chomp($message); | ||
| 20 | $self->{task}->tell_status($message); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub task { return shift->{task}; } | ||
| 24 | |||
| 25 | package Padre::Plugin::Shopify::Task; | ||
| 26 | use parent 'Padre::Task'; | ||
| 27 | |||
| 28 | sub new { | ||
| 29 | my $package = shift; | ||
| 30 | my $self = $package->SUPER::new(@_); | ||
| 31 | my %settings = @_; | ||
| 32 | my ($action, $project) = ($settings{action}, $settings{project}); | ||
| 33 | $self->{action} = $action; | ||
| 34 | $self->{directory} = $project->directory; | ||
| 35 | $self->{email} = $project->email; | ||
| 36 | $self->{password} = $project->password; | ||
| 37 | $self->{url} = $project->url; | ||
| 38 | $self->{api_key} = $project->api_key; | ||
| 39 | $self->{manifest} = $project->manifest; | ||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub run { | ||
| 44 | my ($self) = @_; | ||
| 45 | my $action = $self->{action}; | ||
| 46 | if ($action =~ m/(\w+):?(\d*)/) { | ||
| 47 | my ($action, $id) = ($1, $2); | ||
| 48 | eval { | ||
| 49 | my $themer = Padre::Plugin::Shopify::Themer->new($self, $self->{email} ? | ||
| 50 | { email => $self->{email}, password => $self->{password}, url => $self->{url}, directory => $self->{directory} } : | ||
| 51 | { apikey => $self->{api_key}, password => $self->{password}, url => $self->{url}, directory => $self->{directory} } | ||
| 52 | ); | ||
| 53 | eval { | ||
| 54 | if ($id) { | ||
| 55 | $themer->$action(new WWW::Shopify::Model::Theme({ id => $id })); | ||
| 56 | } | ||
| 57 | else { | ||
| 58 | $themer->$action; | ||
| 59 | } | ||
| 60 | }; | ||
| 61 | if (my $exception = $@) { | ||
| 62 | my $string = $themer->read_exception($exception); | ||
| 63 | $themer->log("Error: $string"); | ||
| 64 | } | ||
| 65 | $themer->manifest->save($self->{directory} . "/.shopmanifest"); | ||
| 66 | $self->{manifest} = $themer->manifest; | ||
| 67 | }; | ||
| 68 | if (my $e = $@) { | ||
| 69 | $self->{task}->tell_status("Error: Unable to instantiate themer: $e"); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | return 1; | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; |