lucid_shopify-resource 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -3
- data/lib/lucid_shopify/resource/base.rb +26 -13
- data/lib/lucid_shopify/resource/create.rb +3 -1
- data/lib/lucid_shopify/resource/delete.rb +3 -3
- data/lib/lucid_shopify/resource/read.rb +2 -3
- data/lib/lucid_shopify/resource/update.rb +3 -1
- data/lib/lucid_shopify/resource/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40a00b5c2ef9edac2d54be5ad00be475050abc49e0036cbecf6c3c82fc2e487d
|
4
|
+
data.tar.gz: 8377b1e7a55ce874d5411cf925ebc2d32e9d4982d273aec34eeceb4bf6a119aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a803b745e506d29e10e85fc51ad0069942c309f27d04cf9c9a60a70f68cc5dce68412e001598ce32685c3c672a871448cdedf7a6a97fc39a04b2bd353b3444ee
|
7
|
+
data.tar.gz: 1a60769e2ad0da5057d824e5906ff525e2306a5f1dc4b197de6d6fa149b7eb85ca623549c354f299d5b76f2cd97a9a7ca7888beca0ecca647ae74a0c6a6f9cc5
|
data/README.md
CHANGED
@@ -15,12 +15,28 @@ Usage
|
|
15
15
|
|
16
16
|
### Create a resource
|
17
17
|
|
18
|
-
|
18
|
+
class OrderRepository
|
19
|
+
include LucidShopify::Resource::Create
|
20
|
+
|
21
|
+
resource :orders
|
22
|
+
end
|
23
|
+
|
24
|
+
order_repo = OrderRepository.new
|
25
|
+
|
26
|
+
order_repo.create(credentials, new_order)
|
19
27
|
|
20
28
|
|
21
29
|
### Delete a resource
|
22
30
|
|
23
|
-
|
31
|
+
class OrderRepository
|
32
|
+
include LucidShopify::Resource::Delete
|
33
|
+
|
34
|
+
resource :orders
|
35
|
+
end
|
36
|
+
|
37
|
+
order_repo = OrderRepository.new
|
38
|
+
|
39
|
+
order_repo.delete(credentials, id)
|
24
40
|
|
25
41
|
|
26
42
|
### Read a resource
|
@@ -51,4 +67,12 @@ from the API as needed, rather than all at once:
|
|
51
67
|
|
52
68
|
### Update a resource
|
53
69
|
|
54
|
-
|
70
|
+
class OrderRepository
|
71
|
+
include LucidShopify::Resource::Update
|
72
|
+
|
73
|
+
resource :orders
|
74
|
+
end
|
75
|
+
|
76
|
+
order_repo = OrderRepository.new
|
77
|
+
|
78
|
+
order_repo.create(credentials, id, order)
|
@@ -31,27 +31,40 @@ module LucidShopify
|
|
31
31
|
end
|
32
32
|
|
33
33
|
#
|
34
|
-
# @
|
35
|
-
#
|
34
|
+
# @abstract Use {ClassMethods#resource} to implement (required)
|
35
|
+
#
|
36
|
+
# @return [String]
|
36
37
|
#
|
37
|
-
def
|
38
|
-
|
39
|
-
@client = client
|
40
|
-
@logger = logger
|
38
|
+
def resource
|
39
|
+
raise NotImplementedError
|
41
40
|
end
|
42
41
|
|
42
|
+
#
|
43
43
|
# @return [Client]
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
#
|
45
|
+
def client
|
46
|
+
@client ||= Container[:client]
|
47
|
+
end
|
47
48
|
|
48
49
|
#
|
49
|
-
# @
|
50
|
+
# @param new_client [Client]
|
50
51
|
#
|
51
|
-
|
52
|
+
def client=(new_client)
|
53
|
+
@client = new_client
|
54
|
+
end
|
55
|
+
|
52
56
|
#
|
53
|
-
|
54
|
-
|
57
|
+
# @return [Logger]
|
58
|
+
#
|
59
|
+
def logger
|
60
|
+
@logger ||= Logger.new(IO::NULL)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# @param new_logger [Logger]
|
65
|
+
#
|
66
|
+
def logger=(new_logger)
|
67
|
+
@logger = new_logger
|
55
68
|
end
|
56
69
|
end
|
57
70
|
end
|
@@ -28,7 +28,9 @@ module LucidShopify
|
|
28
28
|
def create(credentials, data)
|
29
29
|
response = client.post_json(credentials, resource, resource_singular => data)
|
30
30
|
|
31
|
-
response.data_hash.dig(resource_singular, 'id')
|
31
|
+
response.data_hash.dig(resource_singular, 'id').tap do |id|
|
32
|
+
logger.info("Created #{resource_singular} id=#{id}")
|
33
|
+
end
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -24,9 +24,9 @@ module LucidShopify
|
|
24
24
|
# @param id [Integer]
|
25
25
|
#
|
26
26
|
def delete(credentials, id)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
client.delete(credentials, "#{resource}/#{id}").tap do
|
28
|
+
logger.info("Deleted #{resource_singular} id=#{id}")
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -69,7 +69,7 @@ module LucidShopify
|
|
69
69
|
def find(credentials, id, params = {})
|
70
70
|
params = finalise_params(params)
|
71
71
|
|
72
|
-
logger.info("Fetching #{
|
72
|
+
logger.info("Fetching #{resource_singular} id=#{id}")
|
73
73
|
|
74
74
|
client.get(credentials, "#{resource}/#{id}", params).values.first
|
75
75
|
end
|
@@ -146,11 +146,10 @@ module LucidShopify
|
|
146
146
|
#
|
147
147
|
private def finalise_params(params)
|
148
148
|
params = default_shopify_params.merge(default_params).merge(params)
|
149
|
+
|
149
150
|
params.each_with_object({}) do |(k, v), h|
|
150
151
|
k = k.to_s
|
151
|
-
|
152
152
|
k == 'fields' && v.is_a?(Array) ? v.join(',') : v
|
153
|
-
|
154
153
|
h[k] = v
|
155
154
|
end
|
156
155
|
end
|
@@ -25,7 +25,9 @@ module LucidShopify
|
|
25
25
|
# @param data [Hash]
|
26
26
|
#
|
27
27
|
def update(credentials, id, data)
|
28
|
-
client.put_json(credentials, "#{resource}/#{id}", resource_singular => data)
|
28
|
+
client.put_json(credentials, "#{resource}/#{id}", resource_singular => data).tap do
|
29
|
+
logger.info("Updated #{resource_singular} id=#{id}")
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|