| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # All the extra functionality relating to the admin panel should go in here. | ||||||||||||||||||||||||||||||||
| 8 | package WWW::Shopify::Login; | ||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent 'WWW::Shopify'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | sub get_all { | ||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my ($self, $package, $hash) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | if ($package =~ m/LocaleTranslation/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | $hash->{locale_id} = $hash->{parent}->id if $hash->{parent}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||
| 16 | 0 | return shift->SUPER::get_all(@_); | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | # Used for the login version. | ||||||||||||||||||||||||||||||||
| 21 | # X-Shopify-Api-Features:pagination-headers, embed-metafields, include-image-token. | ||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub embed_metafields { if (defined $_[1]) { $_[0]->{embed_metafields} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{embed_metafields}; } | ||||||||||||||||||||||||||||||
|
Subroutine
embed_metafields: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub include_image_token { if (defined $_[1]) { $_[0]->{include_image_token} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_image_token}; } | ||||||||||||||||||||||||||||||
|
Subroutine
include_image_token: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub pagination_headers { if (defined $_[1]) { $_[0]->{pagination_headers} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{pagination_headers}; } | ||||||||||||||||||||||||||||||
|
Subroutine
pagination_headers: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub include_variant_summary { if (defined $_[1]) { $_[0]->{include_variant_summary} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_variant_summary}; } | ||||||||||||||||||||||||||||||
|
Subroutine
include_variant_summary: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub include_gift_cards { if (defined $_[1]) { $_[0]->{include_gift_cards} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{include_gift_cards}; } | ||||||||||||||||||||||||||||||
|
Subroutine
include_gift_cards: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub future_publishables { if (defined $_[1]) { $_[0]->{future_publishables} = $_[1]; $_[0]->update_x_shopify_api_features; } return $_[0]->{future_publishables}; } | ||||||||||||||||||||||||||||||
|
Subroutine
future_publishables: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | sub x_shopify_api_headers { | ||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $_[0]->embed_metafields($_[1]); | ||||||||||||||||||||||||||||||
|
Subroutine
x_shopify_api_headers: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 31 | 0 | $_[0]->include_image_token($_[1]); | |||||||||||||||||||||||||||||||
| 32 | 0 | $_[0]->pagination_headers($_[1]); | |||||||||||||||||||||||||||||||
| 33 | 0 | $_[0]->include_variant_summary($_[1]); | |||||||||||||||||||||||||||||||
| 34 | 0 | $_[0]->include_gift_cards($_[1]); | |||||||||||||||||||||||||||||||
| 35 | 0 | $_[0]->future_publishables($_[1]); | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | sub update_x_shopify_api_features { | ||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
update_x_shopify_api_features: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my @list = ( | ||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||
| 41 | ($_[0]->embed_metafields ? ('embed-metafields') : ()), | ||||||||||||||||||||||||||||||||
| 42 | ($_[0]->pagination_headers ? ('pagination-headers') : ()), | ||||||||||||||||||||||||||||||||
| 43 | ($_[0]->include_image_token ? ('include-image-token') : ()), | ||||||||||||||||||||||||||||||||
| 44 | ($_[0]->include_variant_summary ? ('include-variant-summary') : ()), | ||||||||||||||||||||||||||||||||
| 45 | ($_[0]->include_gift_cards ? ('include-gift-cards') : ()), | ||||||||||||||||||||||||||||||||
| 46 | ($_[0]->future_publishables ? ('future-publishables') : ()), | ||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (int(@list) == 0 && $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
int @list == 0 and $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
MC/DC0%0/2
int @list == 0 and $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
int @list == 0
$self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
Truth table0%0/3
A and B
A= int @list == 0B= $self->url_handler->{"_default_headers"}{"X-Shopify-Api-Features"}
| |||||||||||||||||||||||||||||||||
| 49 | 0 | delete $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'}; | |||||||||||||||||||||||||||||||
| 50 | 0 | delete $self->url_handler->{_default_headers}->{'X-Requested-With'}; | |||||||||||||||||||||||||||||||
| 51 | } elsif (int(@list) > 0) { | ||||||||||||||||||||||||||||||||
| 52 | 0 | $self->url_handler->{_default_headers}->{'X-Shopify-Api-Features'} = join(", ", @list); | |||||||||||||||||||||||||||||||
| 53 | 0 | $self->url_handler->{_default_headers}->{'X-Requested-With'} = "XMLHttpRequest"; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | # Takes in a list of locales. | ||||||||||||||||||||||||||||||||
| 57 | sub create_update_locale_translation { | ||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my ($self, @locales) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
create_update_locale_translation: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 59 | 0 | my @english_translation = $self->get_english_translation; | |||||||||||||||||||||||||||||||
| 60 | 0 | my %hash = map { $_->english => $_->text } @locales; | |||||||||||||||||||||||||||||||
| 61 | 0 | my %mapping = (); | |||||||||||||||||||||||||||||||
| 62 | 0 | foreach my $english (@english_translation) { | |||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $mapping{$english->id} = exists $hash{$english->english} ? $hash{$english->english} : ""; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | 0 | my $locale_id = $locales[0]->locale_id; | |||||||||||||||||||||||||||||||
| 66 | 0 | my ($decoded, $response) = $self->use_url('put', "/admin/locales/$locale_id.json", { s => \%mapping }); | |||||||||||||||||||||||||||||||
| 67 | 0 | my $package = "WWW::Shopify::Model::Locale"; | |||||||||||||||||||||||||||||||
| 68 | 0 | my $object = $package->from_json($decoded->{$package->singular}, $self); | |||||||||||||||||||||||||||||||
| 69 | 0 | return $object; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | sub get_english_translation { | ||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_english_translation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 74 | 0 | my $package = "WWW::Shopify::Model::LocaleTranslation"; | |||||||||||||||||||||||||||||||
| 75 | 0 | my ($decoded, $response) = $self->use_url('get', "/admin/locale_translations/english_translations.json"); | |||||||||||||||||||||||||||||||
| 76 | 0 | return map { my $object = $package->from_json($_, $self); $object; } @{$decoded->{$package->plural}}; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | sub create { | ||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | my ($self, $item, $hash) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return shift->SUPER::create(@_) unless ref($item) =~ m/LocaleTranslation/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | sub send_activation_links { | ||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my ($self, @customers) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
send_activation_links: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 87 | 0 | my ($decoded, $response) = $self->use_url('put', "/admin/customers/set", { operation => "invite", 'customer_ids[]' => [map { $_->id } @customers] }, 1, "application/x-www-form-urlencoded"); | |||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | die new WWW::Shopify::Exception("Unexpected Response.") unless $decoded->{message} =~ m/Invited (\d+) customer/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 0 | return $1; | |||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | sub get_activation_link { | ||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my ($self, $customer) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_activation_link: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 94 | 0 | my ($decoded, $reponse) = $self->use_url('get', "/admin/customers/" . $customer->id, { }, "text/html"); | |||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find activation link for " . $customer->id . ".") unless $decoded =~ m/http:\/\/[\w\.]+\/account\/activate\/\w+/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 96 | 0 | return $&; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | sub get_reset_token { | ||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ($self, $customer) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_reset_token: not called CC=2 SCAR=12.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 101 | 0 | my ($decoded, $response) = $self->use_url('get', "/admin/customers/" . $customer->id, { }, "text/html"); | |||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 103 | 0 | print STDERR Dumper($response); | |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | die new WWW::Shopify::Exception("Unable to find activation link for " . $customer->id . ".") unless $decoded =~ m/http:\/\/[\w\.]+\/account\/activate\/(\w+)/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | 0 | return $1; | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | sub send_activation_link { | ||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | my ($self, $customer, $from, $subject, $body, $reset_token) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
send_activation_link: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 110 | 0 | my ($decoded, $response) = $self->use_url('post', "/admin/customers/" . $customer->id . "/invite", { | |||||||||||||||||||||||||||||||
| 111 | utf => '✓', | ||||||||||||||||||||||||||||||||
| 112 | source => 'adminnext', | ||||||||||||||||||||||||||||||||
| 113 | 'customer_invite_message[from]' => $from, | ||||||||||||||||||||||||||||||||
| 114 | 'customer_invite_message[subject]' => $subject, | ||||||||||||||||||||||||||||||||
| 115 | 'customer_invite_message[body]' => $body, | ||||||||||||||||||||||||||||||||
| 116 | 'customer_invite_message[reset_token]' => $reset_token | ||||||||||||||||||||||||||||||||
| 117 | }, "application/x-www-form-urlencoded"); | ||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 1 | 1; | |||||||||||||||||||||||||||||||