Sha256: d3f0630a769638bb6d2131b8e3a21968d479343c156c893f346a72f9367e56eb

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

require 'json'
require 'duedil/struct'

module Duedil
  class Response
    def initialize(http_response)
      @http_response = http_response
    end

    def respond_to_missing?(name, include_private = false)
      @http_response.respond_to?(name)
    end

    def method_missing(name, *args, &block)
      @http_response.send(name, *args, &block)
    end

    def ok?
      code.to_i == 200
    end

    def hash
      object.hash
    end

    def list
      hash['data'].map(&:hash) if hash['data'].present?
    end

    def json?
      self['Content-Type'].split(';').first == 'application/json'
    end

    def object
      @object ||= JSON.parse(body, :object_class => Struct).response
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duedil-client-0.0.1 lib/duedil/response.rb