module Polr::Api
Public Class Methods
api_key()
click to toggle source
# File lib/polr/api.rb, line 16 def self.api_key Polr.configuration.api_key end
api_url(path = nil)
click to toggle source
# File lib/polr/api.rb, line 12 def self.api_url(path = nil) %(#{Polr.configuration.api_url}/api/#{API_VERSION}/action/#{path}) end
process() { || ... }
click to toggle source
# File lib/polr/api.rb, line 20 def self.process JSON.parse(yield).with_indifferent_access rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e # API unreachable raise Polr::Error, 'Polr API is unreachable' rescue RestClient::Exception => e # HTTP status error result = (begin JSON.parse(e.response) rescue StandardError {} end) raise Polr::Error, result['error'] || 'undefined error' rescue JSON::ParserError => e # JSON error raise Polr::Error, e.message end
request(path, params)
click to toggle source
# File lib/polr/api.rb, line 35 def self.request(path, params) RestClient.get(Api.api_url(path.to_s), params: params.merge(key: Api.api_key, response_type: :json), content_type: :json, accept: :json, timeout: 10) end