chord 0.0.5 → 0.0.6

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: 6da5791c0fe9f32d72d827bc87ae15186cadbff18bfceecee81b98f17c3111a0
4
- data.tar.gz: 037ad832506b87180563ce7ab0d8fbf591bcef211e1a72abe1110292329052dc
3
+ metadata.gz: 82b29351f996510a42975aa338c2ece2744e49780e4c31b2c265593a2707824c
4
+ data.tar.gz: 7bc61180788440328b85083997629d9d63ddf7496c2a5702869973a6ca4ce238
5
5
  SHA512:
6
- metadata.gz: afd04a08a2150ee30708c5ded7ec9a795839cfe606e17e9633691a76e2820346a7127995374639a8bbda0a20b39d529380b1b60810fee7993ad68983ae904fc5
7
- data.tar.gz: d9c99564446ead46f5155f6efa8ae6efed6caa28d6ac64241f4be70fb6f4f674f3f9b228610ebf8a1d41dd8cf7d81b279942d5bcb25368ba877dd90d88506dbf
6
+ metadata.gz: a9694514bb6710a41ab0a3331f9e9fdcbe0c36945304384e7b0b4207f93d323c1c65e10eed77cdbddaea566f325a2354918d43cbdf978d32224a57665826298e
7
+ data.tar.gz: 2e2b02f34e13133d93f70693670e423250aa16090165b87484eee2927dca52d48b791ef1ac7ec914aa87dd6aca09e4726942a2d55a23ddf198f2df2f74e90ac5
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.6
6
+
7
+ * Return User objects from Role#users.
8
+ * Add config methods.
9
+
5
10
  ## 0.0.5
6
11
 
7
12
  * Add expand! method.
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.attributes # see attributes hash
12
- u.update(name: 'New Name', notes: 'Etc') # update attributes
13
- u.update(metadata: {ambassador_id: 415}) # when updating 'metadata' attribute, the given
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 these objects, use the `expand!` method:
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
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
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.5
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-20 00:00:00.000000000 Z
11
+ date: 2022-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty