class GenesisClient::Client
Public Class Methods
new(options = {})
click to toggle source
# File lib/genesis_client/client.rb, line 7 def initialize(options = {}) @endpoint = options[:endpoint].to_s @token = options[:token].to_s raise ArgumentError, ":endpoint can't be blank" if @endpoint.empty? raise ArgumentError, ":token can't be blank" if @token.empty? end
Private Instance Methods
connection()
click to toggle source
Returns a Faraday::Connection object
@return [Faraday::Connection]
# File lib/genesis_client/client.rb, line 43 def connection @connection ||= Faraday.new @endpoint do |f| f.request :json f.headers[:user_agent] = GenesisClient::USER_AGENT f.headers['Authorization'] = "Token token=\"#{@token}\"" # f.response :logger f.response :mashify f.response :json, content_type: /\bjson$/ f.adapter Faraday.default_adapter end end
get(path, options = {})
click to toggle source
# File lib/genesis_client/client.rb, line 19 def get(path, options = {}) request(:get, path, options) end
post(path, data = {})
click to toggle source
# File lib/genesis_client/client.rb, line 23 def post(path, data = {}) request(:post, path, data) end
put(path, data = {})
click to toggle source
# File lib/genesis_client/client.rb, line 27 def put(path, data = {}) request(:put, path, data) end
request(method, path, data = {})
click to toggle source
# File lib/genesis_client/client.rb, line 31 def request(method, path, data = {}) res = connection.send(method, "api/#{path}", data) if res.success? && !res.body.nil? && !res.body.empty? && res.body != ' ' res.body else res end end