Sha256: ea53d20eeb7f9122d555aaea69e0df3507bce874e310c886732056259712dc4c

Contents?: true

Size: 726 Bytes

Versions: 8

Compression:

Stored size: 726 Bytes

Contents

require 'json'
require 'hashie'

module Echonest
  class Response
    attr_reader :json

    def initialize(body)
      @json = Hashie::Mash.new(JSON.parse(body))
    end

    def status
      @status ||= Status.new(body)
    end

    def success?
      status.code == Status::SUCCESS
    end

    def body
      json.response
    end

    class Status
      UNKNOWN_ERROR = -1
      SUCCESS = 0
      INVALID_API_KEY = 1
      PERMISSION_DENIED = 2
      RATE_LIMIT_EXCEEDED = 3
      MISSING_PARAMETER = 4
      INVALID_PARAMETER = 5

      attr_reader :code, :message

      def initialize(response_body)
        @code = response_body.status.code
        @message = response_body.status.message
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ruby-echonest-0.5.0 lib/echonest/response.rb
ruby-echonest-0.4.0 lib/echonest/response.rb
bassnode-ruby-echonest-0.1.3 lib/echonest/response.rb
ruby-echonest-0.3.0 lib/echonest/response.rb
ruby-echonest-0.2.0 lib/echonest/response.rb
ruby-echonest-0.1.2 lib/echonest/response.rb
bassnode-ruby-echonest-0.1.2 lib/echonest/response.rb
ruby-echonest-0.1.1 lib/echonest/response.rb