Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/infusionsoft/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Configuration
VALID_OPTION_KEYS = [
:api_url,
:api_key,
:api_token,
:api_logger,
:use_oauth,
:user_agent # allows you to change the User-Agent of the request headers
Expand Down Expand Up @@ -48,6 +49,10 @@ def user_agent
def api_logger
@api_logger || Infusionsoft::APILogger.new
end

def api_key
@api_key || 'na'
end
end

end
18 changes: 16 additions & 2 deletions lib/infusionsoft/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ module Infusionsoft
module Connection
private


def connection(service_call, *args)
path = use_oauth ? "/crm/xmlrpc/v1?access_token=#{api_key}" : "/api/xmlrpc"

headers = {'User-Agent' => user_agent}

if api_token
api_url = 'api.infusionsoft.com'
path = "/crm/xmlrpc/v1"
headers["X-Keap-API-Key"] = api_token
elsif use_oauth
path = "/crm/xmlrpc/v1?access_token=#{api_key}"
else
path = "/api/xmlrpc"
end

client = XMLRPC::Client.new3({
'host' => api_url,
'path' => path,
'port' => 443,
'use_ssl' => true
})
client.http_header_extra = {'User-Agent' => user_agent}

client.http_header_extra = headers

begin
api_logger.info "CALL: #{service_call} api_url: #{api_url} at:#{Time.now} args:#{args.inspect}"
result = client.call("#{service_call}", api_key, *args)
Expand Down