Module: Heroku::Samorau::HTTP
- Included in:
- DeprovisionCheck, SsoCheck
- Defined in:
- lib/heroku/samorau.rb
Instance Method Summary collapse
- #delete(credentials, path, payload = nil) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #post(credentials, path, payload = nil) ⇒ Object
- #request(meth, credentials, path, payload = nil) ⇒ Object
Instance Method Details
#delete(credentials, path, payload = nil) ⇒ Object
285 286 287 |
# File 'lib/heroku/samorau.rb', line 285 def delete(credentials, path, payload=nil) request(:delete, credentials, path, payload) end |
#get(path, params = {}) ⇒ Object
276 277 278 279 |
# File 'lib/heroku/samorau.rb', line 276 def get(path, params={}) path = "#{path}?" + params.map { |k, v| "#{k}=#{v}" }.join("&") unless params.empty? request(:get, [], path) end |
#post(credentials, path, payload = nil) ⇒ Object
281 282 283 |
# File 'lib/heroku/samorau.rb', line 281 def post(credentials, path, payload=nil) request(:post, credentials, path, payload) end |
#request(meth, credentials, path, payload = nil) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/heroku/samorau.rb', line 289 def request(meth, credentials, path, payload=nil) code = nil body = nil begin args = [ (Yajl::Encoder.encode(payload) if payload), { :accept => "application/json", :content_type => "application/json" } ].compact user, pass = credentials body = RestClient::Resource.new(url, user, pass)[path].send( meth, *args ) code = 200 rescue RestClient::ExceptionWithResponse => boom code = boom.http_code body = boom.http_body rescue Errno::ECONNREFUSED code = -1 body = nil end [code, body] end |