class ProcessOut::APIRequest

Attributes

api_version[R]
body[R]
created_at[R]
headers[R]
id[R]
idempotency_key[R]
method[R]
project[R]
response_body[R]
response_code[R]
response_headers[R]
response_ms[R]
sandbox[R]
url[R]

Public Class Methods

new(client, data = {}) click to toggle source

Initializes the APIRequest object Params:

client

ProcessOut client instance

data

data that can be used to fill the object

# 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

Public Instance Methods

all(options = {}) click to toggle source

Get all the API requests. Params:

options

Hash of options

# 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
api_version=(val) click to toggle source
# File lib/processout/api_request.rb, line 47
def api_version=(val)
  if val.nil?
    @api_version = val
    return
  end

  if val.instance_of? APIVersion
    @api_version = val
  else
    obj = APIVersion.new(@client)
    obj.fill_with_data(val)
    @api_version = obj
  end
  
end
body=(val) click to toggle source
# File lib/processout/api_request.rb, line 79
def body=(val)
  @body = val
end
created_at=(val) click to toggle source
# File lib/processout/api_request.rb, line 103
def created_at=(val)
  @created_at = val
end
fill_with_data(data) click to toggle source

Fills the object with data coming from the API Params:

data

Hash of data coming from the API

# 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 = {}) click to toggle source

Find an API request by its ID. Params:

api_request_id

ID of the API request

options

Hash of options

# 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
headers=(val) click to toggle source
# File lib/processout/api_request.rb, line 75
def headers=(val)
  @headers = val
end
id=(val) click to toggle source
# File lib/processout/api_request.rb, line 27
def id=(val)
  @id = val
end
idempotency_key=(val) click to toggle source
# File lib/processout/api_request.rb, line 63
def idempotency_key=(val)
  @idempotency_key = val
end
method=(val) click to toggle source
# File lib/processout/api_request.rb, line 71
def method=(val)
  @method = val
end
new(data = {}) click to toggle source

Create a new APIRequest using the current client

# File lib/processout/api_request.rb, line 133
def new(data = {})
  APIRequest.new(@client, data)
end
prefill(data) click to toggle source

Prefills the object with the data passed as parameters Params:

data

Hash of data

# 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
project=(val) click to toggle source
# File lib/processout/api_request.rb, line 31
def project=(val)
  if val.nil?
    @project = val
    return
  end

  if val.instance_of? Project
    @project = val
  else
    obj = Project.new(@client)
    obj.fill_with_data(val)
    @project = obj
  end
  
end
response_body=(val) click to toggle source
# File lib/processout/api_request.rb, line 91
def response_body=(val)
  @response_body = val
end
response_code=(val) click to toggle source
# File lib/processout/api_request.rb, line 83
def response_code=(val)
  @response_code = val
end
response_headers=(val) click to toggle source
# File lib/processout/api_request.rb, line 87
def response_headers=(val)
  @response_headers = val
end
response_ms=(val) click to toggle source
# File lib/processout/api_request.rb, line 95
def response_ms=(val)
  @response_ms = val
end
sandbox=(val) click to toggle source
# File lib/processout/api_request.rb, line 99
def sandbox=(val)
  @sandbox = val
end
to_json(options) click to toggle source

Overrides the JSON marshaller to only send the fields we want

# 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
url=(val) click to toggle source
# File lib/processout/api_request.rb, line 67
def url=(val)
  @url = val
end