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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 128de0ab9db042cb27d00bdcf1210a2c605726afc7ab167b1b0273141ab15d6b
4
- data.tar.gz: 1dfcbc9cce9734e915451abc21313baa9c17c52d7923d70e26f39724124e8595
3
+ metadata.gz: 40a00b5c2ef9edac2d54be5ad00be475050abc49e0036cbecf6c3c82fc2e487d
4
+ data.tar.gz: 8377b1e7a55ce874d5411cf925ebc2d32e9d4982d273aec34eeceb4bf6a119aa
5
5
  SHA512:
6
- metadata.gz: 4cd71fcea5deabd39aa71d324d026038e6a0e3c75d5761e7db8e3836a0c989e85a28a2e0b98a394e20815e8f3d83ec5a313ad4ba12ed38472d23f09f7df26d6d
7
- data.tar.gz: 0e3595492bcbeac153ce84fa31790886cbf7b7cddd9af7a56dcf502f5fdf447516a2fc9eaa42a97eb7e672a25aa8dceeea50caea24c7457693a1d8b6708c1d57
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
- _TODO: Implement when needed._
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
- _TODO: Implement when needed._
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
- _TODO: Implement when needed._
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
- # @param client [Client]
35
- # @param logger [Logger]
34
+ # @abstract Use {ClassMethods#resource} to implement (required)
35
+ #
36
+ # @return [String]
36
37
  #
37
- def initialize(client: Container[:client],
38
- logger: Logger.new(IO::NULL))
39
- @client = client
40
- @logger = logger
38
+ def resource
39
+ raise NotImplementedError
41
40
  end
42
41
 
42
+ #
43
43
  # @return [Client]
44
- attr_reader :client
45
- # @return [Client]
46
- attr_reader :logger
44
+ #
45
+ def client
46
+ @client ||= Container[:client]
47
+ end
47
48
 
48
49
  #
49
- # @abstract Use {ClassMethods#resource} to implement (required)
50
+ # @param new_client [Client]
50
51
  #
51
- # @return [String]
52
+ def client=(new_client)
53
+ @client = new_client
54
+ end
55
+
52
56
  #
53
- def resource
54
- raise NotImplementedError
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
- logger.info("Deleting #{resource_singular} id=#{id}")
28
-
29
- client.delete(credentials, "#{resource}/#{id}")
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 #{resource} id=#{id}")
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LucidShopify
4
4
  module Resource
5
- VERSION = '0.6.0'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_shopify-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson