chord 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +5 -4
- data/lib/chord/version.rb +1 -1
- data/lib/chord.rb +26 -9
- 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: 6da5791c0fe9f32d72d827bc87ae15186cadbff18bfceecee81b98f17c3111a0
|
4
|
+
data.tar.gz: 037ad832506b87180563ce7ab0d8fbf591bcef211e1a72abe1110292329052dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
24
|
-
|
25
|
-
s.user
|
23
|
+
orders = Chord::Order.all
|
24
|
+
o = orders.first
|
26
25
|
|
27
|
-
will return a Chord::
|
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
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;
|
31
|
+
def per_page; 99999; end
|
32
32
|
|
33
33
|
def all
|
34
|
-
@all ||= fetch_all_data[base_path].map{ |i| new(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[
|
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 =
|
44
|
-
attrs.include?('error') ? nil : new(
|
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
|