Class: ImlClient::RestApiClient

Inherits:
AbstractApiClient show all
Defined in:
lib/iml_client/rest_api_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(login, password, options = {}) ⇒ RestApiClient

Returns a new instance of RestApiClient.



8
9
10
11
12
13
# File 'lib/iml_client/rest_api_client.rb', line 8

def initialize(, password, options = {})
  @login    = 
  @password = password
  options = Util.symbolize_keys options
  @test_mode = !!options[:test_mode]
end

Instance Method Details

#calculate_price(params) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/iml_client/rest_api_client.rb', line 40

def calculate_price(params)
  result = request url_for(:calculate_price), :post, nil, params
  if result.errors.any?
    result.set_data nil
  elsif !result.data.is_a?(Hash) || result.data['Price'].nil?
    Util.array_wrap(result.data).each do |error_data|
      error = ImlClient::APIError.new error_data['Code'], error_data['Mess']
      result.add_error error
    end
    result.set_data nil
  else
    result.set_data result.data['Price']
  end
  result
end

#create_order(params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/iml_client/rest_api_client.rb', line 23

def create_order(params)
  result = request url_for(:create_order), :post, nil, params
  if result.errors.any?
    result.set_data({})
  elsif result.data['Result'] == 'Error'
    result.data['Errors'].each do |error_data|
      error = ImlClient::APIError.new error_data['Code'], error_data['Message']
      result.add_error error
    end
    result.set_data({})
  else
    normalized_data = normalize_response_data result.data['Order'], response_normalization_rules_for(:create_order)
    result.set_data normalized_data
  end
  result
end

#order_statuses(params = {}) ⇒ Object



19
20
21
# File 'lib/iml_client/rest_api_client.rb', line 19

def order_statuses(params = {})
  request_and_normalize url_for(:order_statuses), :post, nil, params, response_normalization_rules_for(:order_statuses), []
end

#orders(params = {}) ⇒ Object



15
16
17
# File 'lib/iml_client/rest_api_client.rb', line 15

def orders(params = {})
  request_and_normalize url_for(:orders), :post, nil, params, response_normalization_rules_for(:orders), []
end

#test_mode?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/iml_client/rest_api_client.rb', line 56

def test_mode?
  @test_mode
end