chord 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +9 -9
- data/lib/chord/version.rb +1 -1
- data/lib/chord.rb +18 -29
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e83b6981808cf5864784c21d0558273fa3edc0099f43d495ef06d556c36f08e
|
4
|
+
data.tar.gz: 8b4a00fc5b097a03b527097350fab0f38ed21871f5279e2a58d9fef58dc60b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c212e87eb22ea7a0fa807949ecd0470154abc16761d1847411cb9d516518febaf0da6e754558895e13fd7ecf0cd4660685a6593b9b554549cc3b87ed28d2a6
|
7
|
+
data.tar.gz: 9e84d6c2edf9cb3526184f13121099e3ecd8ee9412b5563a311c41f2910d09b229b7f5de1c10ca215fd5274b48a46114aba8221430bb1700818862bc35f41072
|
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.9
|
6
|
+
|
7
|
+
* When API error on update, don't update object attributes.
|
8
|
+
|
9
|
+
## 0.0.8
|
10
|
+
|
11
|
+
* Don't preserve existing attributes when calling `expand!`.
|
12
|
+
* Add User#orders method.
|
13
|
+
|
5
14
|
## 0.0.7
|
6
15
|
|
7
16
|
* Remove ActiveRecord dependency.
|
data/README.md
CHANGED
@@ -7,15 +7,16 @@ These classes provide simple read and write access to the Chord OMS API. Get sta
|
|
7
7
|
api_key: '<key>'
|
8
8
|
)
|
9
9
|
|
10
|
-
u = Chord::User.find(1) # fetch user
|
10
|
+
u = Chord::User.find(1) # fetch user by ID
|
11
11
|
u.email # view an attribute
|
12
12
|
u.attributes # see all attributes (returns hash)
|
13
13
|
u.update(name: 'Joe Smith', notes: 'Etc') # update attributes
|
14
14
|
u.add_role(3) # add role (by ID) to the user
|
15
15
|
u.remove_role(3) # remove role (by ID) from the user
|
16
|
+
u.orders # fetch the user's orders
|
16
17
|
u.subscriptions # fetch the user's subscriptions
|
17
18
|
|
18
|
-
o = Chord::Order.find(
|
19
|
+
o = Chord::Order.find('R87234695') # fetch order by ID
|
19
20
|
o.subscription_installment? # was the order a subscription installment?
|
20
21
|
o.subscription_start? # did the order start a subscription?
|
21
22
|
|
@@ -28,12 +29,10 @@ The most basic way to get a collection of objects:
|
|
28
29
|
|
29
30
|
Chord::Order.all
|
30
31
|
|
31
|
-
You can also filter
|
32
|
+
You can also filter results by using `where`:
|
32
33
|
|
33
|
-
Chord::Order.where(
|
34
|
-
|
35
|
-
'q[s]' => 'completed_at desc'
|
36
|
-
)
|
34
|
+
Chord::Order.where('q[completed_at_gt]' => '2022-09-14')
|
35
|
+
Chord::User.where('q[spree_roles_id_in]' => 8)
|
37
36
|
|
38
37
|
|
39
38
|
## Object attributes
|
@@ -50,7 +49,7 @@ will return a Chord::Order object with around 40 attributes, not the full set of
|
|
50
49
|
|
51
50
|
# Configuration options
|
52
51
|
|
53
|
-
To get
|
52
|
+
To get configuration data out of your code, put it in a YAML file, like so:
|
54
53
|
|
55
54
|
# chord_config.yml
|
56
55
|
base_url: https://...
|
@@ -60,7 +59,7 @@ and load it by calling:
|
|
60
59
|
|
61
60
|
Chord.config_from_file('chord_config.yml')
|
62
61
|
|
63
|
-
Or
|
62
|
+
Or put your config in environment variables:
|
64
63
|
|
65
64
|
CHORD_BASE_URL=https://...
|
66
65
|
CHORD_API_KEY=...
|
@@ -77,3 +76,4 @@ Both config-loading methods return a boolean indicating whether configuration da
|
|
77
76
|
# To Do
|
78
77
|
|
79
78
|
* tests should use mocks instead of real API requests
|
79
|
+
* support more objects and methods
|
data/lib/chord/version.rb
CHANGED
data/lib/chord.rb
CHANGED
@@ -125,9 +125,14 @@ module Chord
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def update(new_attributes)
|
128
|
-
|
128
|
+
response = self.class.patch(base_url + "#{base_path}/#{id}",
|
129
129
|
http_options.merge(body: new_attributes.to_json)
|
130
130
|
).parsed_response
|
131
|
+
if response.include?('error')
|
132
|
+
raise APIError, "Chord API error (status #{response['status']}): #{response['error']}"
|
133
|
+
else
|
134
|
+
self.attributes = response
|
135
|
+
end
|
131
136
|
end
|
132
137
|
|
133
138
|
def delete
|
@@ -137,8 +142,7 @@ module Chord
|
|
137
142
|
# fetch all attributes, but don't overwrite existing ones,
|
138
143
|
# in case changes have been made
|
139
144
|
def expand!
|
140
|
-
|
141
|
-
@attributes = all_attributes.merge(@attributes)
|
145
|
+
self.attributes = self.class.send(:fetch_attributes, id)
|
142
146
|
end
|
143
147
|
|
144
148
|
def method_missing(method, *args, &block)
|
@@ -153,36 +157,14 @@ module Chord
|
|
153
157
|
|
154
158
|
class User < Base
|
155
159
|
|
156
|
-
#
|
157
|
-
# For avoiding API calls.
|
158
|
-
#
|
159
|
-
def self.all_by_id
|
160
|
-
unless @all_by_id
|
161
|
-
@all_by_id = {}
|
162
|
-
all.each do |u|
|
163
|
-
@all_by_id[u.id] = u
|
164
|
-
end
|
165
|
-
end
|
166
|
-
@all_by_id
|
167
|
-
end
|
168
|
-
|
169
|
-
#
|
170
|
-
# For mapping users on our old site to Chord.
|
171
|
-
#
|
172
|
-
def self.all_by_email
|
173
|
-
unless @all_by_email
|
174
|
-
@all_by_email = {}
|
175
|
-
all.each do |u|
|
176
|
-
@all_by_email[u.email] = u
|
177
|
-
end
|
178
|
-
end
|
179
|
-
@all_by_email
|
180
|
-
end
|
181
|
-
|
182
160
|
def self.base_path
|
183
161
|
'users'
|
184
162
|
end
|
185
163
|
|
164
|
+
def orders
|
165
|
+
Order.where('q[user_id_eq]' => id)
|
166
|
+
end
|
167
|
+
|
186
168
|
def add_role(role_id)
|
187
169
|
self.class.put(base_url + "roles/#{role_id}/add/#{id}", http_options).parsed_response
|
188
170
|
end
|
@@ -270,6 +252,13 @@ module Chord
|
|
270
252
|
end
|
271
253
|
end
|
272
254
|
|
255
|
+
class Variant < Base
|
256
|
+
|
257
|
+
def self.base_path
|
258
|
+
'variants'
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
273
262
|
class ConfigurationError < StandardError
|
274
263
|
end
|
275
264
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 2.
|
55
|
+
version: 2.0.0
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - ">="
|