lucid_shopify-resource 0.2.2 → 0.4.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: 442ac5f02ccc7d05e3cc715a51338656e0577f33e3f715a81f797fcf0ab7df52
4
- data.tar.gz: 49e45c0d8538b6605029e310e028da06d775bba70e9b78558269ef0905c3ba7a
3
+ metadata.gz: c4b65bc3519016b53e1811d4e93a8833d84f6173fbdaadefd8bd60f2e3e48783
4
+ data.tar.gz: 8790c0ffcc53b524c1fa50efb53b8476be148fb146d149e93945ecbc87f91a5c
5
5
  SHA512:
6
- metadata.gz: 26424188f53a43cfdf2553dec31a4eafae04c3fb041db665f5f894676af0208cce54dcfaf6b1d5d79134f6cb8541cf9647a11f72ccd5576d50c0017c2eddabbc
7
- data.tar.gz: 99372149fd632daa266b7f11eb7d5d5876105d95c55e9453ec85e24e7fe156c6f4d8dd88e83f97bf08f362504c2659199135263e36429905a2865a9a30b61ab6
6
+ metadata.gz: 7c6dd3baa65eada85753f56f28904e722a6faf821f8cea44eaf9b50cc435f88191b88477c33288d11eab2d44c493cf00d79bbe64ebe89f247da67eabafb5c58f
7
+ data.tar.gz: 3d8bb9f9843b44491c77dde4bb1117388c860cc2351cdff34022a46fc7e969d797f6ca236d574015392dedf05aa7fed2fe4ba0b828d0a606b80cf553ab1ed617
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidShopify
4
- module Resource; end
4
+ module Resource
5
+ autoload :Create, 'lucid_shopify/resource/create'
6
+ autoload :Delete, 'lucid_shopify/resource/delete'
7
+ autoload :Read, 'lucid_shopify/resource/read'
8
+ autoload :Update, 'lucid_shopify/resource/update'
9
+ end
5
10
  end
6
-
7
- require 'lucid_shopify/resource/create'
8
- require 'lucid_shopify/resource/delete'
9
- require 'lucid_shopify/resource/read'
10
- require 'lucid_shopify/resource/update'
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lucid_shopify/container'
4
+
5
+ module LucidShopify
6
+ module Resource
7
+ module Base
8
+ module ClassMethods
9
+ #
10
+ # Set the remote API resource name for the subclass.
11
+ #
12
+ # @param resource_name [String, #to_s]
13
+ #
14
+ # @example
15
+ # resource :orders
16
+ #
17
+ def resource(resource_name)
18
+ define_method(:resource) { resource_name.to_s }
19
+ end
20
+ end
21
+
22
+ def self.included(base)
23
+ base.extend(ClassMethods)
24
+ end
25
+
26
+ #
27
+ # @param client [Client]
28
+ #
29
+ def initialize(client: Container[:client])
30
+ @client = client
31
+ end
32
+
33
+ # @return [Client]
34
+ attr_reader :client
35
+
36
+ #
37
+ # @abstract Use {ClassMethods#resource} to implement (required)
38
+ #
39
+ # @return [String]
40
+ #
41
+ def resource
42
+ raise NotImplementedError
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,12 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lucid_shopify/resource/base'
4
+
3
5
  module LucidShopify
4
6
  module Resource
5
7
  #
6
- # @abstract
8
+ # @example
9
+ # class OrderRepository
10
+ # include LucidShopify::Resource::Create
11
+ #
12
+ # resource :orders
7
13
  #
8
- class Create
9
- def self.new; raise NotImplementedError; end
14
+ # # ...
15
+ # end
16
+ #
17
+ module Create
18
+ def self.included(base)
19
+ base.include(Base)
20
+
21
+ raise NotImplementedError # TODO
22
+ end
10
23
  end
11
24
  end
12
25
  end
@@ -1,12 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lucid_shopify/resource/base'
4
+
3
5
  module LucidShopify
4
6
  module Resource
5
7
  #
6
- # @abstract
8
+ # @example
9
+ # class OrderRepository
10
+ # include LucidShopify::Resource::Delete
11
+ #
12
+ # resource :orders
7
13
  #
8
- class Delete
9
- def self.new; raise NotImplementedError; end
14
+ # # ...
15
+ # end
16
+ #
17
+ module Delete
18
+ def self.included(base)
19
+ base.include(Base)
20
+
21
+ raise NotImplementedError # TODO
22
+ end
10
23
  end
11
24
  end
12
25
  end
@@ -1,67 +1,46 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lucid_shopify/resource/base'
4
+
3
5
  module LucidShopify
4
6
  module Resource
5
- #
6
- # @abstract
7
7
  #
8
8
  # @example
9
- # class Orders < LucidShopify::Resource::Read
9
+ # class OrderRepository
10
+ # include LucidShopify::Resource::Read
11
+ #
10
12
  # resource :orders
11
13
  #
12
- # default_params fields: %w(id tags)
14
+ # default_params fields: %w[id tags]
15
+ #
16
+ # # ...
13
17
  # end
14
18
  #
15
- class Read
16
- include Enumerable
17
- include LucidShopify
18
-
19
- #
20
- # @param client [LucidShopify::Client]
21
- #
22
- def initialize(client: Client.new(send_request: SendThrottledRequest.new))
23
- @client = client
24
- end
25
-
26
- # @return [LucidShopify::Client]
27
- attr_reader :client
28
-
29
- #
30
- # Set the remote API resource name for the subclass.
31
- #
32
- # @param resource_name [String, #to_s]
33
- #
34
- # @example
35
- # resource :orders
36
- #
37
- def self.resource(resource_name)
38
- define_method(:resource) { resource_name.to_s }
19
+ module Read
20
+ module ClassMethods
21
+ #
22
+ # Set the default query params. Note that 'fields' may be passed as an
23
+ # array of strings.
24
+ #
25
+ # @param params [Hash]
26
+ #
27
+ # @example
28
+ # default_params fields: %w(id tags)
29
+ #
30
+ def default_params(params)
31
+ define_method(:default_params) { params }
32
+ end
39
33
  end
40
34
 
41
- #
42
- # @abstract
43
- #
44
- # @return [String]
45
- #
46
- def resource
47
- raise NotImplementedError
48
- end
35
+ include Enumerable
49
36
 
50
- #
51
- # Set the default query params. Note that 'fields' may be passed as an
52
- # array of strings.
53
- #
54
- # @param params [Hash]
55
- #
56
- # @example
57
- # default_params fields: %w(id tags)
58
- #
59
- def self.default_params(params)
60
- define_method(:default_params) { params }
37
+ def self.included(base)
38
+ base.extend(ClassMethods)
39
+ base.include(Base)
61
40
  end
62
41
 
63
42
  #
64
- # @abstract
43
+ # @abstract Use {ClassMethods#default_params} to implement (optional)
65
44
  #
66
45
  # @return [Hash]
67
46
  #
@@ -81,7 +60,7 @@ module LucidShopify
81
60
  end
82
61
 
83
62
  #
84
- # @param credentials [LucidShopify::RequestCredentials]
63
+ # @param credentials [RequestCredentials]
85
64
  # @param id [Integer]
86
65
  # @param params [Hash]
87
66
  #
@@ -100,7 +79,7 @@ module LucidShopify
100
79
  #
101
80
  # Throttling is always enabled.
102
81
  #
103
- # @param credentials [LucidShopify::RequestCredentials]
82
+ # @param credentials [RequestCredentials]
104
83
  # @param params [Hash]
105
84
  #
106
85
  # @yield [Hash]
@@ -114,10 +93,12 @@ module LucidShopify
114
93
 
115
94
  assert_fields_id!(params = finalized_params(params))
116
95
 
96
+ throttled_client = client.throttled
97
+
117
98
  since_id = 1
118
99
 
119
100
  loop do
120
- results = client.get(credentials, resource, params.merge(since_id: since_id))
101
+ results = throttled_client.get(credentials, resource, params.merge(since_id: since_id))
121
102
  results.each do |result|
122
103
  yield result
123
104
  end
@@ -139,12 +120,11 @@ module LucidShopify
139
120
  end
140
121
 
141
122
  #
142
- # @param client [LucidShopify::AuthorizedClient]
143
123
  # @param params [Hash]
144
124
  #
145
125
  # @return [Integer]
146
126
  #
147
- def count(client, params = {})
127
+ def count(params = {})
148
128
  params = finalize_params(params)
149
129
 
150
130
  client.get("#{resource}/count", params)['count']
@@ -1,12 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lucid_shopify/resource/base'
4
+
3
5
  module LucidShopify
4
6
  module Resource
5
7
  #
6
- # @abstract
8
+ # @example
9
+ # class OrderRepository
10
+ # include LucidShopify::Resource::Update
11
+ #
12
+ # resource :orders
7
13
  #
8
- class Update
9
- def self.new; raise NotImplementedError; end
14
+ # # ...
15
+ # end
16
+ #
17
+ module Update
18
+ def self.included(base)
19
+ base.include(Base)
20
+
21
+ raise NotImplementedError # TODO
22
+ end
10
23
  end
11
24
  end
12
25
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LucidShopify
4
4
  class Resource
5
- VERSION = '0.2.2'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_shopify-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-02 00:00:00.000000000 Z
11
+ date: 2018-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.5'
47
+ version: '0.9'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.5'
54
+ version: '0.9'
55
55
  description:
56
56
  email: kelsey@lucid.nz
57
57
  executables: []
@@ -61,6 +61,7 @@ files:
61
61
  - README.md
62
62
  - lib/lucid_shopify-resource.rb
63
63
  - lib/lucid_shopify/resource.rb
64
+ - lib/lucid_shopify/resource/base.rb
64
65
  - lib/lucid_shopify/resource/create.rb
65
66
  - lib/lucid_shopify/resource/delete.rb
66
67
  - lib/lucid_shopify/resource/read.rb