Class: KashflowApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/kashflow_api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



3
4
5
6
7
8
# File 'lib/kashflow_api/client.rb', line 3

def initialize(config)
    @config = config
    @url = "https://securedwebapp.com/api/service.asmx?WSDL"
    
    @client = Savon::Client.new @url
end

Instance Method Details

#call(api_call) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/kashflow_api/client.rb', line 10

def call(api_call)
    result = @client.request("KashFlow/#{api_call.method}") do |soap|
        soap.xml = api_call.xml
    end
    raise "Incorrect username or password" if result.to_hash.first.last[:status_detail] == "Incorrect username or password"
    raise "Your IP Address is not in the access list!" if result.to_hash.first.last[:status_detail] =~ /The IP address of .*? is not in the access list/
    #raise api_call.xml if result.to_hash.first.last[:status] == "NO"
    raise "Kashflow Error: #{result.to_hash.first.last[:status_detail]}" if result.to_hash.first.last[:status] == "NO"
    return result
end

#clientObject



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

def client
    @client
end