Class: ActiveCampaign::Client

Inherits:
Object
  • Object
show all
Includes:
API, TransformHash
Defined in:
lib/active_campaign/client.rb

Overview

Provides http request functionality

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf = {}) ⇒ Client

Returns a new instance of Client.



22
23
24
# File 'lib/active_campaign/client.rb', line 22

def initialize(conf = {})
  @config = conf
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



20
21
22
# File 'lib/active_campaign/client.rb', line 20

def config
  @config
end

Instance Method Details

#connectionObject

rubocop:disable Metrics/AbcSize



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_campaign/client.rb', line 26

def connection # rubocop:disable Metrics/AbcSize
  @connection ||= ::Faraday.new(url: config[:api_url]) do |faraday|
    ActiveCampaign::Faraday::Middleware.add_request_middleware(faraday, config)
    ActiveCampaign::Faraday::Middleware.add_response_middleware(faraday, config[:response_middleware])

    faraday.adapter config[:adapter]

    if (options = faraday.options)
      options.timeout      = config[:api_timeout]
      options.open_timeout = options.timeout
    end

    faraday
  end
end

#delete(*args) ⇒ Object



54
55
56
57
58
# File 'lib/active_campaign/client.rb', line 54

def delete(*args)
  safe_http_call do
    connection.delete(*args)
  end
end

#get(*args) ⇒ Object



60
61
62
63
64
# File 'lib/active_campaign/client.rb', line 60

def get(*args)
  safe_http_call do
    connection.get(*args)
  end
end

#post(*args) ⇒ Object



42
43
44
45
46
# File 'lib/active_campaign/client.rb', line 42

def post(*args)
  safe_http_call do
    connection.post(*args)
  end
end

#put(*args) ⇒ Object



48
49
50
51
52
# File 'lib/active_campaign/client.rb', line 48

def put(*args)
  safe_http_call do
    connection.put(*args)
  end
end

#transform_key(key, *new_case) ⇒ Symbol Originally defined in module TransformHash

Transform the provided keys case and lastly symbolize it

Parameters:

  • key (String, Symbol)

    the name of the key to change case

  • new_case (Symbol, Symbol)

    the new case eg. :underscore or :camelcase, :lower

Returns:

  • (Symbol)

    the transformed key

#transform_keys(hash, *new_case) ⇒ Hash Originally defined in module TransformHash

Note:

this is used to always output a hash response

Transforms case of all hash keys

Parameters:

  • hash (Hash)

    initial hash before transformation

  • new_case (Symbol, Symbol)

    the new case eg. :underscore or :camelcase, :lower

Returns:

  • (Hash)

#transform_value(value, *new_case) ⇒ Object Originally defined in module TransformHash

Note:

used for nested values like hashes and arrays

Transform all values

Parameters:

  • value (Object)

    the value to transform

  • new_case (Symbol, Symbol)

    the new case eg. :underscore or :camelcase, :lower

Returns:

  • (Object)