Module: Polr::Api
- Defined in:
- lib/polr/api.rb
Class Method Summary collapse
Class Method Details
.api_key ⇒ Object
16 17 18 |
# File 'lib/polr/api.rb', line 16 def self.api_key Polr.configuration.api_key end |
.api_url(path = nil) ⇒ Object
12 13 14 |
# File 'lib/polr/api.rb', line 12 def self.api_url(path = nil) %(#{Polr.configuration.api_url}/api/#{API_VERSION}/action/#{path}) end |
.process ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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. end |