Class: RussianPost::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/russianpost/client.rb

Constant Summary collapse

ENDPOINT =
'http://voh.russianpost.ru:8080/niips-operationhistory-web/OperationHistory'
NAMESPACE =
'http://russianpost.org/operationhistory/data'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
# File 'lib/russianpost/client.rb', line 13

def initialize(opts = {})
  @savon = Savon.client(
    endpoint:     ENDPOINT,
    namespace:    NAMESPACE,
    open_timeout: opts[:timeout] || 10, # in seconds
    log:          false)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



8
9
10
# File 'lib/russianpost/client.rb', line 8

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/russianpost/client.rb', line 8

def namespace
  @namespace
end

#savonObject (readonly)

Returns the value of attribute savon.



8
9
10
# File 'lib/russianpost/client.rb', line 8

def savon
  @savon
end

Instance Method Details

#call(opts = {barcode: nil}) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/russianpost/client.rb', line 21

def call(opts = {barcode: nil})
  message = { 'wsdl:Barcode' => opts[:barcode], 'wsdl:MessageType' => '0' }
  response = savon.call('OperationHistoryRequest', message: message)
  result = response.to_hash[:operation_history_data][:history_record]

  result.kind_of?(Array) ? result : [result].compact
end