chord 0.0.4 → 0.0.5

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: d87fc026e550a99125b7aac97b1069d943ccc8b6c23f4bface9ae5136d2fd48d
4
- data.tar.gz: ca017e9919b6323d25f0dbac900598be630c843120bef07f1db29787e94b675d
3
+ metadata.gz: 6da5791c0fe9f32d72d827bc87ae15186cadbff18bfceecee81b98f17c3111a0
4
+ data.tar.gz: 037ad832506b87180563ce7ab0d8fbf591bcef211e1a72abe1110292329052dc
5
5
  SHA512:
6
- metadata.gz: e027f417299124bbcf66d573ddd4ddb36f9a3c3d193385df49b2499ed9658543b58375064ba4cd583777a66be63ef685c036ba3616f7813bd34ebd857753d34a
7
- data.tar.gz: fc10bf3c2ff5b9fd59048024ff07f3288b9593aea3da6a90fc35b11697d992bdcc48b00d873bbc07685b63440e9a228dc27330409568d98073f1e9adc51c0416
6
+ metadata.gz: afd04a08a2150ee30708c5ded7ec9a795839cfe606e17e9633691a76e2820346a7127995374639a8bbda0a20b39d529380b1b60810fee7993ad68983ae904fc5
7
+ data.tar.gz: d9c99564446ead46f5155f6efa8ae6efed6caa28d6ac64241f4be70fb6f4f674f3f9b228610ebf8a1d41dd8cf7d81b279942d5bcb25368ba877dd90d88506dbf
data/CHANGELOG.md CHANGED
@@ -2,9 +2,14 @@
2
2
 
3
3
  Major changes for each release. Please see the Git log for complete list of changes.
4
4
 
5
+ ## 0.0.5
6
+
7
+ * Add expand! method.
8
+ * Fix Order object IDs.
9
+
5
10
  ## 0.0.4
6
11
 
7
- * Load attribute if missing.
12
+ * Load subscription_in_cart attribute if missing when it's needed.
8
13
 
9
14
  ## 0.0.3
10
15
 
data/README.md CHANGED
@@ -20,9 +20,10 @@ These classes provide simple read and write access to the Chord OMS API. Get sta
20
20
 
21
21
  Objects are constructed in a way that minimizes API calls but occasionally yields objects that seem incomplete. For example:
22
22
 
23
- u = Chord::User.find(44)
24
- s = u.subscriptions.first
25
- s.user
23
+ orders = Chord::Order.all
24
+ o = orders.first
26
25
 
27
- will return a Chord::User object with only two attributes (ID and email) because the API only returns two attributes with a Subscription object.
26
+ will return a Chord::Order object with around 40 attributes, not the full set of 55 (it's missing line items, for example), because the `/orders` endpoint returns abbreviated objects. To load the full set of data for these objects, use the `expand!` method:
27
+
28
+ o.expand!
28
29
 
data/lib/chord/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/chord.rb CHANGED
@@ -28,20 +28,28 @@ module Chord
28
28
 
29
29
  class << self
30
30
  attr_writer :per_page
31
- def per_page; @per_page || 99999; end
31
+ def per_page; 99999; end
32
32
 
33
33
  def all
34
- @all ||= fetch_all_data[base_path].map{ |i| new(i['id'], i) }
34
+ @all ||= fetch_all_data[base_path].map{ |i| new(i[id_attribute], i) }
35
35
  end
36
36
 
37
37
  def where(query_options = {})
38
- fetch_all_data(query_options)[base_path].map{ |i| new(i['id'], i) }
38
+ fetch_all_data(query_options)[base_path].map{ |i| new(i[id_attribute], i) }
39
39
  end
40
40
 
41
41
  def find(id)
42
42
  return nil if id.nil? or id == ''
43
- attrs = get(base_url + "#{base_path}/#{id}", http_options).parsed_response
44
- attrs.include?('error') ? nil : new(id, attrs)
43
+ attrs = fetch_attributes(id)
44
+ attrs.include?('error') ? nil : new(attrs[id_attribute], attrs)
45
+ end
46
+
47
+ def fetch_attributes(id)
48
+ get(base_url + "#{base_path}/#{id}", http_options).parsed_response
49
+ end
50
+
51
+ def id_attribute
52
+ 'id'
45
53
  end
46
54
 
47
55
  def fetch_all_data(query_options = {})
@@ -109,6 +117,13 @@ module Chord
109
117
  self.class.delete(base_url + "#{base_path}/#{id}", http_options).parsed_response
110
118
  end
111
119
 
120
+ # fetch all attributes, but don't overwrite existing ones,
121
+ # in case changes have been made
122
+ def expand!
123
+ all_attributes = self.class.fetch_attributes(id)
124
+ @attributes = all_attributes.merge(@attributes)
125
+ end
126
+
112
127
  def method_missing(method, *args, &block)
113
128
  if attributes.include?(method.to_s)
114
129
  attributes[method.to_s]
@@ -175,8 +190,12 @@ module Chord
175
190
  'orders'
176
191
  end
177
192
 
193
+ def self.id_attribute
194
+ 'number'
195
+ end
196
+
178
197
  def user
179
- Chord::User.find(attributes['user_id'])
198
+ @user ||= Chord::User.find(attributes['user_id'])
180
199
  end
181
200
 
182
201
  def payments
@@ -198,9 +217,7 @@ module Chord
198
217
  end
199
218
 
200
219
  def subscription_start?
201
- unless attributes.include?('subscription_in_cart')
202
- attributes['subscription_in_cart'] = Chord::Order.find(number).subscription_in_cart
203
- end
220
+ expand! unless attributes.include?('subscription_in_cart')
204
221
  subscription_in_cart
205
222
  end
206
223
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner