class Croudia::Client

Public Class Methods

new(options={}) click to toggle source

Initialize a new Client object

@param [Hash] options

# File lib/croudia/client.rb, line 34
def initialize(options={})
  Croudia::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Croudia.instance_variable_get(:"@#{key}"))
  end
end

Public Instance Methods

delete(path, params={}) click to toggle source

Perform an HTTP DELETE request

# File lib/croudia/client.rb, line 41
def delete(path, params={})
  request(:delete, path, params)
end
get(path, params={}) click to toggle source

Perform an HTTP GET request

# File lib/croudia/client.rb, line 46
def get(path, params={})
  request(:get, path, params)
end
post(path, params={}) click to toggle source

Perform an HTTP POST request

# File lib/croudia/client.rb, line 51
def post(path, params={})
  request(:post, path, params)
end
put(path, params={}) click to toggle source

Perform an HTTP PUT request

# File lib/croudia/client.rb, line 56
def put(path, params={})
  request(:put, path, params)
end

Private Instance Methods

connection() click to toggle source

Return a Faraday::Connection objet

@return [Faraday::Connection]

# File lib/croudia/client.rb, line 72
def connection
  @connection ||= Faraday.new(@endpoint, @connection_options.merge(builder: @middleware))
end
request(method, path, params={}) click to toggle source

@return [String] Response body

# File lib/croudia/client.rb, line 63
def request(method, path, params={})
  connection.send(method.to_sym, path, params) do |request|
    request.headers[:authorization] = "Bearer #{@access_token}" if @access_token
  end.body
end