Class: ProcessOut::APIRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/api_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data = {}) ⇒ APIRequest

Initializes the APIRequest object Params:

client

ProcessOut client instance

data

data that can be used to fill the object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/processout/api_request.rb', line 112

def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.project = data.fetch(:project, nil)
  self.api_version = data.fetch(:api_version, nil)
  self.idempotency_key = data.fetch(:idempotency_key, nil)
  self.url = data.fetch(:url, nil)
  self.method = data.fetch(:method, nil)
  self.headers = data.fetch(:headers, nil)
  self.body = data.fetch(:body, nil)
  self.response_code = data.fetch(:response_code, nil)
  self.response_headers = data.fetch(:response_headers, nil)
  self.response_body = data.fetch(:response_body, nil)
  self.response_ms = data.fetch(:response_ms, nil)
  self.sandbox = data.fetch(:sandbox, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Instance Attribute Details

#api_versionObject

Returns the value of attribute api_version.



13
14
15
# File 'lib/processout/api_request.rb', line 13

def api_version
  @api_version
end

#bodyObject

Returns the value of attribute body.



18
19
20
# File 'lib/processout/api_request.rb', line 18

def body
  @body
end

#created_atObject

Returns the value of attribute created_at.



24
25
26
# File 'lib/processout/api_request.rb', line 24

def created_at
  @created_at
end

#headersObject

Returns the value of attribute headers.



17
18
19
# File 'lib/processout/api_request.rb', line 17

def headers
  @headers
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/processout/api_request.rb', line 11

def id
  @id
end

#idempotency_keyObject

Returns the value of attribute idempotency_key.



14
15
16
# File 'lib/processout/api_request.rb', line 14

def idempotency_key
  @idempotency_key
end

#methodObject

Returns the value of attribute method.



16
17
18
# File 'lib/processout/api_request.rb', line 16

def method
  @method
end

#projectObject

Returns the value of attribute project.



12
13
14
# File 'lib/processout/api_request.rb', line 12

def project
  @project
end

#response_bodyObject

Returns the value of attribute response_body.



21
22
23
# File 'lib/processout/api_request.rb', line 21

def response_body
  @response_body
end

#response_codeObject

Returns the value of attribute response_code.



19
20
21
# File 'lib/processout/api_request.rb', line 19

def response_code
  @response_code
end

#response_headersObject

Returns the value of attribute response_headers.



20
21
22
# File 'lib/processout/api_request.rb', line 20

def response_headers
  @response_headers
end

#response_msObject

Returns the value of attribute response_ms.



22
23
24
# File 'lib/processout/api_request.rb', line 22

def response_ms
  @response_ms
end

#sandboxObject

Returns the value of attribute sandbox.



23
24
25
# File 'lib/processout/api_request.rb', line 23

def sandbox
  @sandbox
end

#urlObject

Returns the value of attribute url.



15
16
17
# File 'lib/processout/api_request.rb', line 15

def url
  @url
end

Instance Method Details

#all(options = {}) ⇒ Object

Get all the API requests. Params:

options

Hash of options



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/processout/api_request.rb', line 238

def all(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/api-requests"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['api_requests']
    tmp = APIRequest.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end

#fill_with_data(data) ⇒ Object

Fills the object with data coming from the API Params:

data

Hash of data coming from the API



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
203
204
205
206
207
208
# File 'lib/processout/api_request.rb', line 160

def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "project"
    self.project = data["project"]
  end
  if data.include? "api_version"
    self.api_version = data["api_version"]
  end
  if data.include? "idempotency_key"
    self.idempotency_key = data["idempotency_key"]
  end
  if data.include? "url"
    self.url = data["url"]
  end
  if data.include? "method"
    self.method = data["method"]
  end
  if data.include? "headers"
    self.headers = data["headers"]
  end
  if data.include? "body"
    self.body = data["body"]
  end
  if data.include? "response_code"
    self.response_code = data["response_code"]
  end
  if data.include? "response_headers"
    self.response_headers = data["response_headers"]
  end
  if data.include? "response_body"
    self.response_body = data["response_body"]
  end
  if data.include? "response_ms"
    self.response_ms = data["response_ms"]
  end
  if data.include? "sandbox"
    self.sandbox = data["sandbox"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end

#find(api_request_id, options = {}) ⇒ Object

Find an API request by its ID. Params:

api_request_id

ID of the API request

options

Hash of options



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/processout/api_request.rb', line 269

def find(api_request_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/api-requests/{request_id}"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["api_request"]
  
  
  obj = APIRequest.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end

#new(data = {}) ⇒ Object

Create a new APIRequest using the current client



133
134
135
# File 'lib/processout/api_request.rb', line 133

def new(data = {})
  APIRequest.new(@client, data)
end

#prefill(data) ⇒ Object

Prefills the object with the data passed as parameters Params:

data

Hash of data



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/processout/api_request.rb', line 213

def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.project = data.fetch(:project, self.project)
  self.api_version = data.fetch(:api_version, self.api_version)
  self.idempotency_key = data.fetch(:idempotency_key, self.idempotency_key)
  self.url = data.fetch(:url, self.url)
  self.method = data.fetch(:method, self.method)
  self.headers = data.fetch(:headers, self.headers)
  self.body = data.fetch(:body, self.body)
  self.response_code = data.fetch(:response_code, self.response_code)
  self.response_headers = data.fetch(:response_headers, self.response_headers)
  self.response_body = data.fetch(:response_body, self.response_body)
  self.response_ms = data.fetch(:response_ms, self.response_ms)
  self.sandbox = data.fetch(:sandbox, self.sandbox)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end

#to_json(options) ⇒ Object

Overrides the JSON marshaller to only send the fields we want



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/processout/api_request.rb', line 138

def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "api_version": self.api_version,
      "idempotency_key": self.idempotency_key,
      "url": self.url,
      "method": self.method,
      "headers": self.headers,
      "body": self.body,
      "response_code": self.response_code,
      "response_headers": self.response_headers,
      "response_body": self.response_body,
      "response_ms": self.response_ms,
      "sandbox": self.sandbox,
      "created_at": self.created_at,
  }.to_json
end