chord 0.0.7 → 0.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4caa956b7d9f279a1973f2a5ad5e63f0078697ecb1fc129fcff09c10dfcdbbc3
4
- data.tar.gz: c4a93aa0e26f11d6bb42b7345b1dead92f685eafb43d96fa34516d05eb3a09a2
3
+ metadata.gz: 8f0f6af63adad1bbb028d80575a89a9edcbb424125446e7d8b7c6988d110afd9
4
+ data.tar.gz: ed4caff66b9252177a0bb9ee2a173db714f6da72e893146abab367c05965aa7a
5
5
  SHA512:
6
- metadata.gz: 8fa44ce53bc77f079140bab0838a66196314f103f3c515ea8dd90c9341af047fa5afb19925189a864652590d4fcf2f431095ceb4cbbde99725085dd72477206e
7
- data.tar.gz: f30e7aa9d991c7822ab93777a8a6de9c9f6df943a83d8bf7c629a2b1f3ba18bc485d570a2aa152ca14f2e01d6b3e794925d1cf931199ad76f78a3ddb868b9feb
6
+ metadata.gz: 5e7aa4ab708794d3a80bd61158973cfdd38d9aec7af9b320811af6699137043ef4ce5372fb26c0e1493f4a0100b77356aae555d3228a3b819324a3c7e65853bc
7
+ data.tar.gz: 418c1f595998d385289b4825ebd181e1f2abdfe823b8d6ea33348f7b3c9c7adf771864cb94545fcead076b75ab4b2570dfea0a3519bb03e5000bca3f818189b1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Major changes for each release. Please see the Git log for complete list of changes.
4
4
 
5
+ ## 0.0.8
6
+
7
+ * Don't preserve existing attributes when calling `expand!`.
8
+ * Add User#orders method.
9
+
5
10
  ## 0.0.7
6
11
 
7
12
  * 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(1) # fetch order
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 and sort, though the parameters are not well documented:
32
+ You can also filter results by using `where`:
32
33
 
33
- Chord::Order.where(
34
- 'q[completed_at_gt]' => '2022-09-14',
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 your sensitive config data out of your code, you can put it in a YAML file, like so:
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 you can put your configuration in environment variables:
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
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/chord.rb CHANGED
@@ -137,8 +137,7 @@ module Chord
137
137
  # fetch all attributes, but don't overwrite existing ones,
138
138
  # in case changes have been made
139
139
  def expand!
140
- all_attributes = self.class.send(:fetch_attributes, id)
141
- @attributes = all_attributes.merge(@attributes)
140
+ self.attributes = self.class.send(:fetch_attributes, id)
142
141
  end
143
142
 
144
143
  def method_missing(method, *args, &block)
@@ -153,36 +152,14 @@ module Chord
153
152
 
154
153
  class User < Base
155
154
 
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
155
  def self.base_path
183
156
  'users'
184
157
  end
185
158
 
159
+ def orders
160
+ Order.where('q[user_id_eq]' => id)
161
+ end
162
+
186
163
  def add_role(role_id)
187
164
  self.class.put(base_url + "roles/#{role_id}/add/#{id}", http_options).parsed_response
188
165
  end
@@ -270,6 +247,13 @@ module Chord
270
247
  end
271
248
  end
272
249
 
250
+ class Variant < Base
251
+
252
+ def self.base_path
253
+ 'variants'
254
+ end
255
+ end
256
+
273
257
  class ConfigurationError < StandardError
274
258
  end
275
259
 
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.7
4
+ version: 0.0.8
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-22 00:00:00.000000000 Z
11
+ date: 2022-09-23 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.5.0
55
+ version: 2.0.0
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="