class Coyodlee::RequestBuilder
Attributes
Public Class Methods
new(uri_builder)
click to toggle source
# File lib/coyodlee/connection.rb, line 14 def initialize(uri_builder) @uri_builder = uri_builder @session_authorization = SessionAuthorization.create end
Public Instance Methods
build(method, resource_path, headers: {}, params: {}, body: nil)
click to toggle source
# File lib/coyodlee/connection.rb, line 31 def build(method, resource_path, headers: {}, params: {}, body: nil) q = params.empty? ? nil : build_query(params) uri = @uri_builder.build(resource_path, query: q) http_constructor(method).new(uri).tap do |req| add_headers(req, headers) req.body = body if body end end
Private Instance Methods
add_headers(req, headers)
click to toggle source
# File lib/coyodlee/connection.rb, line 49 def add_headers(req, headers) if @session_authorization headers['Authorization'] = @session_authorization.to_s end headers.each do |key, value| req[key] = value end end
build_query(params)
click to toggle source
# File lib/coyodlee/connection.rb, line 42 def build_query(params) params .to_a .map { |keyval| keyval.join('=') } .join('&') end
http_constructor(method)
click to toggle source
# File lib/coyodlee/connection.rb, line 59 def http_constructor(method) case method when :get Net::HTTP::Get when :post Net::HTTP::Post when :put Net::HTTP::Put when :delete Net::HTTP::Delete end end