Class: Theoldreader::API::Service

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/theoldreader/api/service.rb

Constant Summary collapse

HOST =
'theoldreader.com'
BASE_PATH =
'/reader/api/0'
DEFAULT_MIDDLEWARE =
Proc.new do |builder|
  builder.request :url_encoded
  builder.adapter Faraday.default_adapter
end
FARADAY_OPTIONS =
%w{request proxy ssl builder url parallel_manager params headers builder_class}.map(&:to_sym)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



24
25
26
# File 'lib/theoldreader/api/service.rb', line 24

def initialize
  @http_options = {}
end

Instance Attribute Details

#faraday_middlewareObject

Returns the value of attribute faraday_middleware.



19
20
21
# File 'lib/theoldreader/api/service.rb', line 19

def faraday_middleware
  @faraday_middleware
end

#http_optionsObject

config of the http options for all requests from the client http_options can be set through Service.instance.http_options = false



22
23
24
# File 'lib/theoldreader/api/service.rb', line 22

def http_options
  @http_options
end

Instance Method Details

#make_request(verb, path, params, headers, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/theoldreader/api/service.rb', line 28

def make_request(verb, path, params, headers, options = {})
  # use ssl by default
  options[:use_ssl] ||= true
  options[:base_path] ||= BASE_PATH
  options[:host] ||= HOST
  # per request options will override the client options
  request_options = http_options.merge(options)

  conn = Faraday.new(service_url(options[:use_ssl], options[:host], options[:base_path]),
                     faraday_options(request_options), &(faraday_middleware || DEFAULT_MIDDLEWARE))
  response = conn.send(verb, path, params, headers)
  Theoldreader::API::Response.new(response.status.to_i, response.body, response.headers)
end