chord 0.0.1 → 0.0.3

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: ecdb151eb16d8e1187e7ae8a6bf59cd57895580ba5c578fd166ed5b2c795da16
4
- data.tar.gz: 33bb400c1a6c0f6df638125ebc86d6fa54f513075e994756e71daf72a1cc198d
3
+ metadata.gz: b19cd9b9520300cd180df422f8ec819593113febc7a63cfedb23c1b727e83a24
4
+ data.tar.gz: 4d654b32483b583e853a624b3b8d6e955b2647cd962222c8dd4be13498c464e4
5
5
  SHA512:
6
- metadata.gz: cac1d8dfeb749f6e8e5e12776031973755f73e4976ed6bb4505fc464eb92b43942cffed3251ccb34d9013fbfab3ee4b32648c257107bac885b90e11231a27810
7
- data.tar.gz: 1c95d655de397bd5b0d88c46d924ce8dbdd760bde3e17a16a38bf4dc7c262a8127a7f662ab9eacd5eb91315a5b9645cbea918a09a040eb0df281846f7ed5ab20
6
+ metadata.gz: 7ecca2abcf3397c438bd15ff7fbf286ec2d867742cdfccb0b374cba05725db58fc59ce14da8fee4e7c1cb7347a48558ae7b79e9f30784ce352d261ea72a12576
7
+ data.tar.gz: 41bb0c8b107cb4ef7bc1fbbd930061097252d5ae5d2eb423935dc9c4c79d15ed1e4805f091d2ad64794ffa2f5282da084e1eeedc078d2446feff7dbc62e61553
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Major changes for each release. Please see the Git log for complete list of changes.
4
4
 
5
+ ## 0.0.3
6
+
7
+ * Refactor configuration.
8
+
9
+ ## 0.0.2
10
+
11
+ * Don't memoize filtered queries.
12
+
5
13
  ## 0.0.1
6
14
 
7
15
  * Very rudimentary start, focused on the parts of the API I need to use.
data/README.md CHANGED
@@ -1,17 +1,11 @@
1
- # Chord OMS
1
+ # Chord Commerce OMS API Gem
2
2
 
3
3
  These classes provide simple read and write access to the Chord OMS API. Get started like this:
4
4
 
5
- CHORD_API_CONFIG = {
6
- staging: {
7
- base_url: 'https://<customer>.staging.assembly-api.com/api/',
8
- api_key: '<key>'
9
- },
10
- production: {
11
- base_url: 'https://<customer>.assembly-api.com/api/',
12
- api_key: '<key>'
13
- }
14
- }
5
+ Chord.config(
6
+ base_url: 'https://<customer>.staging.assembly-api.com/api/',
7
+ api_key: '<key>'
8
+ )
15
9
 
16
10
  u = Chord::User.find(1) # fetch user
17
11
  u.attributes # see attributes hash
data/bin/console CHANGED
@@ -3,10 +3,7 @@
3
3
  require 'bundler/setup'
4
4
  require 'chord'
5
5
 
6
- if File.exist?('config.yml')
7
- require 'yaml'
8
- CHORD_API_CONFIG = YAML.load(File.read('config.yml'), symbolize_names: true)
9
- end
6
+ Chord.config_from_file('config.yml')
10
7
 
11
8
  require 'irb'
12
9
  IRB.start
data/lib/chord/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/chord.rb CHANGED
@@ -3,8 +3,24 @@ require 'httparty'
3
3
  module Chord
4
4
 
5
5
  class << self
6
- attr_writer :env
7
- def env; @env || :staging; end # :staging by default
6
+ attr_accessor :base_url
7
+ attr_accessor :api_key
8
+
9
+ def config(options)
10
+ self.base_url = options[:base_url]
11
+ self.api_key = options[:api_key]
12
+ end
13
+
14
+ def config_from_file(filepath)
15
+ if File.exist?(filepath)
16
+ require 'yaml'
17
+ config = YAML.load(File.read(filepath), symbolize_names: true)
18
+ Chord.config(
19
+ base_url: config[:base_url],
20
+ api_key: config[:api_key]
21
+ )
22
+ end
23
+ end
8
24
  end
9
25
 
10
26
  class Base
@@ -13,40 +29,46 @@ module Chord
13
29
  class << self
14
30
  attr_writer :per_page
15
31
  def per_page; @per_page || 99999; end
16
- end
17
32
 
18
- def self.base_url
19
- CHORD_API_CONFIG[Chord.env][:base_url]
20
- end
33
+ def all
34
+ @all ||= fetch_all_data[base_path].map{ |i| new(i['id'], i) }
35
+ end
21
36
 
22
- def self.find(id)
23
- attrs = get(base_url + "#{base_path}/#{id}", http_options).parsed_response
24
- new(id, attrs)
25
- end
37
+ def where(query_options = {})
38
+ fetch_all_data(query_options)[base_path].map{ |i| new(i['id'], i) }
39
+ end
26
40
 
27
- def self.fetch_all_data(query_options = {})
28
- query_options = {
29
- per_page: per_page
30
- }.merge(query_options)
31
- get(base_url + "#{base_path}?#{hash_to_query(query_options)}", http_options).parsed_response
32
- end
41
+ def find(id)
42
+ return nil if id.nil? or id == ''
43
+ attrs = get(base_url + "#{base_path}/#{id}", http_options).parsed_response
44
+ attrs.include?('error') ? nil : new(id, attrs)
45
+ end
33
46
 
34
- def self.all(query_options = {})
35
- @all ||= fetch_all_data(query_options)[base_path].map{ |i| new(i['id'], i) }
36
- end
47
+ def fetch_all_data(query_options = {})
48
+ query_options = { per_page: per_page }.merge(query_options)
49
+ url = base_url + base_path + '?' + hash_to_query(query_options)
50
+ get(url, http_options).parsed_response
51
+ end
37
52
 
38
- def self.http_options
39
- {headers: {
40
- 'Authorization' => "Bearer #{CHORD_API_CONFIG[Chord.env][:api_key]}",
41
- 'Content-Type' => 'application/json'
42
- }}
43
- end
53
+ def base_url
54
+ Chord.base_url
55
+ end
56
+
57
+ def http_options
58
+ {headers: {
59
+ 'Authorization' => "Bearer #{Chord.api_key}",
60
+ 'Content-Type' => 'application/json'
61
+ }}
62
+ end
63
+
64
+ private # --------------------------------------------------------------
44
65
 
45
- def self.hash_to_query(hash)
46
- require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
47
- hash.collect{ |p|
48
- p[1].nil? ? nil : p.map{ |i| CGI.escape i.to_s } * '='
49
- }.compact.sort * '&'
66
+ def hash_to_query(hash)
67
+ require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
68
+ hash.collect{ |p|
69
+ p[1].nil? ? nil : p.map{ |i| CGI.escape i.to_s } * '='
70
+ }.compact.sort * '&'
71
+ end
50
72
  end
51
73
 
52
74
  def base_url
@@ -170,6 +192,14 @@ module Chord
170
192
  http_options.merge(body: attributes.to_json)
171
193
  ).parsed_response
172
194
  end
195
+
196
+ def subscription_installment?
197
+ channel == 'subscriptions'
198
+ end
199
+
200
+ def subscription_start?
201
+ subscription_in_cart
202
+ end
173
203
  end
174
204
 
175
205
 
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.1
4
+ version: 0.0.3
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-19 00:00:00.000000000 Z
11
+ date: 2022-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty