Sha256: c2b59ec2995b18c751970f1c6ce124e3347d88fadeb944f0f5f04ec03af616ee

Contents?: true

Size: 1.18 KB

Versions: 25

Compression:

Stored size: 1.18 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
  
  # 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)
    @status   = hash['response']['status']
    @uid      = hash['response']['uid']
    @message  = hash['response']['message']
    @data     = hash['data']
  rescue
    @status   = 'fail'
  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

25 entries across 25 versions & 1 rubygems

Version Path
postageapp-1.0.24 lib/postageapp/response.rb
postageapp-1.0.23 lib/postageapp/response.rb
postageapp-1.0.22 lib/postageapp/response.rb
postageapp-1.0.21 lib/postageapp/response.rb
postageapp-1.0.20 lib/postageapp/response.rb
postageapp-1.0.19 lib/postageapp/response.rb
postageapp-1.0.18 lib/postageapp/response.rb
postageapp-1.0.17 lib/postageapp/response.rb
postageapp-1.0.16 lib/postageapp/response.rb
postageapp-1.0.15 lib/postageapp/response.rb
postageapp-1.0.14 lib/postageapp/response.rb
postageapp-1.0.13 lib/postageapp/response.rb
postageapp-1.0.12 lib/postageapp/response.rb
postageapp-1.0.11 lib/postageapp/response.rb
postageapp-1.0.10 lib/postageapp/response.rb
postageapp-1.0.9 lib/postageapp/response.rb
postageapp-1.0.8 lib/postageapp/response.rb
postageapp-1.0.7 lib/postageapp/response.rb
postageapp-1.0.6 lib/postageapp/response.rb
postageapp-1.0.5 lib/postageapp/response.rb