Sha256: 41175287dd71a8d200314652c696ae9949a24001df30c81ecc79744915c771ea

Contents?: true

Size: 710 Bytes

Versions: 3

Compression:

Stored size: 710 Bytes

Contents

module Rubyflare
  class Response
    attr_reader :body

    def initialize(method_name, endpoint, response)
      @body = JSON.parse(response, symbolize_names: true)

      unless successful?
        message = "Unable to #{method_name.to_s.upcase} to endpoint: " \
                  "#{endpoint}. Inspect Rubyflare::ConnectionError#response "\
                  "for further details"
        raise Rubyflare::ConnectionError.new(message, self)
      end
    end

    def result
      body[:result].first
    end

    def results
      body[:result]
    end

    def successful?
      body[:success]
    end

    def errors
      body[:errors]
    end

    def messages
      body[:messages]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubyflare-0.2.1 lib/rubyflare/response.rb
rubyflare-0.2.0 lib/rubyflare/response.rb
rubyflare-0.1.0 lib/rubyflare/response.rb