Sha256: 6fccf478d9b869ad650a849180a8d18a49845139ee46939e6ee9f38ae3db4ff6

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

require 'typetalk/connection'

module Typetalk

  class Api
    include Connection

    Dir[File.join(__dir__, 'api/*.rb')].each{|f| require f}
    include Auth
    include User
    include Topic
    include Message
    include Mention
    include Notification


    def access_token
      @access_token ||= get_access_token
      @access_token['access_token']
    end


    protected
    def parse_response(response)

      # TODO remove debug print
      #require 'awesome_print'
      #ap response

      case response.status
      when 400, 401
        raise InvalidRequest, response_values(response)
      when 404
        raise NotFound, response_values(response)
      when 413
        raise InvalidFileSize, response_values(response)
      end

      body = JSON.parse(response.body) rescue response.body
      body.is_a?(Hash) ? Hashie::Mash.new(body) : body
    end

    def response_values(response)
      {status: response.status, headers: response.headers, body: response.body}
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
typetalk-0.0.1 lib/typetalk/api.rb