Class: ProductHunt::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty, API
Defined in:
lib/product_hunt/client.rb

Constant Summary

Constants included from API::Users

API::Users::PATH

Constants included from API::Posts

API::Posts::PATH

Instance Method Summary collapse

Methods included from API::Users

#user

Methods included from API::Posts

#comments_for_post, #post, #posts, #votes_for_post

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



12
13
14
# File 'lib/product_hunt/client.rb', line 12

def initialize(token)
  @config = { headers: { "Authorization" => "Bearer #{token}" } }
end

Instance Method Details

#configObject



16
17
18
# File 'lib/product_hunt/client.rb', line 16

def config
  @config
end

#fetch(path, params) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/product_hunt/client.rb', line 20

def fetch(path, params)
  queryopts = if params.is_a?(Enumerable) && params.size > 0
    "?" + URI.encode_www_form(params)
  end

  self.class.get(path + (queryopts || ""), @config)
end