Class: Increase::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/increase/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Client

Returns a new instance of Client.



28
29
30
# File 'lib/increase/client.rb', line 28

def initialize(config = nil)
  @configuration = config.is_a?(Configuration) ? config : Configuration.new(config)
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



21
22
23
# File 'lib/increase/client.rb', line 21

def configuration
  @configuration
end

Instance Method Details

#connectionObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/increase/client.rb', line 32

def connection
  Faraday.new(
    url: @configuration.base_url,
    headers: {
      Authorization: "Bearer #{@configuration.api_key}",
      "User-Agent": "Increase Ruby Gem v#{Increase::VERSION} (https://github.com/garyhtou/increase-ruby)"
    }
  ) do |f|
    f.request :json
    f.request :multipart

    if @configuration.raise_api_errors
      # This custom middleware for raising Increase API errors must be
      # located before the JSON response middleware.
      f.use Increase::Middleware::RaiseApiError
    end

    f.response :json
    f.response :follow_redirects
    f.adapter Faraday.default_adapter
  end
end