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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64509e85be57dcc511d83fd3d6e3e618b514df6c303fb4a02e726d115bfac9b0
4
- data.tar.gz: 5a14982c46a12344c65ea41b3c7ce1b55315c7a878499db4c338606acd8d6ba4
3
+ metadata.gz: 244d535b9b207228adf3e369095795b614ad8a1f8d11b65d061d8d8221fb5803
4
+ data.tar.gz: 92af48704ef825497a0b6d83dfb45778f5f6e0021fc4d92b9c9e0ecdfca7410d
5
5
  SHA512:
6
- metadata.gz: 82cf3fce2f905fc903b92f4bd765a2f9ffc1e39961952d744200ed476768fb832169f5725dbd94337531cc3b19fd886f9ba778d01754d24c36142a15c4894db3
7
- data.tar.gz: 1165baf24e244defc497b04c229e684623c5ea18cc4b527fba452279f5c5e72f27f0d019a9dbe670395a7448ea73c70dfc5bff94e0737d5ab1c9685a4f8f0ef4
6
+ metadata.gz: 590718ca6a66a73d1a7a88ca7d35a90bd65a4a8b97731fe98ad00617aae5624e014e1b4c7306f960c9bfbff61117a7fa758ea2a9d1988a27f42111a7f703f678
7
+ data.tar.gz: 24c492f39b77aaaf2568a8f7d29a69a13937f4e13a7f1c9cfa61b5833dca60bd17ea5cff7d64a497dc0cda8e634235af648137dde2cb95101d8b040c8556b715
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- splinter-pto (0.1.5)
4
+ splinter-pto (0.1.6)
5
5
  rest-client (~> 2.0)
6
6
 
7
7
  GEM
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
- headers = { 'Authorization': "Token #{Splinter.configuration.api_key}" }
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
- headers = { 'Authorization': "Token #{Splinter.configuration.api_key}" }
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.merge({ params: params }))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Splinter
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splinter-pto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lien Van Den Steen