Class: ZapiEmployee
- Inherits:
-
Object
- Object
- ZapiEmployee
- Defined in:
- lib/zapi_employee.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
-
#initialize(username:, password:, zapi: nil, xml_generator: nil, responder: nil) ⇒ ZapiEmployee
constructor
A new instance of ZapiEmployee.
- #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) ⇒ ZapiEmployee
Returns a new instance of ZapiEmployee.
5 6 7 8 9 10 |
# File 'lib/zapi_employee.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_employee.rb', line 3 def generate_xml @generate_xml end |
#responder ⇒ Object (readonly)
Returns the value of attribute responder.
3 4 5 |
# File 'lib/zapi_employee.rb', line 3 def responder @responder end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/zapi_employee.rb', line 3 def response @response end |
#zapi ⇒ Object (readonly)
Returns the value of attribute zapi.
3 4 5 |
# File 'lib/zapi_employee.rb', line 3 def zapi @zapi end |
Instance Method Details
#_account_id ⇒ Object
47 48 49 |
# File 'lib/zapi_employee.rb', line 47 def _account_id response.try(:[],'zapiAccountId').to_i end |
#_account_type ⇒ Object
51 52 53 |
# File 'lib/zapi_employee.rb', line 51 def _account_type response.try(:[],'zapiAccountType').to_i end |
#_api_token ⇒ Object
59 60 61 |
# File 'lib/zapi_employee.rb', line 59 def _api_token response.try(:[],'zapiApiToken') end |
#_cart_id ⇒ Object
55 56 57 |
# File 'lib/zapi_employee.rb', line 55 def _cart_id response.try(:[],'cartId') end |
#_firstname ⇒ Object
67 68 69 |
# File 'lib/zapi_employee.rb', line 67 def _firstname response.try(:[],'firstName') end |
#_fullname ⇒ Object
75 76 77 |
# File 'lib/zapi_employee.rb', line 75 def _fullname [_firstname, _lastname].compact.join(" ") if _firstname || _lastname end |
#_lastname ⇒ Object
71 72 73 |
# File 'lib/zapi_employee.rb', line 71 def _lastname response.try(:[],'lastName') end |
#_login(username:, password:) ⇒ Object
38 39 40 41 |
# File 'lib/zapi_employee.rb', line 38 def _login username:, password: login_xml = generate_xml.agent_login(username: username, password: Digest::MD5.hexdigest(password)) zapi.request(xml: login_xml) end |
#_method_name ⇒ Object
79 80 81 |
# File 'lib/zapi_employee.rb', line 79 def _method_name response.try(:[],'methodName') end |
#_user_id ⇒ Object
43 44 45 |
# File 'lib/zapi_employee.rb', line 43 def _user_id response.try(:[],'zapiUserId').to_i end |
#_username ⇒ Object
63 64 65 |
# File 'lib/zapi_employee.rb', line 63 def _username response.try(:[],'zapiUsername') end |
#is_logged_in? ⇒ Boolean
12 13 14 |
# File 'lib/zapi_employee.rb', line 12 def is_logged_in? response_msg == "Login Successful" && _method_name == 'zapiMobileLogin' end |
#response_msg ⇒ Object
16 17 18 |
# File 'lib/zapi_employee.rb', line 16 def response_msg response.try(:[],'methodErrorMessage') end |
#session(hash: session_hash) ⇒ Object
34 35 36 |
# File 'lib/zapi_employee.rb', line 34 def session hash: session_hash responder.new(hash: hash) end |
#session_hash ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/zapi_employee.rb', line 20 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 |