Class: PickpointApi::Session
- Inherits:
-
Object
- Object
- PickpointApi::Session
- Defined in:
- lib/pickpoint_api/session.rb
Instance Attribute Summary collapse
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Instance Method Summary collapse
- #create_sending(data) ⇒ Object
-
#initialize(hash = {}) ⇒ Session
constructor
A new instance of Session.
- #login(login, password) ⇒ Object
- #logout ⇒ Object
- #make_label(invoice_id) ⇒ Object
- #make_reestr(invoice_id) ⇒ Object
- #postamat_list ⇒ Object
- #track_sending(invoice_id) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Session
Returns a new instance of Session.
8 9 10 11 |
# File 'lib/pickpoint_api/session.rb', line 8 def initialize(hash = {}) @state = :new @test = hash[:test] == true end |
Instance Attribute Details
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/pickpoint_api/session.rb', line 5 def state @state end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
6 7 8 |
# File 'lib/pickpoint_api/session.rb', line 6 def test @test end |
Instance Method Details
#create_sending(data) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pickpoint_api/session.rb', line 48 def create_sending(data) if @state == :started data = attach_session_id(data, 'Sendings') response = execute_action(:create_sending, data) response = JSON.parse(response) end end |
#login(login, password) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pickpoint_api/session.rb', line 13 def login(login, password) if @state!= :new return nil end data = {'Login' => login, 'Password' => password} response = execute_action(:login, data) response = JSON.parse(response) if response['ErrorMessage'].nil? && !response['SessionId'].nil? @session_id = response['SessionId'] @state = :started else @state = :error raise ::PickpointApi::Exceptions::ApiError, response['ErrorMessage'] end end |
#logout ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pickpoint_api/session.rb', line 31 def logout if !@session_id.nil? && @state == :started data = {'SessionId' => @session_id} response = execute_action :logout, data response = JSON.parse(response) if response['Success'] @state = :closed @session_id = nil return true else return false end else return false end end |
#make_label(invoice_id) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pickpoint_api/session.rb', line 79 def make_label(invoice_id) if @state != :started return nil end if invoice_id.kind_of?(Array) data = invoice_id elsif data = [invoice_id] end data = attach_session_id(data,'Invoices') response = execute_action(:make_label, data) if response.start_with?("Error") raise ::PickpointApi::Exceptions::ApiError, response return nil else return response end end |
#make_reestr(invoice_id) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/pickpoint_api/session.rb', line 101 def make_reestr(invoice_id) if @state != :started return nil end if invoice_id.kind_of?(Array) data = invoice_id elsif data = [invoice_id] end data = attach_session_id(data,'Invoices') response = execute_action(:make_reestr, data) if response.start_with?("Error") raise ::PickpointApi::Exceptions::ApiError, response return nil else return response end end |
#postamat_list ⇒ Object
72 73 74 75 76 77 |
# File 'lib/pickpoint_api/session.rb', line 72 def postamat_list if @state == :started response = execute_action(:postamat_list) response = JSON.parse(response) end end |
#track_sending(invoice_id) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/pickpoint_api/session.rb', line 56 def track_sending(invoice_id) if @state != :started return nil end data = invoice_id data = attach_session_id(data, 'InvoiceNumber') response = execute_action(:track_sending, data) if response.nil? || response.empty? return nil end response = JSON.parse(response) end |