chord 0.0.3 → 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: b19cd9b9520300cd180df422f8ec819593113febc7a63cfedb23c1b727e83a24
4
- data.tar.gz: 4d654b32483b583e853a624b3b8d6e955b2647cd962222c8dd4be13498c464e4
3
+ metadata.gz: 6da5791c0fe9f32d72d827bc87ae15186cadbff18bfceecee81b98f17c3111a0
4
+ data.tar.gz: 037ad832506b87180563ce7ab0d8fbf591bcef211e1a72abe1110292329052dc
5
5
  SHA512:
6
- metadata.gz: 7ecca2abcf3397c438bd15ff7fbf286ec2d867742cdfccb0b374cba05725db58fc59ce14da8fee4e7c1cb7347a48558ae7b79e9f30784ce352d261ea72a12576
7
- data.tar.gz: 41bb0c8b107cb4ef7bc1fbbd930061097252d5ae5d2eb423935dc9c4c79d15ed1e4805f091d2ad64794ffa2f5282da084e1eeedc078d2446feff7dbc62e61553
6
+ metadata.gz: afd04a08a2150ee30708c5ded7ec9a795839cfe606e17e9633691a76e2820346a7127995374639a8bbda0a20b39d529380b1b60810fee7993ad68983ae904fc5
7
+ data.tar.gz: d9c99564446ead46f5155f6efa8ae6efed6caa28d6ac64241f4be70fb6f4f674f3f9b228610ebf8a1d41dd8cf7d81b279942d5bcb25368ba877dd90d88506dbf
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
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
+
10
+ ## 0.0.4
11
+
12
+ * Load subscription_in_cart attribute if missing when it's needed.
13
+
5
14
  ## 0.0.3
6
15
 
7
16
  * Refactor configuration.
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.3"
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,6 +217,7 @@ module Chord
198
217
  end
199
218
 
200
219
  def subscription_start?
220
+ expand! unless attributes.include?('subscription_in_cart')
201
221
  subscription_in_cart
202
222
  end
203
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.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner