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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/chord/version.rb +1 -1
- data/lib/chord.rb +34 -28
- 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: 0d80163ac430fb1f71487c3a0656a89b110ebb4642169428675944ae5f97d241
|
4
|
+
data.tar.gz: 38ee178bc55275a7ea3e3b56538ec281daee425fa2885ecf5cb7580a77bbd356
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2422e06e382c5a9f8e752d79e45348582024318a7ec4858044cd0852174a66eb441772133d36f47f95033885c3a083e3de1d8ff041075c78498e8320a42b625e
|
7
|
+
data.tar.gz: 4acad1139ba34288cbb43c781e2bfe0d3c98b0ee3db9826cd025bbf5b269a11e776f22ce1e53c19bdb64f9910a4929d5dba351b22110084cbeb8dd466c7963d1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/chord/version.rb
CHANGED
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
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def all
|
18
|
+
@all ||= fetch_all_data[base_path].map{ |i| new(i['id'], i) }
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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.
|
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-
|
11
|
+
date: 2022-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|