class ProcessOut::Request

Public Class Methods

new(client) click to toggle source
# File lib/processout/networking/request.rb, line 7
def initialize(client)
  @client = client
end

Public Instance Methods

delete(path, data, options) click to toggle source

DELETE sends a delete request to the API

# File lib/processout/networking/request.rb, line 87
def delete(path, data, options) 
  uri = URI(@client.host + path)
  uri.query = URI.encode_www_form(self.compute_data(data, options))
  req = Net::HTTP::Delete.new(uri)
  self.apply_headers(req, options)

  Net::HTTP.start(uri.hostname, uri.port,
    :open_timeout => 5,
    :read_timeout => 65,
    :use_ssl => true) do |http|

    http.request(req)
  end
end
get(path, data, options) click to toggle source

GET sends a get request to the API

# File lib/processout/networking/request.rb, line 39
def get(path, data, options) 
  uri = URI(@client.host + path)
  uri.query = URI.encode_www_form(self.compute_data(data, options))
  req = Net::HTTP::Get.new(uri)
  self.apply_headers(req, options)

  Net::HTTP.start(uri.hostname, uri.port,
    :open_timeout => 5,
    :read_timeout => 65,
    :use_ssl => true) do |http|

    http.request(req)
  end
end
post(path, data, options) click to toggle source

POST sends a post request to the API

# File lib/processout/networking/request.rb, line 55
def post(path, data, options) 
  uri = URI(@client.host + path)
  req = Net::HTTP::Post.new(uri)
  req.body = self.compute_data(data, options).to_json
  self.apply_headers(req, options)

  Net::HTTP.start(uri.hostname, uri.port,
    :open_timeout => 5,
    :read_timeout => 65,
    :use_ssl => true) do |http|

    http.request(req)
  end
end
put(path, data, options) click to toggle source

PUT sends a put request to the API

# File lib/processout/networking/request.rb, line 71
def put(path, data, options) 
  uri = URI(@client.host + path)
  req = Net::HTTP::Put.new(uri)
  req.body = self.compute_data(data, options).to_json
  self.apply_headers(req, options)

  Net::HTTP.start(uri.hostname, uri.port,
    :open_timeout => 5,
    :read_timeout => 65,
    :use_ssl => true) do |http|

    http.request(req)
  end
end

Protected Instance Methods

apply_headers(req, options) click to toggle source

ApplyHeaders applies the pre-defined headers to the request

# File lib/processout/networking/request.rb, line 12
def apply_headers(req, options)
  req.basic_auth @client.project_id, @client.project_secret
  req.content_type = "application/json"
  req["API-Version"] = "1.4.0.0"
  req["User-Agent"] = "ProcessOut Ruby-Bindings/2.15.1"

  unless options.nil?
    req["Idempotency-Key"] = options.fetch(:idempotency_key, "")
    req["Disable-Logging"] = options.fetch(:disable_logging, "")
  end
end
compute_data(data, options) click to toggle source

ComputeData computes the data to be sent in the request

# File lib/processout/networking/request.rb, line 26
def compute_data(data, options)
  unless options.nil?
    data["expand"] = options.fetch(:expand, [])
    data["filter"] = options.fetch(:filter, "")
    data["limit"] = options.fetch(:limit, "")
    data["end_before"] = options.fetch(:end_before, "")
    data["start_after"] = options.fetch(:start_after, "")
  end
  data
end