Class: Patronage::API

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

Instance Method Summary collapse

Constructor Details

#initialize(base_url, options = {}) ⇒ API

Returns a new instance of API.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/patronage/api.rb', line 3

def initialize(base_url, options = {})
  @session          = ::Patron::Session.new
  @session.base_url = base_url
  @default_params   = options.delete(:params) || {}

  options.each do |key, value|
    if @session.public_methods.include?("#{key}=")
      send("#{key}=", value)
    end
  end
end

Instance Method Details

#get(url, headers = {}) ⇒ Object



15
16
17
18
19
# File 'lib/patronage/api.rb', line 15

def get(url, headers = {})
  url = ::Addressable::URI.parse(url)
  url.query_values = url.query_values.merge(@default_params)
  @session.get(url.to_s, headers)
end

#service(service_name, opts = {}) ⇒ Object



21
22
23
# File 'lib/patronage/api.rb', line 21

def service(service_name, opts = {})
  Service.new(self, service_name, opts)
end