Sha256: 3566acd760f35aec7f3302fdaae6c6af48f382852190d260db659e5dd7d10c40

Contents?: true

Size: 1012 Bytes

Versions: 4

Compression:

Stored size: 1012 Bytes

Contents

module YouGotListed
  class Response

    attr_accessor :ygl_response

    def initialize(response, raise_error = true)
      if !response.respond_to?(:each_pair)
        self.ygl_response = nil
        raise Error.new('empty_response', 'Empty Response') if raise_error
      else
        rash = Hashie::Rash.new(response)
        self.ygl_response = rash.ygl_response
        if !success? && raise_error
          if self.ygl_response.respond_to?(:response_code)
            raise Error.new(self.ygl_response.response_code, self.ygl_response.error)
          else
            raise Error.new('empty_response', 'Empty Response')
          end
        end
      end
    end

    def success?
      self.ygl_response && self.ygl_response.respond_to?(:response_code) && self.ygl_response.response_code.to_i < 300
    end

    def method_missing(method_name, *args)
      if self.ygl_response.respond_to?(method_name)
        self.ygl_response.send(method_name)
      else
        super
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
you_got_listed-0.4.0 lib/you_got_listed/response.rb
you_got_listed-0.3.6 lib/you_got_listed/response.rb
you_got_listed-0.3.5 lib/you_got_listed/response.rb
you_got_listed-0.3.4 lib/you_got_listed/response.rb