splinter-pto 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/splinter/api.rb +17 -5
- data/lib/splinter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 244d535b9b207228adf3e369095795b614ad8a1f8d11b65d061d8d8221fb5803
|
4
|
+
data.tar.gz: 92af48704ef825497a0b6d83dfb45778f5f6e0021fc4d92b9c9e0ecdfca7410d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 590718ca6a66a73d1a7a88ca7d35a90bd65a4a8b97731fe98ad00617aae5624e014e1b4c7306f960c9bfbff61117a7fa758ea2a9d1988a27f42111a7f703f678
|
7
|
+
data.tar.gz: 24c492f39b77aaaf2568a8f7d29a69a13937f4e13a7f1c9cfa61b5833dca60bd17ea5cff7d64a497dc0cda8e634235af648137dde2cb95101d8b040c8556b715
|
data/Gemfile.lock
CHANGED
data/lib/splinter/api.rb
CHANGED
@@ -2,29 +2,41 @@
|
|
2
2
|
|
3
3
|
require 'rest-client'
|
4
4
|
require 'json'
|
5
|
+
require 'uri'
|
5
6
|
|
6
7
|
module Splinter
|
7
8
|
class API
|
8
9
|
BASE_URL = 'https://ninja-bot.treehoppr.com/api/beta'
|
9
10
|
|
10
11
|
def self.get(endpoint)
|
11
|
-
|
12
|
-
response = RestClient.get("#{BASE_URL}/#{endpoint}", headers)
|
12
|
+
response = RestClient.get(build_url(endpoint), headers)
|
13
13
|
JSON.parse(response.body)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.paginated_get(endpoint, params = {})
|
17
|
-
|
18
|
-
url = "#{BASE_URL}/#{endpoint}"
|
17
|
+
url = build_url(endpoint, params)
|
19
18
|
results = []
|
19
|
+
|
20
20
|
loop do
|
21
|
-
result = RestClient.get(url, headers
|
21
|
+
result = RestClient.get(url, headers)
|
22
22
|
parsed_result = JSON.parse(result.body)
|
23
23
|
results.concat(parsed_result['results'])
|
24
24
|
url = parsed_result.dig('next')
|
25
25
|
break if url.nil?
|
26
26
|
end
|
27
|
+
|
27
28
|
results
|
28
29
|
end
|
30
|
+
|
31
|
+
def self.headers
|
32
|
+
{ 'Authorization': "Token #{Splinter.configuration.api_key}" }
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.build_url(endpoint, params = {})
|
36
|
+
url = "#{BASE_URL}/#{endpoint}"
|
37
|
+
url += "?#{URI.encode_www_form(params)}" unless params.empty?
|
38
|
+
|
39
|
+
url
|
40
|
+
end
|
29
41
|
end
|
30
42
|
end
|
data/lib/splinter/version.rb
CHANGED