Class: KashflowApi::Client
- Inherits:
-
Object
- Object
- KashflowApi::Client
- Includes:
- Expects
- Defined in:
- lib/kashflow_api/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #call(api_call) ⇒ Object
- #handle_errors(hash) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 |
# File 'lib/kashflow_api/client.rb', line 7 def initialize(config) expects config, KashflowApi::Config @config = config @url = "https://securedwebapp.com/api/service.asmx?WSDL" @client = Savon.client(wsdl: @url, log: @config.loggers) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/kashflow_api/client.rb', line 5 def client @client end |
Instance Method Details
#call(api_call) ⇒ Object
15 16 17 18 19 |
# File 'lib/kashflow_api/client.rb', line 15 def call(api_call) result = @client.call(api_call.method_sym, xml: api_call.xml) handle_errors(result.to_hash) return result end |
#handle_errors(hash) ⇒ Object
21 22 23 24 25 |
# File 'lib/kashflow_api/client.rb', line 21 def handle_errors(hash) raise "Incorrect username or password" if hash.first.last[:status_detail] == "Incorrect username or password" raise "Your IP Address is not in the access list!" if hash.first.last[:status_detail] =~ /The IP address of .*? is not in the access list/ raise "Kashflow Error: #{result.to_hash.first.last[:status_detail]}" if hash.first.last[:status] == "NO" end |