Sha256: 52cc186c205e75ce31c0f5a5736308d3fd16af68b2506406d5e8cc44c407e87c
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
class PostageApp::Response # The UID should match the Request's UID. If Request didn't provide with one # PostageApp service should generate it for the Response attr_reader :uid # The status of the response in string format (like: ok, bad_request) # Will be set to +fail+ if Request times out attr_reader :status # The message of the response. Could be used as an error explanation. attr_reader :message # The data payload of the response. This is usually the return value of the # request we're looking for attr_reader :data attr_reader :exception # Takes in Net::HTTPResponse object as the attribute. # If something goes wrong Response will be thought of as failed def initialize(http_response) hash = JSON::parse(http_response.body) _response = hash['response'] @status = _response['status'] @uid = _response['uid'] @message = _response['message'] @data = hash['data'] rescue => e @status = 'fail' @exception = '[%s] %s' % [ e.class, e ] end # Little helper that checks for the Response status # => @response.ok? # >> true # => @response.fail? # >> false def method_missing(method) /.*?\?$/.match(method.to_s) ? "#{self.status}?" == method.to_s : super(method) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
postageapp-1.2.6 | lib/postageapp/response.rb |
postageapp-1.2.5 | lib/postageapp/response.rb |