Sha256: 4709b864f12969eab7d3e6b2c2e82bafbedf454a1bbd6e9442f3bc0a0eac4dd6
Contents?: true
Size: 1.65 KB
Versions: 3
Compression:
Stored size: 1.65 KB
Contents
module Firstjob class HttpParser def self.parse_json_to_hash(json, hash) json.each{|object| hash[object["id"]] ? hash[object["id"]].merge!(object) : hash[object["id"]] = object} return hash end def self.parse_response(response) Firstjob.last_response = response Firstjob.last_request = response.request case response.code when 200..201 # "All good!" return response.body when 401 Firstjob.invalidate_access_token! raise "Error 401: Unauthorized. Check login info.\n #{response.body}" when 403 raise "Error 403: Forbidden" when 404 raise "Error 404 not found" when 500...600 raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}" else raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}" end end def self.parse_json_response(response) Firstjob.last_response = response Firstjob.last_request = response.request case response.code when 200..201 # "All good!" return JSON.parse(response.body) when 401 Firstjob.invalidate_access_token! raise "Error 401: Unauthorized. Check login info.\n #{response.body}" when 403 raise "Error 403: Forbidden" when 404 raise "Error 404 not found" when 500...600 raise "ZOMG ERROR #{response.code}: #{response.request.path}, #{response.body}" else raise "Error #{response.code}, unkown response: #{response.request.path}, #{response.body}" end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
firstjob-1.0.4 | lib/firstjob/http_parser.rb |
firstjob-1.0.1 | lib/firstjob/http_parser.rb |
firstjob-1.0.0 | lib/firstjob/http_parser.rb |