class Recruitee::HTTP::Client
Constants
- DEFAULT_DOMAIN
Attributes
options[R]
prefix[R]
recruitee[R]
Public Class Methods
new(recruitee, options = {})
click to toggle source
# File lib/recruitee/http/client.rb, line 10 def initialize(recruitee, options = {}) raise ArgumentError if recruitee.nil? @recruitee = recruitee @prefix = options[:prefix] || "/c/#{@recruitee.company_id}" @options = options end
Public Instance Methods
request(method, path, params: nil, body: nil, headers: {})
click to toggle source
# File lib/recruitee/http/client.rb, line 18 def request(method, path, params: nil, body: nil, headers: {}) res = connection.send(method.downcase.to_sym, prefixed(path)) do |req| req.body = body unless body.nil? req.params = params unless params.nil? req.headers = default_headers.merge(headers) end Recruitee::Response.new(res.status, res.body, headers: res.headers) end
Private Instance Methods
connection()
click to toggle source
# File lib/recruitee/http/client.rb, line 43 def connection @_connection ||= Faraday.new(url: domain, ssl: { verify: true }) do |f| f.options.params_encoder = Faraday::FlatParamsEncoder f.request :json f.request :url_encoded f.response :logger if options[:debug] f.adapter Faraday.default_adapter end end
default_headers()
click to toggle source
# File lib/recruitee/http/client.rb, line 30 def default_headers { 'Accept-Charset': 'utf-8', 'Authorization': "Bearer #{@recruitee.api_token}", 'Content-Type': 'application/json', 'Accept': 'application/json' } end
domain()
click to toggle source
# File lib/recruitee/http/client.rb, line 39 def domain options[:domain] || DEFAULT_DOMAIN end
prefixed(path)
click to toggle source
# File lib/recruitee/http/client.rb, line 53 def prefixed(path) "#{prefix}#{path}" end