Class: Uber::Client
- Inherits:
-
Object
- Object
- Uber::Client
- Defined in:
- lib/simple_worker/uber_client.rb
Instance Method Summary collapse
- #get(url, req_hash = {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #post(url, req_hash = {}) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
65 66 67 |
# File 'lib/simple_worker/uber_client.rb', line 65 def initialize end |
Instance Method Details
#get(url, req_hash = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/simple_worker/uber_client.rb', line 69 def get(url, req_hash={}) if Uber.gem == :typhoeus req_hash[:connect_timeout] = 5000 req_hash[:timeout] ||= 10000 # puts "REQ_HASH=" + req_hash.inspect response = Typhoeus::Request.get(url, req_hash) #p response if response.timed_out? raise TyphoeusTimeoutError.new(response) end else begin headers = req_hash[:headers] || {} r2 = RestClient.get(url, req_hash.merge(headers)) response = RestClientResponseWrapper.new(r2) # todo: make generic exception rescue RestClient::Exception => ex raise RestClientExceptionWrapper.new(ex) end end response end |
#post(url, req_hash = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/simple_worker/uber_client.rb', line 92 def post(url, req_hash={}) if Uber.gem == :typhoeus # todo: should change this timeout to longer if it's for posting file req_hash[:connect_timeout] = 5000 req_hash[:timeout] ||= 10000 # puts "REQ_HASH=" + req_hash.inspect response = Typhoeus::Request.post(url, req_hash) #p response if response.timed_out? raise TyphoeusTimeoutError.new(response) end else begin headers = req_hash[:headers] || {} r2 = RestClient.post(url, req_hash[:body], headers) response = RestClientResponseWrapper.new(r2) # todo: make generic exception rescue RestClient::Exception => ex raise RestClientExceptionWrapper(ex) end end response end |