class Fleetly::Client

Attributes

api_url[R]
token[R]

Public Class Methods

new(options={}) click to toggle source

Create a new Fleetly::Client object

@params options

# File lib/fleetly/client.rb, line 23
def initialize(options={})
  @api_url = options[:api_url] || Fleetly.api_url
  @token = options[:token] || Fleetly.token
end

Public Instance Methods

connection() click to toggle source

Create a Faraday::Connection object

@return [Faraday::Connection]

# File lib/fleetly/client.rb, line 32
def connection
  params = {}
  @connection = Faraday.new(url: api_url, params: params, headers: default_headers) do |faraday|
    faraday.use FaradayMiddleware::Mashify
    faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
    faraday.use FaradayMiddleware::FollowRedirects
    faraday.adapter Faraday.default_adapter
  end
end

Private Instance Methods

default_headers() click to toggle source
# File lib/fleetly/client.rb, line 44
def default_headers
  headers = {
    accept: 'application/json',
    content_type: 'application/json',
    user_agent: "Ruby Gem by Validic #{Fleetly::VERSION}"
  }
end