Module: VC::HttpHelpers
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/helpers/http_helpers.rb', line 5 def url @url end |
Instance Method Details
#dec_json(json) ⇒ Object
18 19 20 |
# File 'lib/helpers/http_helpers.rb', line 18 def dec_json(json) Yajl::Parser.parse(json) end |
#enc_json(hash) ⇒ Object
14 15 16 |
# File 'lib/helpers/http_helpers.rb', line 14 def enc_json(hash) Yajl::Encoder.encode(hash) end |
#handle_req(&blk) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/helpers/http_helpers.rb', line 22 def handle_req(&blk) begin resp = yield dec_json(resp.body) rescue RestClient::Exception => e body = dec_json(e.http_body) case e.http_code when 404 when 401 raise(AuthorizationError, "Response: #{body.inspect}") when 403 when 409 when 500 raise(UnexpectedError, "Response: #{body.inspect}") when 503 raise(ServiceDownError, "#{VC.url} is down for maintenance.") else raise(UnexpectedError, "Response: #{body.inspect}") end end end |
#headers ⇒ Object
10 11 12 |
# File 'lib/helpers/http_helpers.rb', line 10 def headers {:content_type => :json, :accept => :json} end |