| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use WWW::Shopify; | ||
| 7 | |||
| 8 | package WWW::Shopify::Model::Webhook; | ||
| 9 | use parent "WWW::Shopify::Model::Item"; | ||
| 10 | |||
| 11 | my $fields; sub fields { return $fields; } | ||
| 12 | BEGIN { $fields = { | ||
| 13 | "format" => new WWW::Shopify::Field::String("(xml|json)"), | ||
| 14 | "address" => new WWW::Shopify::Field::String::URL(), | ||
| 15 | "topic" => new WWW::Shopify::Field::String::Enum( | ||
| 16 | qw( | ||
| 17 | orders/create orders/delete orders/updated orders/paid orders/cancelled orders/fulfilled orders/partially_fulfilled carts/create | ||
| 18 | carts/update checkouts/create checkouts/update checkouts/delete products/create products/update | ||
| 19 | products/delete collections/create collections/update collections/delete customer_groups/create | ||
| 20 | customer_groups/update customer_groups/delete customers/create customers/enable customers/disable | ||
| 21 | customers/update customers/delete fulfillments/create fulfillments/update shop/update app/uninstalled refunds/create | ||
| 22 | themes/create themes/delete themes/publish themes/update draft_orders/create draft_orders/delete draft_orders/update | ||
| 23 | |||
| 24 | ) | ||
| 25 | ), | ||
| 26 | "id" => new WWW::Shopify::Field::Identifier(), | ||
| 27 | "created_at" => new WWW::Shopify::Field::Date(), | ||
| 28 | "updated_at" => new WWW::Shopify::Field::Date() | ||
| 29 | }; } | ||
| 30 | |||
| 31 | my $queries; sub queries { return $queries; } | ||
| 32 | BEGIN { $queries = { | ||
| 33 | topic => new WWW::Shopify::Query::Match('topic') | ||
| 34 | }; } | ||
| 35 | |||
| 36 | |||
| 37 | # Looks at the topic to termine which package it's related to. | ||
| 38 | sub related_packages { | ||
| 39 | my ($self) = @_; | ||
| 40 | return ('WWW::Shopify::Model::Order') if $self->topic =~ m/^orders/; | ||
| 41 | return ('WWW::Shopify::Model::Checkout') if $self->topic =~ m/^checkout/; | ||
| 42 | return ('WWW::Shopify::Model::Product') if $self->topic =~ m/^product/; | ||
| 43 | return ('WWW::Shopify::Model::CustomerGroup') if $self->topic =~ m/^customer_groups/; | ||
| 44 | return ('WWW::Shopify::Model::Customer') if $self->topic =~ m/^customers/; | ||
| 45 | return ('WWW::Shopify::Model::Order::Fulfillment') if $self->topic =~ m/^fulfillments/; | ||
| 46 | return ('WWW::Shopify::Model::Shop') if $self->topic =~ m/^shop/; | ||
| 47 | return ('WWW::Shopify::Model::Refund') if $self->topic =~ m/^refunds/; | ||
| 48 | return ('WWW::Shopify::Model::Theme') if $self->topic =~ m/^themes/; | ||
| 49 | return ('WWW::Shopify::Model::DraftOrder') if $self->topic =~ m/^draft_orders/; | ||
| 50 | return ('WWW::Shopify::Model::SmartCollection', 'WWW::Shopify::Model::CustomCollection') if $self->topic =~ m/^collections/; | ||
| 51 | return (); | ||
| 52 | } | ||
| 53 | |||
| 54 | sub creation_minimal { return qw(address topic format); } | ||
| 55 | sub creation_filled { return qw(created_at); } | ||
| 56 | sub update_filled { return qw(updated_at); } | ||
| 57 | sub update_fields { return qw(address topic format); } | ||
| 58 | sub valid_topics { return @{$_[0]->fields->{topic}->{arguments}}; } | ||
| 59 | |||
| 60 | eval(__PACKAGE__->generate_accessors); die $@ if $@; | ||
| 61 | |||
| 62 | 1 |