Class: Getui::Request
- Inherits:
-
Net::HTTPRequest
- Object
- Net::HTTPRequest
- Getui::Request
- Defined in:
- lib/getui/request.rb
Direct Known Subclasses
Constant Summary collapse
- REQUEST_HAS_BODY =
true- RESPONSE_HAS_BODY =
true- MAX_TRY =
3
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(path) ⇒ Request
Returns a new instance of Request.
44 45 46 |
# File 'lib/getui/request.rb', line 44 def initialize(path) super(path, {'Content-Type' => 'application/json', 'authtoken' => Getui::Auth.auth_token}) end |
Class Method Details
.get(url, params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/getui/request.rb', line 28 def self.get(url, params = {}) MAX_TRY.times do |current_try| begin uri = URI(url) req = Getui::GetRequest.new(uri) http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = (uri.scheme == "https") return http.request(req) rescue Errno::ETIMEDOUT, Net::ReadTimeout, Timeout::Error, EOFError => e if current_try == MAX_TRY - 1 raise e end end end end |
.post(url, params = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/getui/request.rb', line 11 def self.post(url, params = {}) MAX_TRY.times do |current_try| begin uri = URI(url) req = Getui::PostRequest.new(uri) req.body = JSON.dump(params) http = Net::HTTP.new(uri.hostname, uri.port) http.use_ssl = (uri.scheme == "https") return http.request(req) rescue Errno::ETIMEDOUT, Net::ReadTimeout, Timeout::Error, EOFError => e if current_try == MAX_TRY - 1 raise e end end end end |