class Yousty::HTTP::Connection
Sends actual requests to the Gallery API server
Constants
- DEFAULT_HEADERS
Attributes
connection[R]
Public Class Methods
new(host, auth_token: nil, connection: nil)
click to toggle source
# File lib/yousty/http/connection.rb, line 39 def initialize(host, auth_token: nil, connection: nil) @connection = connection || Faraday.new(url: host, headers: DEFAULT_HEADERS) authorize!(auth_token) if auth_token end
Public Instance Methods
call(method_name, path, body: {}, headers: {})
click to toggle source
@param [Symbol] - A name of HTTP
method to be sent: [:get, :patch, :put, :post, :delete] @param [String] - A path to the called endpoint @param body [Hash] - Request body to be sent to the server @param headers [Hash] - Custom request headers to be merged into the default ones @return Faraday::Response
# File lib/yousty/http/connection.rb, line 23 def call(method_name, path, body: {}, headers: {}) request_method = RequestMethod.new(method_name) connection.method(request_method.to_s).call(path) do |req| req.headers = req.headers.merge(headers) req.body = JSON.generate(body) end end