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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +5 -11
- data/bin/console +1 -4
- data/lib/chord/version.rb +1 -1
- data/lib/chord.rb +60 -30
- 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: b19cd9b9520300cd180df422f8ec819593113febc7a63cfedb23c1b727e83a24
|
4
|
+
data.tar.gz: 4d654b32483b583e853a624b3b8d6e955b2647cd962222c8dd4be13498c464e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
data/lib/chord/version.rb
CHANGED
data/lib/chord.rb
CHANGED
@@ -3,8 +3,24 @@ require 'httparty'
|
|
3
3
|
module Chord
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
33
|
+
def all
|
34
|
+
@all ||= fetch_all_data[base_path].map{ |i| new(i['id'], i) }
|
35
|
+
end
|
21
36
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
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-
|
11
|
+
date: 2022-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|