Class: ProcessOut::APIRequest
- Inherits:
-
Object
- Object
- ProcessOut::APIRequest
- Defined in:
- lib/processout/api_request.rb
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#body ⇒ Object
Returns the value of attribute body.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#idempotency_key ⇒ Object
Returns the value of attribute idempotency_key.
-
#method ⇒ Object
Returns the value of attribute method.
-
#project ⇒ Object
Returns the value of attribute project.
-
#response_body ⇒ Object
Returns the value of attribute response_body.
-
#response_code ⇒ Object
Returns the value of attribute response_code.
-
#response_headers ⇒ Object
Returns the value of attribute response_headers.
-
#response_ms ⇒ Object
Returns the value of attribute response_ms.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Get all the API requests.
-
#fill_with_data(data) ⇒ Object
- Fills the object with data coming from the API Params:
data -
Hashof data coming from the API.
- Fills the object with data coming from the API Params:
-
#find(api_request_id, options = {}) ⇒ Object
Find an API request by its ID.
-
#initialize(client, data = {}) ⇒ APIRequest
constructor
- Initializes the APIRequest object Params:
client ProcessOutclient instancedata-
data that can be used to fill the object.
- Initializes the APIRequest object Params:
-
#new(data = {}) ⇒ Object
Create a new APIRequest using the current client.
-
#prefill(data) ⇒ Object
- Prefills the object with the data passed as parameters Params:
data -
Hashof data.
- Prefills the object with the data passed as parameters Params:
Constructor Details
#initialize(client, data = {}) ⇒ APIRequest
Initializes the APIRequest object Params:
client-
ProcessOutclient instance data-
data that can be used to fill the object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/processout/api_request.rb', line 111 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_version ⇒ Object
Returns the value of attribute api_version.
12 13 14 |
# File 'lib/processout/api_request.rb', line 12 def api_version @api_version end |
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/processout/api_request.rb', line 17 def body @body end |
#created_at ⇒ Object
Returns the value of attribute created_at.
23 24 25 |
# File 'lib/processout/api_request.rb', line 23 def created_at @created_at end |
#headers ⇒ Object
Returns the value of attribute headers.
16 17 18 |
# File 'lib/processout/api_request.rb', line 16 def headers @headers end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/processout/api_request.rb', line 10 def id @id end |
#idempotency_key ⇒ Object
Returns the value of attribute idempotency_key.
13 14 15 |
# File 'lib/processout/api_request.rb', line 13 def idempotency_key @idempotency_key end |
#method ⇒ Object
Returns the value of attribute method.
15 16 17 |
# File 'lib/processout/api_request.rb', line 15 def method @method end |
#project ⇒ Object
Returns the value of attribute project.
11 12 13 |
# File 'lib/processout/api_request.rb', line 11 def project @project end |
#response_body ⇒ Object
Returns the value of attribute response_body.
20 21 22 |
# File 'lib/processout/api_request.rb', line 20 def response_body @response_body end |
#response_code ⇒ Object
Returns the value of attribute response_code.
18 19 20 |
# File 'lib/processout/api_request.rb', line 18 def response_code @response_code end |
#response_headers ⇒ Object
Returns the value of attribute response_headers.
19 20 21 |
# File 'lib/processout/api_request.rb', line 19 def response_headers @response_headers end |
#response_ms ⇒ Object
Returns the value of attribute response_ms.
21 22 23 |
# File 'lib/processout/api_request.rb', line 21 def response_ms @response_ms end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
22 23 24 |
# File 'lib/processout/api_request.rb', line 22 def sandbox @sandbox end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/processout/api_request.rb', line 14 def url @url end |
Instance Method Details
#all(options = {}) ⇒ Object
Get all the API requests. Params:
options-
Hashof options
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 |
# File 'lib/processout/api_request.rb', line 217 def all( = {}) self.prefill() request = Request.new(@client) path = "/api-requests" data = { } response = Response.new(request.get(path, data, )) 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-
Hashof data coming from the API
139 140 141 142 143 144 145 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 |
# File 'lib/processout/api_request.rb', line 139 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-
Hashof options
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/processout/api_request.rb', line 248 def find(api_request_id, = {}) self.prefill() request = Request.new(@client) path = "/api-requests/{request_id}" data = { } response = Response.new(request.get(path, data, )) 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
132 133 134 |
# File 'lib/processout/api_request.rb', line 132 def new(data = {}) APIRequest.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data-
Hashof data
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/processout/api_request.rb', line 192 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 |