shopify_oracle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/shopify_oracle/accessor/base.rb +40 -0
- data/lib/shopify_oracle/accessor/customer.rb +19 -0
- data/lib/shopify_oracle/accessor/selling_plan_group.rb +53 -0
- data/lib/shopify_oracle/accessor/subscription_contract.rb +105 -0
- data/lib/shopify_oracle/accessor/subscription_draft.rb +63 -0
- data/lib/shopify_oracle/connector/base.rb +13 -0
- data/lib/shopify_oracle/connector/mutater.rb +12 -0
- data/lib/shopify_oracle/connector/querier.rb +12 -0
- data/lib/shopify_oracle/fragments.rb +274 -0
- data/lib/shopify_oracle/mutations.rb +266 -0
- data/lib/shopify_oracle/queries.rb +111 -0
- data/lib/shopify_oracle.rb +48 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 431af632e49a61cea23e3606be12a3040b5183a351229a53cf4fc27f387d9363
|
4
|
+
data.tar.gz: 74ab32a60f133889b2ea6048672725709ffdeae8abd130beb4e8b6bb5db421e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 675da738016eb86aff429354012e318cb830feb314826137315e4b7cfd8b895f83e152587dca174cc366dad983f3d145bb6c82ee94287593dd1d42e506a1972e
|
7
|
+
data.tar.gz: e19467c647f5ce7666a6b6ddbb8f97a81b33cf90a3938da45030315b97731a022e2f435af73ab43adc32a3fbf9c654e1cc41bd1079c33ce7eb2d49771bb75224
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Accessor
|
5
|
+
class Base
|
6
|
+
class << self
|
7
|
+
def list(first: 10)
|
8
|
+
ShopifyOracle.query(class_name.underscore.pluralize, first:)
|
9
|
+
end
|
10
|
+
|
11
|
+
def find(id:)
|
12
|
+
ShopifyOracle.query(class_name.underscore, id:)
|
13
|
+
end
|
14
|
+
|
15
|
+
def class_name
|
16
|
+
name.split('::').last
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :gid, :object
|
21
|
+
|
22
|
+
def initialize(id:, object_class: Hash)
|
23
|
+
@oracle = ShopifyOracle
|
24
|
+
|
25
|
+
class_name = self.class.name.split('::').last
|
26
|
+
object_class_name = class_name.camelize(:lower)
|
27
|
+
|
28
|
+
@gid = id.is_a?(Integer) ? "gid://shopify/#{class_name}/#{id}" : id
|
29
|
+
|
30
|
+
object = self.class.find(id: @gid, oracle: @oracle).body['data'][object_class_name]
|
31
|
+
@object = JSON.parse(object.to_json, object_class:)
|
32
|
+
end
|
33
|
+
|
34
|
+
def reload
|
35
|
+
object = self.class.find(id: @gid, oracle: @oracle).body['data'][object_class]
|
36
|
+
@object = JSON.parse(object.to_json, object_class:)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Accessor
|
5
|
+
class Customer < Base
|
6
|
+
attr_reader :customer
|
7
|
+
|
8
|
+
def initialize(id:, oracle: nil)
|
9
|
+
super
|
10
|
+
@customer = @object
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload
|
14
|
+
super
|
15
|
+
@customer = @object
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Accessor
|
5
|
+
class SellingPlanGroup < Base
|
6
|
+
class << self
|
7
|
+
def create(name:)
|
8
|
+
ShopifyOracle.mutate(:create_selling_plan_group, name:)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :selling_plan_group
|
13
|
+
|
14
|
+
def initialize(id:, oracle: nil)
|
15
|
+
super
|
16
|
+
@selling_plan_group = @object
|
17
|
+
end
|
18
|
+
|
19
|
+
def reload
|
20
|
+
super
|
21
|
+
@selling_plan_group = @object
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit_name(name:)
|
25
|
+
@oracle.mutate(
|
26
|
+
:edit_selling_plan_group_name,
|
27
|
+
sellingPlanGroup: @id,
|
28
|
+
name:
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_variants(variants:)
|
33
|
+
variants = variants.map { |v| v.is_a?(Integer) ? "gid://shopify/ProductVariant/#{v}" : v }
|
34
|
+
|
35
|
+
@oracle.mutate(
|
36
|
+
:add_variants_to_selling_plan_group,
|
37
|
+
sellingPlanGroup: @gid,
|
38
|
+
variants:
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_products(products:)
|
43
|
+
products = products.map { |v| v.is_a?(Integer) ? "gid://shopify/Product/#{v}" : v }
|
44
|
+
|
45
|
+
@oracle.mutate(
|
46
|
+
:add_products_to_selling_plan_group,
|
47
|
+
sellingPlanGroup: @gid,
|
48
|
+
products:
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Naming/VariableName
|
4
|
+
# rubocop:disable Naming/MethodParameterName
|
5
|
+
module ShopifyOracle
|
6
|
+
module Accessor
|
7
|
+
class SubscriptionContract < Base
|
8
|
+
class << self
|
9
|
+
def create_v2(
|
10
|
+
customer_id:,
|
11
|
+
customerPaymentMethodId:,
|
12
|
+
oracle: nil
|
13
|
+
)
|
14
|
+
customerId = customer_id.is_a?(Integer) ? "gid://shopify/Customer/#{customer_id}" : customer_id
|
15
|
+
|
16
|
+
ShopifyOracle.mutate(
|
17
|
+
:create_subscription_contract_v2,
|
18
|
+
customerId:,
|
19
|
+
customerPaymentMethodId:
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# rubocop:disable Metrics/MethodLength
|
24
|
+
def create(
|
25
|
+
customer:, oracle: nil,
|
26
|
+
interval: 'WEEK',
|
27
|
+
intervalCount: 6,
|
28
|
+
maxCycles: 10,
|
29
|
+
minCycles: 3,
|
30
|
+
deliveryPrice: 5.50,
|
31
|
+
nextBillingDate: Time.zone.today + 30.days
|
32
|
+
)
|
33
|
+
|
34
|
+
address = customer.default_address
|
35
|
+
input = {
|
36
|
+
contract: {
|
37
|
+
billingPolicy: {
|
38
|
+
interval:,
|
39
|
+
intervalCount:,
|
40
|
+
maxCycles:,
|
41
|
+
minCycles:
|
42
|
+
},
|
43
|
+
customAttributes: [
|
44
|
+
{
|
45
|
+
key: 'key',
|
46
|
+
value: 'value'
|
47
|
+
}
|
48
|
+
],
|
49
|
+
deliveryMethod: {
|
50
|
+
shipping: {
|
51
|
+
address: {
|
52
|
+
address1: address.address1,
|
53
|
+
address2: address.address2,
|
54
|
+
city: address.city,
|
55
|
+
company: address.company,
|
56
|
+
firstName: address.first_name,
|
57
|
+
lastName: address.last_name,
|
58
|
+
phone: address.phone,
|
59
|
+
provinceCode: address.region_code,
|
60
|
+
zip: address.zip,
|
61
|
+
countryCode: address.country_code
|
62
|
+
},
|
63
|
+
shippingOption: {
|
64
|
+
code: 'abc',
|
65
|
+
description: 'description',
|
66
|
+
presentmentTitle: 'title',
|
67
|
+
title: 'title'
|
68
|
+
}
|
69
|
+
}
|
70
|
+
},
|
71
|
+
deliveryPolicy: {
|
72
|
+
interval:,
|
73
|
+
intervalCount:
|
74
|
+
},
|
75
|
+
deliveryPrice:,
|
76
|
+
nextBillingDate:,
|
77
|
+
note: 'note',
|
78
|
+
status: 'ACTIVE'
|
79
|
+
},
|
80
|
+
customerId: "gid://shopify/Customer/#{customer.ext_id}",
|
81
|
+
nextBillingDate: Time.zone.today + 30.days,
|
82
|
+
currencyCode: 'GBP'
|
83
|
+
}
|
84
|
+
|
85
|
+
ShopifyOracle.mutate(:create_subscription_contract, input:)
|
86
|
+
end
|
87
|
+
# rubocop:enable Metrics/MethodLength
|
88
|
+
end
|
89
|
+
|
90
|
+
attr_reader :contract
|
91
|
+
|
92
|
+
def initialize(id:, oracle: nil)
|
93
|
+
super
|
94
|
+
@contract = @object
|
95
|
+
end
|
96
|
+
|
97
|
+
def reload
|
98
|
+
super
|
99
|
+
@contract = @object
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
# rubocop:enable Naming/VariableName
|
105
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Naming/VariableName
|
4
|
+
# rubocop:disable Naming/MethodParameterName
|
5
|
+
module ShopifyOracle
|
6
|
+
module Accessor
|
7
|
+
class SubscriptionDraft < Base
|
8
|
+
attr_reader :draft
|
9
|
+
|
10
|
+
def initialize(id:, oracle: nil)
|
11
|
+
super
|
12
|
+
@draft = @object
|
13
|
+
end
|
14
|
+
|
15
|
+
def reload
|
16
|
+
super
|
17
|
+
@draft = @object
|
18
|
+
end
|
19
|
+
|
20
|
+
def commit
|
21
|
+
@oracle.mutate(
|
22
|
+
:subscription_draft_commit,
|
23
|
+
draftId: @gid
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_delivery_method(
|
28
|
+
address:
|
29
|
+
)
|
30
|
+
input = {
|
31
|
+
deliveryMethod: {
|
32
|
+
shipping: {
|
33
|
+
address:
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
@oracle.mutate(
|
39
|
+
:subscription_draft_update,
|
40
|
+
draftId: @gid,
|
41
|
+
input:
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_line_item(
|
46
|
+
productVariantId:,
|
47
|
+
currentPrice:,
|
48
|
+
quantity:
|
49
|
+
)
|
50
|
+
productVariantId = "gid://shopify/ProductVariant/#{productVariantId}" if productVariantId.is_a?(Integer)
|
51
|
+
input = {
|
52
|
+
productVariantId:,
|
53
|
+
quantity:,
|
54
|
+
currentPrice:
|
55
|
+
}
|
56
|
+
|
57
|
+
@oracle.mutate(:add_line_item_to_subscription_draft, draftId: @id, input:)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# rubocop:enable Naming/VariableName
|
63
|
+
# rubocop:enable Naming/MethodParameterName
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Connector
|
5
|
+
class Base
|
6
|
+
def initialize(shop:)
|
7
|
+
@shop = shop
|
8
|
+
session = ShopifyAPI::Utils::SessionUtils.load_offline_session(shop:)
|
9
|
+
@client = ShopifyAPI::Clients::Graphql::Admin.new(session:)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Connector
|
5
|
+
class Mutater < Base
|
6
|
+
def mutate(method, **args)
|
7
|
+
mutation = ShopifyOracle::Mutations.const_get("#{method.to_s.upcase}_MUTATION".to_sym)
|
8
|
+
@client.query(query: mutation, variables: args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Connector
|
5
|
+
class Querier < Base
|
6
|
+
def query(method, **args)
|
7
|
+
query = ShopifyOracle::Queries.const_get("#{method.to_s.upcase}_QUERY".to_sym)
|
8
|
+
@client.query(query:, variables: args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/ModuleLength
|
4
|
+
module ShopifyOracle
|
5
|
+
module Fragments
|
6
|
+
SELLING_PLAN_DELIVERY_POLICY = <<~GRAPHQL
|
7
|
+
fragment DeliveryPolicy on SellingPlanDeliveryPolicy {
|
8
|
+
interval
|
9
|
+
intervalCount
|
10
|
+
}
|
11
|
+
GRAPHQL
|
12
|
+
|
13
|
+
SELLING_PLAN = <<~GRAPHQL
|
14
|
+
fragment SellingPlan on SellingPlan {
|
15
|
+
id
|
16
|
+
createdAt
|
17
|
+
description
|
18
|
+
name
|
19
|
+
options
|
20
|
+
position
|
21
|
+
billingPolicy {
|
22
|
+
... on SellingPlanRecurringBillingPolicy {
|
23
|
+
createdAt
|
24
|
+
interval
|
25
|
+
intervalCount
|
26
|
+
maxCycles
|
27
|
+
minCycles
|
28
|
+
}
|
29
|
+
}
|
30
|
+
deliveryPolicy {
|
31
|
+
... on SellingPlanRecurringDeliveryPolicy {
|
32
|
+
createdAt
|
33
|
+
cutoff
|
34
|
+
intent
|
35
|
+
interval
|
36
|
+
intervalCount
|
37
|
+
}
|
38
|
+
}
|
39
|
+
pricingPolicies {
|
40
|
+
... on SellingPlanRecurringPricingPolicy {
|
41
|
+
adjustmentType
|
42
|
+
adjustmentValue
|
43
|
+
createdAt
|
44
|
+
afterCycle
|
45
|
+
}
|
46
|
+
... on SellingPlanFixedPricingPolicy {
|
47
|
+
adjustmentType
|
48
|
+
adjustmentValue {
|
49
|
+
... on MoneyV2 {
|
50
|
+
amount
|
51
|
+
currencyCode
|
52
|
+
}
|
53
|
+
... on SellingPlanPricingPolicyPercentageValue {
|
54
|
+
percentage
|
55
|
+
}
|
56
|
+
}
|
57
|
+
createdAt
|
58
|
+
}
|
59
|
+
|
60
|
+
}
|
61
|
+
}
|
62
|
+
GRAPHQL
|
63
|
+
|
64
|
+
SELLING_PLAN_GROUP = <<~GRAPHQL.freeze
|
65
|
+
#{SELLING_PLAN}
|
66
|
+
|
67
|
+
fragment SellingPlanGroup on SellingPlanGroup {
|
68
|
+
createdAt
|
69
|
+
id
|
70
|
+
description
|
71
|
+
merchantCode
|
72
|
+
name
|
73
|
+
options
|
74
|
+
position
|
75
|
+
productCount
|
76
|
+
productVariantCount
|
77
|
+
productVariants(first: $first) {
|
78
|
+
edges {
|
79
|
+
node {
|
80
|
+
id
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
summary
|
85
|
+
sellingPlans(first: $first) {
|
86
|
+
edges {
|
87
|
+
node {
|
88
|
+
...SellingPlan
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
GRAPHQL
|
94
|
+
|
95
|
+
CUSTOMER_PAYMENT_METHOD = <<~GRAPHQL
|
96
|
+
fragment CustomerPaymentMethod on CustomerPaymentMethod {
|
97
|
+
id
|
98
|
+
instrument
|
99
|
+
revokedAt
|
100
|
+
revokedReason
|
101
|
+
}
|
102
|
+
GRAPHQL
|
103
|
+
|
104
|
+
CUSTOMER = <<~GRAPHQL.freeze
|
105
|
+
#{CUSTOMER_PAYMENT_METHOD}
|
106
|
+
|
107
|
+
fragment Customer on Customer {
|
108
|
+
id
|
109
|
+
firstName
|
110
|
+
lastName
|
111
|
+
displayName
|
112
|
+
email
|
113
|
+
paymentMethods(first: 10) {
|
114
|
+
edges {
|
115
|
+
node {
|
116
|
+
...CustomerPaymentMethod
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
GRAPHQL
|
122
|
+
|
123
|
+
MONEY = <<~GRAPHQL
|
124
|
+
fragment Money on MoneyV2 {
|
125
|
+
amount
|
126
|
+
currencyCode
|
127
|
+
}
|
128
|
+
GRAPHQL
|
129
|
+
|
130
|
+
PRICING_POLICY = <<~GRAPHQL
|
131
|
+
fragment PricingPolicy on SubscriptionPricingPolicy {
|
132
|
+
basePrice {
|
133
|
+
...Money
|
134
|
+
}
|
135
|
+
cycleDiscounts {
|
136
|
+
adjustmentType
|
137
|
+
adjustmentValue
|
138
|
+
afterCycle
|
139
|
+
computedPrice {
|
140
|
+
...Money
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
GRAPHQL
|
145
|
+
|
146
|
+
BILLING_POLICY = <<~GRAPHQL
|
147
|
+
fragment BillingPolicy on SubscriptionBillingPolicy {
|
148
|
+
interval
|
149
|
+
intervalCount
|
150
|
+
maxCycles
|
151
|
+
minCycles
|
152
|
+
}
|
153
|
+
GRAPHQL
|
154
|
+
|
155
|
+
DELIVERY_POLICY = <<~GRAPHQL
|
156
|
+
fragment DeliveryPolicy on SubscriptionDeliveryPolicy {
|
157
|
+
interval
|
158
|
+
intervalCount
|
159
|
+
}
|
160
|
+
GRAPHQL
|
161
|
+
|
162
|
+
LINE_ADDED = <<~GRAPHQL.freeze
|
163
|
+
#{MONEY}
|
164
|
+
#{PRICING_POLICY}
|
165
|
+
|
166
|
+
fragment LineAdded on SubscriptionLine {
|
167
|
+
currentPrice {
|
168
|
+
...Money
|
169
|
+
}
|
170
|
+
discountAllocations {
|
171
|
+
amount {
|
172
|
+
...Money
|
173
|
+
}
|
174
|
+
discount
|
175
|
+
}
|
176
|
+
id
|
177
|
+
pricingPolicy {
|
178
|
+
...PricingPolicy
|
179
|
+
}
|
180
|
+
productId
|
181
|
+
quantity
|
182
|
+
requiresShipping
|
183
|
+
sellingPlanId
|
184
|
+
sellingPlanName
|
185
|
+
sku
|
186
|
+
taxable
|
187
|
+
title
|
188
|
+
variantId
|
189
|
+
variantImage {
|
190
|
+
url
|
191
|
+
}
|
192
|
+
variantTitle
|
193
|
+
}
|
194
|
+
GRAPHQL
|
195
|
+
|
196
|
+
SUBSCRIPTION_DRAFT = <<~GRAPHQL.freeze
|
197
|
+
#{CUSTOMER}
|
198
|
+
#{DELIVERY_POLICY}
|
199
|
+
#{BILLING_POLICY}
|
200
|
+
#{MONEY}
|
201
|
+
|
202
|
+
fragment SubscriptionDraft on SubscriptionDraft {
|
203
|
+
currencyCode
|
204
|
+
customAttributes {
|
205
|
+
key
|
206
|
+
value
|
207
|
+
}
|
208
|
+
customer {
|
209
|
+
...Customer
|
210
|
+
}
|
211
|
+
customerPaymentMethod {
|
212
|
+
id
|
213
|
+
instrument
|
214
|
+
revokedAt
|
215
|
+
revokedReason
|
216
|
+
}
|
217
|
+
billingPolicy {
|
218
|
+
...BillingPolicy
|
219
|
+
}
|
220
|
+
deliveryMethod
|
221
|
+
deliveryPolicy {
|
222
|
+
...DeliveryPolicy
|
223
|
+
}
|
224
|
+
deliveryPrice {
|
225
|
+
...Money
|
226
|
+
}
|
227
|
+
id
|
228
|
+
nextBillingDate
|
229
|
+
shippingOptions
|
230
|
+
status
|
231
|
+
}
|
232
|
+
GRAPHQL
|
233
|
+
|
234
|
+
SUBSCRIPTION_CONTRACT = <<~GRAPHQL.freeze
|
235
|
+
#{MONEY}
|
236
|
+
#{BILLING_POLICY}
|
237
|
+
#{DELIVERY_POLICY}
|
238
|
+
#{CUSTOMER}
|
239
|
+
|
240
|
+
fragment SubscriptionContract on SubscriptionContract {
|
241
|
+
id
|
242
|
+
createdAt
|
243
|
+
currencyCode
|
244
|
+
deliveryPrice {
|
245
|
+
...Money
|
246
|
+
}
|
247
|
+
lastPaymentStatus
|
248
|
+
lineCount
|
249
|
+
note
|
250
|
+
status
|
251
|
+
appAdminUrl
|
252
|
+
nextBillingDate
|
253
|
+
customAttributes {
|
254
|
+
key
|
255
|
+
value
|
256
|
+
}
|
257
|
+
billingPolicy {
|
258
|
+
...BillingPolicy
|
259
|
+
}
|
260
|
+
deliveryPolicy {
|
261
|
+
...DeliveryPolicy
|
262
|
+
}
|
263
|
+
customerPaymentMethod {
|
264
|
+
...CustomerPaymentMethod
|
265
|
+
}
|
266
|
+
customer {
|
267
|
+
...Customer
|
268
|
+
}
|
269
|
+
deliveryMethod
|
270
|
+
}
|
271
|
+
GRAPHQL
|
272
|
+
end
|
273
|
+
end
|
274
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -0,0 +1,266 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/ModuleLength
|
4
|
+
module ShopifyOracle
|
5
|
+
module Mutations
|
6
|
+
SUBSCRIPTION_DRAFT_UPDATE_MUTATION = <<~GRAPHQL
|
7
|
+
mutation($draftId: ID!, $input: SubscriptionDraftInput!) {
|
8
|
+
subscriptionDraftUpdate(
|
9
|
+
draftId: $draftId,
|
10
|
+
input: $input
|
11
|
+
) {
|
12
|
+
draft {
|
13
|
+
id
|
14
|
+
}
|
15
|
+
userErrors {
|
16
|
+
field
|
17
|
+
message
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
GRAPHQL
|
22
|
+
|
23
|
+
SUBSCRIPTION_DRAFT_COMMIT_MUTATION = <<~GRAPHQL
|
24
|
+
mutation($draftId: ID!) {
|
25
|
+
subscriptionDraftCommit(draftId: $draftId) {
|
26
|
+
contract {
|
27
|
+
id
|
28
|
+
}
|
29
|
+
userErrors {
|
30
|
+
field
|
31
|
+
message
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
GRAPHQL
|
36
|
+
|
37
|
+
ADD_LINE_ITEM_TO_SUBSCRIPTION_DRAFT_MUTATION = <<~GRAPHQL.freeze
|
38
|
+
#{ShopifyOracle::Fragments::LINE_ADDED}
|
39
|
+
|
40
|
+
mutation subscriptionDraftLineAdd($draftId: ID!, $input: SubscriptionLineInput!) {
|
41
|
+
subscriptionDraftLineAdd(draftId: $draftId, input: $input) {
|
42
|
+
draft {
|
43
|
+
id
|
44
|
+
}
|
45
|
+
lineAdded {
|
46
|
+
...LineAdded
|
47
|
+
}
|
48
|
+
userErrors {
|
49
|
+
field
|
50
|
+
message
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
GRAPHQL
|
55
|
+
|
56
|
+
CREATE_SUBSCRIPTION_CONTRACT_V2_MUTATION = <<~GRAPHQL
|
57
|
+
mutation($customerId: ID!, $customerPaymentMethodId: ID!) {
|
58
|
+
subscriptionContractCreate(
|
59
|
+
input: {
|
60
|
+
customerId: $customerId,
|
61
|
+
nextBillingDate: "2022-09-01"
|
62
|
+
currencyCode: GBP
|
63
|
+
contract: {
|
64
|
+
note: "Dear Sam, I hope you enjoy this gift."
|
65
|
+
status: ACTIVE
|
66
|
+
paymentMethodId: $customerPaymentMethodId
|
67
|
+
billingPolicy: { interval: MONTH, intervalCount: 1, minCycles: 3 }
|
68
|
+
deliveryPolicy: { interval: MONTH, intervalCount: 1 }
|
69
|
+
deliveryPrice: 14.99
|
70
|
+
deliveryMethod: {
|
71
|
+
shipping: {
|
72
|
+
address: {
|
73
|
+
firstName: "John"
|
74
|
+
lastName: "McDonald"
|
75
|
+
address1: "33 New Montgomery St"
|
76
|
+
address2: "#750"
|
77
|
+
city: "San Francisco"
|
78
|
+
province: "California"
|
79
|
+
country: "USA"
|
80
|
+
zip: "94105"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
) {
|
87
|
+
draft {
|
88
|
+
id
|
89
|
+
}
|
90
|
+
userErrors {
|
91
|
+
field
|
92
|
+
message
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
GRAPHQL
|
97
|
+
|
98
|
+
CREATE_SUBSCRIPTION_CONTRACT_MUTATION = <<~GRAPHQL.freeze
|
99
|
+
#{ShopifyOracle::Fragments::SUBSCRIPTION_DRAFT}
|
100
|
+
|
101
|
+
mutation subscriptionContractCreate($input: SubscriptionContractCreateInput!) {
|
102
|
+
subscriptionContractCreate(input: $input) {
|
103
|
+
draft {
|
104
|
+
...SubscriptionDraft
|
105
|
+
}
|
106
|
+
userErrors {
|
107
|
+
field
|
108
|
+
message
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
GRAPHQL
|
113
|
+
|
114
|
+
ADD_VARIANTS_TO_SELLING_PLAN_GROUP_MUTATION = <<~GRAPHQL
|
115
|
+
mutation($sellingPlanGroup: ID!, $variants: [ID!]!) {
|
116
|
+
sellingPlanGroupAddProductVariants(
|
117
|
+
id: $sellingPlanGroup,
|
118
|
+
productVariantIds: $variants
|
119
|
+
) {
|
120
|
+
sellingPlanGroup {
|
121
|
+
id
|
122
|
+
productVariantCount
|
123
|
+
productVariants(first: 10) {
|
124
|
+
edges {
|
125
|
+
node {
|
126
|
+
id
|
127
|
+
title
|
128
|
+
inventoryQuantity
|
129
|
+
product {
|
130
|
+
id
|
131
|
+
title
|
132
|
+
totalInventory
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
userErrors {
|
139
|
+
field
|
140
|
+
message
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
GRAPHQL
|
145
|
+
|
146
|
+
ADD_PRODUCTS_TO_SELLING_PLAN_GROUP_MUTATION = <<~GRAPHQL
|
147
|
+
mutation($sellingPlanGroup: ID!, $products: [ID!]!) {
|
148
|
+
sellingPlanGroupAddProducts(
|
149
|
+
id: $sellingPlanGroup,
|
150
|
+
productIds: $products
|
151
|
+
) {
|
152
|
+
sellingPlanGroup {
|
153
|
+
id
|
154
|
+
productVariantCount
|
155
|
+
productVariants(first: 10) {
|
156
|
+
edges {
|
157
|
+
node {
|
158
|
+
id
|
159
|
+
title
|
160
|
+
inventoryQuantity
|
161
|
+
product {
|
162
|
+
id
|
163
|
+
title
|
164
|
+
totalInventory
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
168
|
+
}
|
169
|
+
}
|
170
|
+
userErrors {
|
171
|
+
field
|
172
|
+
message
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
GRAPHQL
|
177
|
+
|
178
|
+
EDIT_SELLING_PLAN_GROUP_NAME_MUTATION = <<~GRAPHQL
|
179
|
+
mutation($sellingPlanGroup: ID!, $name: String!) {
|
180
|
+
sellingPlanGroupUpdate(
|
181
|
+
id: $sellingPlanGroup
|
182
|
+
input: { name: $name }
|
183
|
+
) {
|
184
|
+
sellingPlanGroup {
|
185
|
+
id
|
186
|
+
name
|
187
|
+
}
|
188
|
+
userErrors {
|
189
|
+
field
|
190
|
+
message
|
191
|
+
}
|
192
|
+
}
|
193
|
+
}
|
194
|
+
GRAPHQL
|
195
|
+
|
196
|
+
CREATE_SELLING_PLAN_GROUP_MUTATION = <<~GRAPHQL
|
197
|
+
mutation($name: String!) {
|
198
|
+
sellingPlanGroupCreate(
|
199
|
+
input: {
|
200
|
+
name: $name,
|
201
|
+
merchantCode: "subscribe-and-save"
|
202
|
+
options: ["Delivery every"]
|
203
|
+
position: 1
|
204
|
+
sellingPlansToCreate: [
|
205
|
+
{
|
206
|
+
name: "Delivered every week"
|
207
|
+
options: "1 Week(s)"
|
208
|
+
position: 1
|
209
|
+
billingPolicy: { recurring: { interval: WEEK, intervalCount: 1 } }
|
210
|
+
deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 1 } }
|
211
|
+
pricingPolicies: [
|
212
|
+
{
|
213
|
+
fixed: {
|
214
|
+
adjustmentType: PERCENTAGE
|
215
|
+
adjustmentValue: { percentage: 15.0 }
|
216
|
+
}
|
217
|
+
}
|
218
|
+
]
|
219
|
+
}
|
220
|
+
{
|
221
|
+
name: "Delivered every six weeks"
|
222
|
+
options: "6 Week(s)"
|
223
|
+
position: 2
|
224
|
+
billingPolicy: { recurring: { interval: WEEK, intervalCount: 6 } }
|
225
|
+
deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 6 } }
|
226
|
+
pricingPolicies: [
|
227
|
+
{
|
228
|
+
fixed: {
|
229
|
+
adjustmentType: PERCENTAGE
|
230
|
+
adjustmentValue: { percentage: 10.0 }
|
231
|
+
}
|
232
|
+
}
|
233
|
+
]
|
234
|
+
}
|
235
|
+
{
|
236
|
+
name: "Delivered every three weeks"
|
237
|
+
options: "3 Week(s)"
|
238
|
+
position: 3
|
239
|
+
billingPolicy: { recurring: { interval: WEEK, intervalCount: 3 } }
|
240
|
+
deliveryPolicy: { recurring: { interval: WEEK, intervalCount: 3 } }
|
241
|
+
pricingPolicies: [
|
242
|
+
{
|
243
|
+
fixed: {
|
244
|
+
adjustmentType: PERCENTAGE
|
245
|
+
adjustmentValue: { percentage: 5.0 }
|
246
|
+
}
|
247
|
+
}
|
248
|
+
]
|
249
|
+
}
|
250
|
+
]
|
251
|
+
}
|
252
|
+
resources: { productIds: [], productVariantIds: [] }
|
253
|
+
) {
|
254
|
+
sellingPlanGroup {
|
255
|
+
id
|
256
|
+
}
|
257
|
+
userErrors {
|
258
|
+
field
|
259
|
+
message
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
GRAPHQL
|
264
|
+
end
|
265
|
+
end
|
266
|
+
# rubocop:enable Metrics/ModuleLength
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ShopifyOracle
|
4
|
+
module Queries
|
5
|
+
CUSTOMERS_QUERY = <<~GRAPHQL
|
6
|
+
#{ShopifyOracle::Fragments::CUSTOMER}
|
7
|
+
|
8
|
+
query($first: Int = 10) {
|
9
|
+
customers(first: $first) {
|
10
|
+
edges {
|
11
|
+
node {
|
12
|
+
...Customer
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
GRAPHQL
|
18
|
+
|
19
|
+
CUSTOMER_QUERY = <<~GRAPHQL.freeze
|
20
|
+
#{ShopifyOracle::Fragments::CUSTOMER}
|
21
|
+
|
22
|
+
query($id: ID!) {
|
23
|
+
customer(id: $id) {
|
24
|
+
...Customer
|
25
|
+
}
|
26
|
+
}
|
27
|
+
GRAPHQL
|
28
|
+
|
29
|
+
SUBSCRIPTION_DRAFT_QUERY = <<~GRAPHQL.freeze
|
30
|
+
#{ShopifyOracle::Fragments::SUBSCRIPTION_DRAFT}
|
31
|
+
|
32
|
+
query($id: ID!) {
|
33
|
+
subscriptionDraft(id: $id) {
|
34
|
+
...SubscriptionDraft
|
35
|
+
}
|
36
|
+
}
|
37
|
+
GRAPHQL
|
38
|
+
|
39
|
+
SUBSCRIPTION_CONTRACTS_QUERY = <<~GRAPHQL.freeze
|
40
|
+
#{ShopifyOracle::Fragments::SUBSCRIPTION_CONTRACT}
|
41
|
+
|
42
|
+
query($first: Int = 10) {
|
43
|
+
subscriptionContracts(first: $first) {
|
44
|
+
edges {
|
45
|
+
node {
|
46
|
+
...SubscriptionContract
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
GRAPHQL
|
52
|
+
|
53
|
+
SUBSCRIPTION_CONTRACT_QUERY = <<~GRAPHQL.freeze
|
54
|
+
#{ShopifyOracle::Fragments::SUBSCRIPTION_CONTRACT}
|
55
|
+
|
56
|
+
query($id: ID!) {
|
57
|
+
subscriptionContract(id: $id) {
|
58
|
+
...SubscriptionContract
|
59
|
+
}
|
60
|
+
}
|
61
|
+
GRAPHQL
|
62
|
+
|
63
|
+
SELLING_PLAN_GROUP_QUERY = <<~GRAPHQL.freeze
|
64
|
+
#{ShopifyOracle::Fragments::SELLING_PLAN_GROUP}
|
65
|
+
|
66
|
+
query($id: ID!, $first: Int = 10) {
|
67
|
+
sellingPlanGroup(id: $id) {
|
68
|
+
...SellingPlanGroup
|
69
|
+
}
|
70
|
+
}
|
71
|
+
GRAPHQL
|
72
|
+
|
73
|
+
SELLING_PLAN_GROUPS_QUERY = <<~GRAPHQL.freeze
|
74
|
+
#{ShopifyOracle::Fragments::SELLING_PLAN_GROUP}
|
75
|
+
|
76
|
+
query($first: Int = 10) {
|
77
|
+
sellingPlanGroups(first: $first) {
|
78
|
+
edges {
|
79
|
+
node {
|
80
|
+
...SellingPlanGroup
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
GRAPHQL
|
86
|
+
|
87
|
+
SELLING_PLAN_QUERY = <<~GRAPHQL.freeze
|
88
|
+
#{ShopifyOracle::Fragments::SELLING_PLAN}
|
89
|
+
|
90
|
+
query($id: ID!, $first: Int = 10) {
|
91
|
+
sellingPlan(id: $id) {
|
92
|
+
...SellingPlan
|
93
|
+
}
|
94
|
+
}
|
95
|
+
GRAPHQL
|
96
|
+
|
97
|
+
SELLING_PLANS_QUERY = <<~GRAPHQL.freeze
|
98
|
+
#{ShopifyOracle::Fragments::SELLING_PLAN}
|
99
|
+
|
100
|
+
query($first: Int = 10) {
|
101
|
+
sellingPlans(first: $first) {
|
102
|
+
edges {
|
103
|
+
node {
|
104
|
+
...SellingPlan
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
GRAPHQL
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shopify_api'
|
4
|
+
require 'shopify_oracle/connector/base'
|
5
|
+
require 'shopify_oracle/connector/querier'
|
6
|
+
require 'shopify_oracle/connector/mutater'
|
7
|
+
require 'shopify_oracle/fragments'
|
8
|
+
require 'shopify_oracle/mutations'
|
9
|
+
require 'shopify_oracle/queries'
|
10
|
+
require 'shopify_oracle/accessor/base'
|
11
|
+
require 'shopify_oracle/accessor/customer'
|
12
|
+
require 'shopify_oracle/accessor/selling_plan_group'
|
13
|
+
require 'shopify_oracle/accessor/subscription_contract'
|
14
|
+
require 'shopify_oracle/accessor/subscription_draft'
|
15
|
+
|
16
|
+
module ShopifyOracle
|
17
|
+
@shop = nil
|
18
|
+
@connector = nil
|
19
|
+
@querier = nil
|
20
|
+
@mutater = nil
|
21
|
+
@initialized = false
|
22
|
+
|
23
|
+
class << self
|
24
|
+
attr_accessor :shop
|
25
|
+
|
26
|
+
def build(shop: nil)
|
27
|
+
@shop = shop if @shop.nil? && shop.present?
|
28
|
+
|
29
|
+
shop ||= @shop
|
30
|
+
|
31
|
+
@querier = ShopifyOracle::Connector::Querier.new(shop:)
|
32
|
+
@mutater = ShopifyOracle::Connector::Mutater.new(shop:)
|
33
|
+
@initialized = true
|
34
|
+
end
|
35
|
+
|
36
|
+
def query(query, **args)
|
37
|
+
raise 'ShopifyOracle not initialized' unless @initialized
|
38
|
+
|
39
|
+
@querier.query(query, variables: args)
|
40
|
+
end
|
41
|
+
|
42
|
+
def mutate(mutation, **args)
|
43
|
+
raise 'ShopifyOracle not initialized' unless @initialized
|
44
|
+
|
45
|
+
@mutator.mutate(mutation, variables: args)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify_oracle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yari Labs
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shopify_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10'
|
27
|
+
description: A simple gem to facilitate interacting with the Shopify GraphQL API
|
28
|
+
email: dev@yarilabs.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/shopify_oracle.rb
|
34
|
+
- lib/shopify_oracle/accessor/base.rb
|
35
|
+
- lib/shopify_oracle/accessor/customer.rb
|
36
|
+
- lib/shopify_oracle/accessor/selling_plan_group.rb
|
37
|
+
- lib/shopify_oracle/accessor/subscription_contract.rb
|
38
|
+
- lib/shopify_oracle/accessor/subscription_draft.rb
|
39
|
+
- lib/shopify_oracle/connector/base.rb
|
40
|
+
- lib/shopify_oracle/connector/mutater.rb
|
41
|
+
- lib/shopify_oracle/connector/querier.rb
|
42
|
+
- lib/shopify_oracle/fragments.rb
|
43
|
+
- lib/shopify_oracle/mutations.rb
|
44
|
+
- lib/shopify_oracle/queries.rb
|
45
|
+
homepage: https://rubygems.org/gems/shopify_oracle
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.3.15
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Oracle
|
68
|
+
test_files: []
|