Class: RussianPost::Client

Inherits:
Object
  • Object
show all
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.



10
11
12
13
14
15
16
# File 'lib/russianpost/client.rb', line 10

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.



5
6
7
# File 'lib/russianpost/client.rb', line 5

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/russianpost/client.rb', line 5

def namespace
  @namespace
end

#savonObject (readonly)

Returns the value of attribute savon.



5
6
7
# File 'lib/russianpost/client.rb', line 5

def savon
  @savon
end

Instance Method Details

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



18
19
20
21
22
23
24
# File 'lib/russianpost/client.rb', line 18

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