chord 0.0.5 → 0.0.6
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 +5 -0
- data/README.md +57 -7
- data/lib/chord/version.rb +1 -1
- data/lib/chord.rb +20 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b29351f996510a42975aa338c2ece2744e49780e4c31b2c265593a2707824c
|
4
|
+
data.tar.gz: 7bc61180788440328b85083997629d9d63ddf7496c2a5702869973a6ca4ce238
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9694514bb6710a41ab0a3331f9e9fdcbe0c36945304384e7b0b4207f93d323c1c65e10eed77cdbddaea566f325a2354918d43cbdf978d32224a57665826298e
|
7
|
+
data.tar.gz: 2e2b02f34e13133d93f70693670e423250aa16090165b87484eee2927dca52d48b791ef1ac7ec914aa87dd6aca09e4726942a2d55a23ddf198f2df2f74e90ac5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,22 +8,72 @@ These classes provide simple read and write access to the Chord OMS API. Get sta
|
|
8
8
|
)
|
9
9
|
|
10
10
|
u = Chord::User.find(1) # fetch user
|
11
|
-
u.
|
12
|
-
u.
|
13
|
-
u.update(
|
14
|
-
# hash is merged into the existing value and
|
15
|
-
# keys and values are stringified (since
|
16
|
-
# metadata is stored in OMS as a JSON string)
|
11
|
+
u.email # view an attribute
|
12
|
+
u.attributes # see all attributes (returns hash)
|
13
|
+
u.update(name: 'Joe Smith', notes: 'Etc') # update attributes
|
17
14
|
u.add_role(3) # add role (by ID) to the user
|
18
15
|
u.remove_role(3) # remove role (by ID) from the user
|
19
16
|
u.subscriptions # fetch the user's subscriptions
|
17
|
+
u.update(metadata: {legacy_id: 415}) # when updating 'metadata' attribute, the given
|
18
|
+
# hash is merged into the existing value and
|
19
|
+
# keys and values are stringified (since
|
20
|
+
# metadata is stored in OMS as a JSON string)
|
21
|
+
|
22
|
+
o = Chord::Order.find(1) # fetch order
|
23
|
+
o.subscription_installment? # was the order a subscription installment?
|
24
|
+
o.subscription_start? # did the order start a subscription?
|
25
|
+
|
26
|
+
For complete/current list of supported objects and methods, please see the code.
|
27
|
+
|
28
|
+
|
29
|
+
## Querying
|
30
|
+
|
31
|
+
The most basic way to get a collection of objects:
|
32
|
+
|
33
|
+
Chord::Order.all
|
34
|
+
|
35
|
+
You can also filter and sort, though the parameters are not well documented:
|
36
|
+
|
37
|
+
Chord::Order.where(
|
38
|
+
'q[completed_at_gt]' => '2022-09-14',
|
39
|
+
'q[s]' => 'completed_at desc'
|
40
|
+
)
|
41
|
+
|
42
|
+
|
43
|
+
## Object attributes
|
20
44
|
|
21
45
|
Objects are constructed in a way that minimizes API calls but occasionally yields objects that seem incomplete. For example:
|
22
46
|
|
23
47
|
orders = Chord::Order.all
|
24
48
|
o = orders.first
|
25
49
|
|
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
|
50
|
+
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 such an object, use the `expand!` method:
|
27
51
|
|
28
52
|
o.expand!
|
29
53
|
|
54
|
+
|
55
|
+
# Configuration options
|
56
|
+
|
57
|
+
To get your sensitive config data out of your code, you can put it in a YAML file, like so:
|
58
|
+
|
59
|
+
# chord_config.yml
|
60
|
+
base_url: https://...
|
61
|
+
api_key: ...
|
62
|
+
|
63
|
+
and load it by calling:
|
64
|
+
|
65
|
+
Chord.config_from_file('chord_config.yml')
|
66
|
+
|
67
|
+
Or you can put your configuration in environment variables:
|
68
|
+
|
69
|
+
CHORD_BASE_URL=https://...
|
70
|
+
CHORD_API_KEY=...
|
71
|
+
|
72
|
+
and load it by calling:
|
73
|
+
|
74
|
+
Chord.config_from_env
|
75
|
+
|
76
|
+
Both config-loading methods return a boolean indicating whether configuration data was found and loaded, so you can easily fall back from one method to the other, for example:
|
77
|
+
|
78
|
+
Chord.config_from_env or Chord.config_from_file('chord_config.yml')
|
79
|
+
|
data/lib/chord/version.rb
CHANGED
data/lib/chord.rb
CHANGED
@@ -7,8 +7,8 @@ module Chord
|
|
7
7
|
attr_accessor :api_key
|
8
8
|
|
9
9
|
def config(options)
|
10
|
-
self.base_url = options[:base_url]
|
11
|
-
self.api_key = options[:api_key]
|
10
|
+
self.base_url = options[:base_url] if options[:base_url]
|
11
|
+
self.api_key = options[:api_key] if options[:api_key]
|
12
12
|
end
|
13
13
|
|
14
14
|
def config_from_file(filepath)
|
@@ -19,6 +19,20 @@ module Chord
|
|
19
19
|
base_url: config[:base_url],
|
20
20
|
api_key: config[:api_key]
|
21
21
|
)
|
22
|
+
else
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def config_from_env
|
28
|
+
if ENV['CHORD_BASE_URL'] or ENV['CHORD_API_KEY']
|
29
|
+
Chord.config(
|
30
|
+
base_url: ENV['CHORD_BASE_URL'],
|
31
|
+
api_key: ENV['CHORD_API_KEY']
|
32
|
+
)
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
22
36
|
end
|
23
37
|
end
|
24
38
|
end
|
@@ -228,6 +242,10 @@ module Chord
|
|
228
242
|
def self.base_path
|
229
243
|
'roles'
|
230
244
|
end
|
245
|
+
|
246
|
+
def users
|
247
|
+
attributes['users'].map{ |u| Chord::User.new(u['id'], u) }
|
248
|
+
end
|
231
249
|
end
|
232
250
|
|
233
251
|
|
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.6
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|