Class: Splinter::API
- Inherits:
-
Object
- Object
- Splinter::API
- Defined in:
- lib/splinter/api.rb
Constant Summary collapse
- BASE_URL =
'https://ninja.tryroots.io/api/beta'
Class Method Summary collapse
- .build_url(endpoint, params = {}) ⇒ Object
- .get(endpoint) ⇒ Object
- .headers ⇒ Object
- .paginated_get(endpoint, params = {}) ⇒ Object
Class Method Details
.build_url(endpoint, params = {}) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/splinter/api.rb', line 35 def self.build_url(endpoint, params = {}) url = "#{BASE_URL}/#{endpoint}" url += "?#{URI.encode_www_form(params)}" unless params.empty? url end |
.get(endpoint) ⇒ Object
11 12 13 14 |
# File 'lib/splinter/api.rb', line 11 def self.get(endpoint) response = RestClient.get(build_url(endpoint), headers) JSON.parse(response.body) end |
.headers ⇒ Object
31 32 33 |
# File 'lib/splinter/api.rb', line 31 def self.headers { Authorization: "Token #{Splinter.configuration.api_key}" } end |
.paginated_get(endpoint, params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/splinter/api.rb', line 16 def self.paginated_get(endpoint, params = {}) url = build_url(endpoint, params) results = [] loop do result = RestClient.get(url, headers) parsed_result = JSON.parse(result.body) results.concat(parsed_result['results']) url = parsed_result&.dig('next')&.gsub('http:', 'https:') break if url.nil? end results end |