Class: ProcessOut::Request

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Request

Returns a new instance of Request.



7
8
9
# File 'lib/processout/networking/request.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#delete(path, data, options) ⇒ Object

DELETE sends a delete request to the API



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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) ⇒ Object

GET sends a get request to the API



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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) ⇒ Object

POST sends a post request to the API



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object

PUT sends a put request to the API



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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