chord 0.0.6 → 0.0.7

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: 82b29351f996510a42975aa338c2ece2744e49780e4c31b2c265593a2707824c
4
- data.tar.gz: 7bc61180788440328b85083997629d9d63ddf7496c2a5702869973a6ca4ce238
3
+ metadata.gz: 4caa956b7d9f279a1973f2a5ad5e63f0078697ecb1fc129fcff09c10dfcdbbc3
4
+ data.tar.gz: c4a93aa0e26f11d6bb42b7345b1dead92f685eafb43d96fa34516d05eb3a09a2
5
5
  SHA512:
6
- metadata.gz: a9694514bb6710a41ab0a3331f9e9fdcbe0c36945304384e7b0b4207f93d323c1c65e10eed77cdbddaea566f325a2354918d43cbdf978d32224a57665826298e
7
- data.tar.gz: 2e2b02f34e13133d93f70693670e423250aa16090165b87484eee2927dca52d48b791ef1ac7ec914aa87dd6aca09e4726942a2d55a23ddf198f2df2f74e90ac5
6
+ metadata.gz: 8fa44ce53bc77f079140bab0838a66196314f103f3c515ea8dd90c9341af047fa5afb19925189a864652590d4fcf2f431095ceb4cbbde99725085dd72477206e
7
+ data.tar.gz: f30e7aa9d991c7822ab93777a8a6de9c9f6df943a83d8bf7c629a2b1f3ba18bc485d570a2aa152ca14f2e01d6b3e794925d1cf931199ad76f78a3ddb868b9feb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Major changes for each release. Please see the Git log for complete list of changes.
4
4
 
5
+ ## 0.0.7
6
+
7
+ * Remove ActiveRecord dependency.
8
+ * Make some methods private.
9
+ * Raise APIError when no data returned.
10
+
5
11
  ## 0.0.6
6
12
 
7
13
  * Return User objects from Role#users.
data/README.md CHANGED
@@ -14,10 +14,6 @@ These classes provide simple read and write access to the Chord OMS API. Get sta
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
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
17
 
22
18
  o = Chord::Order.find(1) # fetch order
23
19
  o.subscription_installment? # was the order a subscription installment?
@@ -77,3 +73,7 @@ Both config-loading methods return a boolean indicating whether configuration da
77
73
 
78
74
  Chord.config_from_env or Chord.config_from_file('chord_config.yml')
79
75
 
76
+
77
+ # To Do
78
+
79
+ * tests should use mocks instead of real API requests
data/lib/chord/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/chord.rb CHANGED
@@ -45,33 +45,22 @@ module Chord
45
45
  def per_page; 99999; end
46
46
 
47
47
  def all
48
+ check_for_config!
48
49
  @all ||= fetch_all_data[base_path].map{ |i| new(i[id_attribute], i) }
49
50
  end
50
51
 
51
52
  def where(query_options = {})
53
+ check_for_config!
52
54
  fetch_all_data(query_options)[base_path].map{ |i| new(i[id_attribute], i) }
53
55
  end
54
56
 
55
57
  def find(id)
58
+ check_for_config!
56
59
  return nil if id.nil? or id == ''
57
60
  attrs = fetch_attributes(id)
58
61
  attrs.include?('error') ? nil : new(attrs[id_attribute], attrs)
59
62
  end
60
63
 
61
- def fetch_attributes(id)
62
- get(base_url + "#{base_path}/#{id}", http_options).parsed_response
63
- end
64
-
65
- def id_attribute
66
- 'id'
67
- end
68
-
69
- def fetch_all_data(query_options = {})
70
- query_options = { per_page: per_page }.merge(query_options)
71
- url = base_url + base_path + '?' + hash_to_query(query_options)
72
- get(url, http_options).parsed_response
73
- end
74
-
75
64
  def base_url
76
65
  Chord.base_url
77
66
  end
@@ -85,6 +74,28 @@ module Chord
85
74
 
86
75
  private # --------------------------------------------------------------
87
76
 
77
+ def id_attribute
78
+ 'id'
79
+ end
80
+
81
+ def fetch_attributes(id)
82
+ check_for_config!
83
+ get(base_url + "#{base_path}/#{id}", http_options).parsed_response or raise APIError, 'No data returned by API'
84
+ end
85
+
86
+ def fetch_all_data(query_options = {})
87
+ check_for_config!
88
+ query_options = { per_page: per_page }.merge(query_options)
89
+ url = base_url + base_path + '?' + hash_to_query(query_options)
90
+ get(url, http_options).parsed_response or raise APIError, 'No data returned by API'
91
+ end
92
+
93
+ def check_for_config!
94
+ if Chord.base_url.nil? or Chord.api_key.nil?
95
+ raise ConfigurationError, 'Please configure Chord by calling Chord.config(base_url: ..., api_key: ...)'
96
+ end
97
+ end
98
+
88
99
  def hash_to_query(hash)
89
100
  require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
90
101
  hash.collect{ |p|
@@ -114,14 +125,6 @@ module Chord
114
125
  end
115
126
 
116
127
  def update(new_attributes)
117
- new_attributes.stringify_keys!
118
- # merge values into existing metadata
119
- if new_attributes.include?('metadata')
120
- # Chord expects all metadata values to be strings
121
- new_metadata = new_attributes['metadata'].map{ |k,v| [k.to_s, v.to_s] }.to_h
122
- new_attributes['metadata'] = (attributes['metadata'] || {}).merge(new_metadata)
123
- # TODO: delete entries with empty value?
124
- end
125
128
  self.attributes = self.class.patch(base_url + "#{base_path}/#{id}",
126
129
  http_options.merge(body: new_attributes.to_json)
127
130
  ).parsed_response
@@ -134,7 +137,7 @@ module Chord
134
137
  # fetch all attributes, but don't overwrite existing ones,
135
138
  # in case changes have been made
136
139
  def expand!
137
- all_attributes = self.class.fetch_attributes(id)
140
+ all_attributes = self.class.send(:fetch_attributes, id)
138
141
  @attributes = all_attributes.merge(@attributes)
139
142
  end
140
143
 
@@ -266,4 +269,10 @@ module Chord
266
269
  'products'
267
270
  end
268
271
  end
272
+
273
+ class ConfigurationError < StandardError
274
+ end
275
+
276
+ class APIError < StandardError
277
+ end
269
278
  end
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.6
4
+ version: 0.0.7
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-21 00:00:00.000000000 Z
11
+ date: 2022-09-22 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.0.0
55
+ version: 2.5.0
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="