Class: Beslist::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/beslist/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/beslist/client.rb', line 8

def initialize(options = {})
  @connection = Beslist::API::Connection.new( :client_id => options[:client_id],
                                              :shop_id   => options[:shop_id],
                                              :personal_key => options[:personal_key])
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/beslist/client.rb', line 6

def connection
  @connection
end

Instance Method Details

#orders(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/beslist/client.rb', line 14

def orders(options)
  date_from, date_to = options.delete(:date_from), options.delete(:date_to)
  response = @connection.request do
    @connection.interface.get do |req|
      req.url Beslist::API::Config.prefix + '/shoppingcart/shop_orders/'
      req.params = {
        checksum: @connection.checksum(date_from, date_to),
        client_id: @connection.options[:client_id],
        shop_id: @connection.options[:shop_id]
      }

      req.params.merge!(date_from: date_from) if date_from
      req.params.merge!(date_to: date_to) if date_to
      req.params.merge!(output_type: 'test', test_orders: '250') if Beslist::API::Config.mode == 'sandbox'
    end
  end

  if response['shoppingCart']['summary'].keys.include?('errorMessage')
    fail(Beslist::API::Error, response['shoppingCart']['summary']['errorMessage'])
  end

  response
end