Class: RPXNow::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/rpx_now/api.rb

Overview

low-level interaction with rpxnow.com api

  • send requests

  • parse response

  • handle server errors

Constant Summary collapse

HOST =
'rpxnow.com'
SSL_CERT =
File.join(File.dirname(__FILE__), '..', '..', 'certs', 'ssl_cert.pem')

Class Method Summary collapse

Class Method Details

.call(method, data) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/rpx_now/api.rb', line 14

def self.call(method, data)
  data = data.dup
  version = RPXNow.extract_version(data)
  data.delete(:api_version)

  path = "/api/v#{version}/#{method}"
  response = request(path, {:apiKey => RPXNow.api_key}.merge(data))
  parse_response(response)
end

.host(realm = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rpx_now/api.rb', line 24

def self.host(realm=nil)
  protocol = RPXNow.ssl ? 'https' : 'http'
  domain =
    if realm.nil?
      Api::HOST
    elsif realm.include?('.')
      realm
    else
      "#{realm}.#{Api::HOST}"
    end
  "#{protocol}://#{domain}"
end