class Talkgh::Namespace

Constants

Delete
Get
Post
Put

Public Class Methods

host() click to toggle source
# File lib/talkgh/namespace.rb, line 13
def self.host
    @host ||= 'api.talkgh.com/api/'
end
host=(host) click to toggle source
# File lib/talkgh/namespace.rb, line 17
def self.host=(host)
    @host = host
end
new(client) click to toggle source
# File lib/talkgh/namespace.rb, line 6
def initialize(client)
    @client = client
    @host = self.class.host
    @logger = client.logger
    @api_token = client.api_token
end

Private Instance Methods

parse(response) click to toggle source
# File lib/talkgh/namespace.rb, line 54
def parse(response)
    case response
    when Net::HTTPNoContent
      :no_content
    when Net::HTTPSuccess
      if response['Content-Type'].split(';').first == 'application/json'
        ::JSON.parse(response.body, object_class: Talkgh::Entity)
      else
        response
      end
    else
      raise Error.parse(response)
    end
end
request(params: nil, type: Get) click to toggle source
# File lib/talkgh/namespace.rb, line 29
def request(params: nil, type: Get)
    uri = URI('https://' + @host + @api_token)

    params ||= {}

    unless type::REQUEST_HAS_BODY || params.empty?
        uri.query = Params.encode(params)
    end
      
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true

    message = type.new(uri)

    @logger.log_request_info(message)
      
    response = http.request(message)

    @logger.log_response_info(response, @host)

    @logger.debug(response.body) if response.body
      
    parse(response)
end