chord 0.0.1 → 0.0.2

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: 0d80163ac430fb1f71487c3a0656a89b110ebb4642169428675944ae5f97d241
4
+ data.tar.gz: 38ee178bc55275a7ea3e3b56538ec281daee425fa2885ecf5cb7580a77bbd356
5
5
  SHA512:
6
- metadata.gz: cac1d8dfeb749f6e8e5e12776031973755f73e4976ed6bb4505fc464eb92b43942cffed3251ccb34d9013fbfab3ee4b32648c257107bac885b90e11231a27810
7
- data.tar.gz: 1c95d655de397bd5b0d88c46d924ce8dbdd760bde3e17a16a38bf4dc7c262a8127a7f662ab9eacd5eb91315a5b9645cbea918a09a040eb0df281846f7ed5ab20
6
+ metadata.gz: 2422e06e382c5a9f8e752d79e45348582024318a7ec4858044cd0852174a66eb441772133d36f47f95033885c3a083e3de1d8ff041075c78498e8320a42b625e
7
+ data.tar.gz: 4acad1139ba34288cbb43c781e2bfe0d3c98b0ee3db9826cd025bbf5b269a11e776f22ce1e53c19bdb64f9910a4929d5dba351b22110084cbeb8dd466c7963d1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Major changes for each release. Please see the Git log for complete list of changes.
4
4
 
5
+ ## 0.0.2
6
+
7
+ * Don't memoize filtered queries.
8
+
5
9
  ## 0.0.1
6
10
 
7
11
  * Very rudimentary start, focused on the parts of the API I need to use.
data/README.md CHANGED
@@ -1,4 +1,4 @@
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
 
data/lib/chord/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Chord
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/chord.rb CHANGED
@@ -13,40 +13,46 @@ module Chord
13
13
  class << self
14
14
  attr_writer :per_page
15
15
  def per_page; @per_page || 99999; end
16
- end
17
16
 
18
- def self.base_url
19
- CHORD_API_CONFIG[Chord.env][:base_url]
20
- end
17
+ def all
18
+ @all ||= fetch_all_data[base_path].map{ |i| new(i['id'], i) }
19
+ end
21
20
 
22
- def self.find(id)
23
- attrs = get(base_url + "#{base_path}/#{id}", http_options).parsed_response
24
- new(id, attrs)
25
- end
21
+ def where(query_options = {})
22
+ fetch_all_data(query_options)[base_path].map{ |i| new(i['id'], i) }
23
+ end
26
24
 
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
25
+ def find(id)
26
+ return nil if id.nil? or id == ''
27
+ attrs = get(base_url + "#{base_path}/#{id}", http_options).parsed_response
28
+ attrs.include?('error') ? nil : new(id, attrs)
29
+ end
33
30
 
34
- def self.all(query_options = {})
35
- @all ||= fetch_all_data(query_options)[base_path].map{ |i| new(i['id'], i) }
36
- end
31
+ def fetch_all_data(query_options = {})
32
+ query_options = { per_page: per_page }.merge(query_options)
33
+ url = base_url + base_path + '?' + hash_to_query(query_options)
34
+ get(url, http_options).parsed_response
35
+ end
37
36
 
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
37
+ def base_url
38
+ CHORD_API_CONFIG[Chord.env][:base_url]
39
+ end
44
40
 
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 * '&'
41
+ def http_options
42
+ {headers: {
43
+ 'Authorization' => "Bearer #{CHORD_API_CONFIG[Chord.env][:api_key]}",
44
+ 'Content-Type' => 'application/json'
45
+ }}
46
+ end
47
+
48
+ private # --------------------------------------------------------------
49
+
50
+ def hash_to_query(hash)
51
+ require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
52
+ hash.collect{ |p|
53
+ p[1].nil? ? nil : p.map{ |i| CGI.escape i.to_s } * '='
54
+ }.compact.sort * '&'
55
+ end
50
56
  end
51
57
 
52
58
  def base_url
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.2
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