Skip to content

Instantly share code, notes, and snippets.

@petedickson
Created March 9, 2011 20:25
Show Gist options
  • Save petedickson/862929 to your computer and use it in GitHub Desktop.
Save petedickson/862929 to your computer and use it in GitHub Desktop.
NoMethodError
require "xmlrpc/client"
class InfusionsoftApiConnection
attr_accessor :api_url, :api_key, :retry_count
def initialize(url, key)
@api_url = url
@api_key = key
@retry_count = 1
end
def api_perform(class_type, method, *args)
begin
server = XMLRPC::Client.new3({'host' => @api_url, 'path' => "/api/xmlrpc", 'port' => 443, 'use_ssl' => true})
result = server.call("#{class_type}.#{method}", @api_key, *args)
if result.nil?; raise RetryException.new(true, @retry_count), "transient read error" end
rescue RetryException => detail
# Catch for transietn Infusionsoft connection errors
puts "*** INFUSION API ERROR: Transient read error *** retrying: #{@retry_count}"
self.retry_count += 1
retry if detail.ok_to_retry
rescue XMLRPC::FaultException => e
puts "*** INFUSION API ERROR: #{e.faultCode} - #{e.faultString} ***"
.
.
.
end
return result
end
module ApiInfusionsoft
# Set account specific InfusionsoftApiConnection obj
def self.set_account_apiconn(url, key)
if ac = Thread.current[:api_conn]
ac.api_url, ac.api_key = url, key
else
Thread.current[:api_conn] = InfusionsoftApiConnection.new(url, key)
end
end
.
.
.
def api_data_authenticate_user(username, password)
# Authenticates a user account in Infusionsoft
Thread.current[:api_conn].api_perform('DataService', 'authenticateUser', username, password)
end
.
.
.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment