Class: Raas::OrdersController

Inherits:
BaseController show all
Defined in:
lib/raas/controllers/orders_controller.rb

Overview

OrdersController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from Raas::BaseController

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



10
11
12
# File 'lib/raas/controllers/orders_controller.rb', line 10

def instance
  @instance
end

Instance Method Details

#create_order(body) ⇒ Object

Places an order CreateOrderRequest object

Parameters:

Returns:

  • OrderModel response from the API call



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/raas/controllers/orders_controller.rb', line 208

def create_order(body)
  begin
    @logger.info("create_order called.")
    # Validate required parameters.
    @logger.info("Validating required parameters for create_order.")
    validate_parameters(
      'body' => body
    )
    # Prepare query url.
    @logger.info("Preparing query URL for create_order.")
    _query_builder = Configuration.get_base_uri
    _query_builder << '/orders'
    _query_url = APIHelper.clean_url _query_builder
  
    # Prepare headers.
    @logger.info("Preparing headers for create_order.")
    _headers = {
      'accept' => 'application/json',
      'content-type' => 'application/json; charset=utf-8'
    }
  
    # Prepare and execute HttpRequest.
    @logger.info('Preparing and executing HttpRequest for create_order.')
    _request = @http_client.post(
      _query_url,
      headers: _headers,
      parameters: body.to_json
    )
    BasicAuth.apply(_request)
    _context = execute_request(_request, name: 'create_order')
  
    # Validate response against endpoint and global error codes.
    @logger.info("Validating response for create_order.")
    unless _context.response.status_code.between?(200, 208)
      raise RaasGenericException.new(
        'API Error',
        _context
      )
    end
    validate_response(_context)
  
    # Return appropriate response type.
    @logger.info("Returning response for create_order.")
    decoded = APIHelper.json_deserialize(_context.response.raw_body)
    OrderModel.from_hash(decoded)

  rescue Exception => e
    @logger.error(e)
    raise e
  end
end

#create_resend_order(reference_order_id) ⇒ Object

Resends an order reference order id

Parameters:

  • reference_order_id (String)

    Required parameter: The order’s

Returns:

  • ResendOrderResponseModel response from the API call



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/raas/controllers/orders_controller.rb', line 79

def create_resend_order(reference_order_id)
  begin
    @logger.info("create_resend_order called.")
    # Validate required parameters.
    @logger.info("Validating required parameters for create_resend_order.")
    validate_parameters(
      'reference_order_id' => reference_order_id
    )
    # Prepare query url.
    @logger.info("Preparing query URL for create_resend_order.")
    _query_builder = Configuration.get_base_uri
    _query_builder << '/orders/{referenceOrderID}/resends'
    _query_builder = APIHelper.append_url_with_template_parameters(
      _query_builder,
      'referenceOrderID' => reference_order_id
    )
    _query_url = APIHelper.clean_url _query_builder
  
    # Prepare headers.
    @logger.info("Preparing headers for create_resend_order.")
    _headers = {
      'accept' => 'application/json'
    }
  
    # Prepare and execute HttpRequest.
    @logger.info('Preparing and executing HttpRequest for create_resend_order.')
    _request = @http_client.post(
      _query_url,
      headers: _headers
    )
    BasicAuth.apply(_request)
    _context = execute_request(_request, name: 'create_resend_order')
  
    # Validate response against endpoint and global error codes.
    @logger.info("Validating response for create_resend_order.")
    unless _context.response.status_code.between?(200, 208)
      raise RaasGenericException.new(
        'API Error',
        _context
      )
    end
    validate_response(_context)
  
    # Return appropriate response type.
    @logger.info("Returning response for create_resend_order.")
    decoded = APIHelper.json_deserialize(_context.response.raw_body)
    ResendOrderResponseModel.from_hash(decoded)

  rescue Exception => e
    @logger.error(e)
    raise e
  end
end

#get_order(reference_order_id) ⇒ Object

Retrieves a single order ID

Parameters:

  • reference_order_id (String)

    Required parameter: Reference Order

Returns:

  • OrderModel response from the API call



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/raas/controllers/orders_controller.rb', line 21

def get_order(reference_order_id)
  begin
    @logger.info("get_order called.")
    # Validate required parameters.
    @logger.info("Validating required parameters for get_order.")
    validate_parameters(
      'reference_order_id' => reference_order_id
    )
    # Prepare query url.
    @logger.info("Preparing query URL for get_order.")
    _query_builder = Configuration.get_base_uri
    _query_builder << '/orders/{referenceOrderID}'
    _query_builder = APIHelper.append_url_with_template_parameters(
      _query_builder,
      'referenceOrderID' => reference_order_id
    )
    _query_url = APIHelper.clean_url _query_builder
  
    # Prepare headers.
    @logger.info("Preparing headers for get_order.")
    _headers = {
      'accept' => 'application/json'
    }
  
    # Prepare and execute HttpRequest.
    @logger.info('Preparing and executing HttpRequest for get_order.')
    _request = @http_client.get(
      _query_url,
      headers: _headers
    )
    BasicAuth.apply(_request)
    _context = execute_request(_request, name: 'get_order')
  
    # Validate response against endpoint and global error codes.
    @logger.info("Validating response for get_order.")
    unless _context.response.status_code.between?(200, 208)
      raise RaasGenericException.new(
        'API Error',
        _context
      )
    end
    validate_response(_context)
  
    # Return appropriate response type.
    @logger.info("Returning response for get_order.")
    decoded = APIHelper.json_deserialize(_context.response.raw_body)
    OrderModel.from_hash(decoded)

  rescue Exception => e
    @logger.error(e)
    raise e
  end
end

#get_orders(options = {}) ⇒ Object

Retrieves a list of orders under a platform identifier identifier id elements per page

Parameters:

  • account_identifier (String)

    Optional parameter: Account

  • customer_identifier (String)

    Optional parameter: Customer

  • external_ref_id (String)

    Optional parameter: External reference

  • start_date (DateTime)

    Optional parameter: The start date

  • end_date (DateTime)

    Optional parameter: The end date

  • elements_per_block (Integer)

    Optional parameter: The number of

  • page (Integer)

    Optional parameter: The page number to return

Returns:

  • GetOrdersResponseModel response from the API call



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/raas/controllers/orders_controller.rb', line 146

def get_orders(options = {})
  begin
    @logger.info("get_orders called.")
    # Prepare query url.
    @logger.info("Preparing query URL for get_orders.")
    _query_builder = Configuration.get_base_uri
    _query_builder << '/orders'
    _query_builder = APIHelper.append_url_with_query_parameters(
      _query_builder,
      {
        'accountIdentifier' => options['account_identifier'],
        'customerIdentifier' => options['customer_identifier'],
        'externalRefID' => options['external_ref_id'],
        'startDate' => options['start_date'],
        'endDate' => options['end_date'],
        'elementsPerBlock' => options['elements_per_block'],
        'page' => options['page']
      },
      array_serialization: Configuration.array_serialization
    )
    _query_url = APIHelper.clean_url _query_builder
  
    # Prepare headers.
    @logger.info("Preparing headers for get_orders.")
    _headers = {
      'accept' => 'application/json'
    }
  
    # Prepare and execute HttpRequest.
    @logger.info('Preparing and executing HttpRequest for get_orders.')
    _request = @http_client.get(
      _query_url,
      headers: _headers
    )
    BasicAuth.apply(_request)
    _context = execute_request(_request, name: 'get_orders')
  
    # Validate response against endpoint and global error codes.
    @logger.info("Validating response for get_orders.")
    unless _context.response.status_code.between?(200, 208)
      raise RaasGenericException.new(
        'API Error',
        _context
      )
    end
    validate_response(_context)
  
    # Return appropriate response type.
    @logger.info("Returning response for get_orders.")
    decoded = APIHelper.json_deserialize(_context.response.raw_body)
    GetOrdersResponseModel.from_hash(decoded)

  rescue Exception => e
    @logger.error(e)
    raise e
  end
end

#instanceObject



13
14
15
# File 'lib/raas/controllers/orders_controller.rb', line 13

def instance
  self.class.instance
end