Class: ZapiAgent
- Inherits:
-
Object
- Object
- ZapiAgent
- Defined in:
- lib/zapi_agent.rb
Instance Attribute Summary collapse
-
#generate_xml ⇒ Object
readonly
Returns the value of attribute generate_xml.
-
#responder ⇒ Object
readonly
Returns the value of attribute responder.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#zapi ⇒ Object
readonly
Returns the value of attribute zapi.
Instance Method Summary collapse
- #_account_id ⇒ Object
- #_account_type ⇒ Object
- #_api_token ⇒ Object
- #_cart_id ⇒ Object
- #_firstname ⇒ Object
- #_fullname ⇒ Object
- #_lastname ⇒ Object
- #_login(username:, password:) ⇒ Object
- #_method_name ⇒ Object
- #_user_id ⇒ Object
- #_username ⇒ Object
- #history ⇒ Object
-
#initialize(username:, password:, zapi: nil, xml_generator: nil, responder: nil) ⇒ ZapiAgent
constructor
A new instance of ZapiAgent.
- #is_logged_in? ⇒ Boolean
- #response_msg ⇒ Object
- #session(hash: session_hash) ⇒ Object
- #session_hash ⇒ Object
Constructor Details
#initialize(username:, password:, zapi: nil, xml_generator: nil, responder: nil) ⇒ ZapiAgent
Returns a new instance of ZapiAgent.
5 6 7 8 9 10 |
# File 'lib/zapi_agent.rb', line 5 def initialize username:, password:, zapi: nil, xml_generator: nil, responder: nil @zapi = zapi || Zapi.new() @generate_xml = xml_generator || ZapiXML.new() @responder = responder || ZapiObject @response = _login username: username, password: password end |
Instance Attribute Details
#generate_xml ⇒ Object (readonly)
Returns the value of attribute generate_xml.
3 4 5 |
# File 'lib/zapi_agent.rb', line 3 def generate_xml @generate_xml end |
#responder ⇒ Object (readonly)
Returns the value of attribute responder.
3 4 5 |
# File 'lib/zapi_agent.rb', line 3 def responder @responder end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/zapi_agent.rb', line 3 def response @response end |
#zapi ⇒ Object (readonly)
Returns the value of attribute zapi.
3 4 5 |
# File 'lib/zapi_agent.rb', line 3 def zapi @zapi end |
Instance Method Details
#_account_id ⇒ Object
52 53 54 |
# File 'lib/zapi_agent.rb', line 52 def _account_id response.try(:[],'zapiAccountId').to_i end |
#_account_type ⇒ Object
56 57 58 |
# File 'lib/zapi_agent.rb', line 56 def _account_type response.try(:[],'zapiAccountType').to_i end |
#_api_token ⇒ Object
64 65 66 |
# File 'lib/zapi_agent.rb', line 64 def _api_token response.try(:[],'zapiApiToken') end |
#_cart_id ⇒ Object
60 61 62 |
# File 'lib/zapi_agent.rb', line 60 def _cart_id response.try(:[],'cartId') end |
#_firstname ⇒ Object
72 73 74 |
# File 'lib/zapi_agent.rb', line 72 def _firstname response.try(:[],'firstName') end |
#_fullname ⇒ Object
80 81 82 |
# File 'lib/zapi_agent.rb', line 80 def _fullname [_firstname, _lastname].compact.join(" ") if _firstname || _lastname end |
#_lastname ⇒ Object
76 77 78 |
# File 'lib/zapi_agent.rb', line 76 def _lastname response.try(:[],'lastName') end |
#_login(username:, password:) ⇒ Object
43 44 45 46 |
# File 'lib/zapi_agent.rb', line 43 def _login username:, password: login_xml = generate_xml.agent_login(username: username, password: password) zapi.request(xml: login_xml) end |
#_method_name ⇒ Object
84 85 86 |
# File 'lib/zapi_agent.rb', line 84 def _method_name response.try(:[],'methodName') end |
#_user_id ⇒ Object
48 49 50 |
# File 'lib/zapi_agent.rb', line 48 def _user_id response.try(:[],'zapiUserId').to_i end |
#_username ⇒ Object
68 69 70 |
# File 'lib/zapi_agent.rb', line 68 def _username response.try(:[],'zapiUsername') end |
#history ⇒ Object
20 21 22 23 |
# File 'lib/zapi_agent.rb', line 20 def history #raise response.inspect Zaui.agents_get_profile(agent_id: _user_id) end |
#is_logged_in? ⇒ Boolean
12 13 14 |
# File 'lib/zapi_agent.rb', line 12 def is_logged_in? response_msg == "Login Successful" && _method_name == 'zapiAgentLogin' end |
#response_msg ⇒ Object
16 17 18 |
# File 'lib/zapi_agent.rb', line 16 def response_msg response.try(:[],'methodErrorMessage') end |
#session(hash: session_hash) ⇒ Object
39 40 41 |
# File 'lib/zapi_agent.rb', line 39 def session hash: session_hash responder.new(hash: hash) end |
#session_hash ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zapi_agent.rb', line 25 def session_hash { user_id: _user_id, account_id: _account_id, account_type: _account_type, cart_id: _cart_id, api_token: _api_token, username: _username, firstname: _firstname, lastname: _lastname, fullname: _fullname } end |