Class: ForemLite::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/forem_lite/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Create a new client object with your Forem API key.

Parameters:

  • api_key (String) (defaults to: nil)

    <Forem/Dev.to API Key>



11
12
13
# File 'lib/forem_lite/client.rb', line 11

def initialize(api_key = nil)
  self.class.default_options[:headers] = {"api-key" => api_key} if api_key
end

Instance Method Details

#article(id) ⇒ Object

Retrieve a single published article given its id.

Parameters:

  • id (Integer, String)

    <a string or integer representing the article id>

Returns:

  • (Object)

    a FormCli::Article object



31
32
33
# File 'lib/forem_lite/client.rb', line 31

def article(id)
  ForemLite::Article.new(self.class.get("/articles/#{id}"))
end

#articlesArray<Object>

Retrieve a list of articles.

Returns:

  • (Array<Object>)

    collection of ForemLite::Article objects



20
21
22
# File 'lib/forem_lite/client.rb', line 20

def articles
  self.class.get("/articles").tap { |z| ForemLite::Article.new(z) }
end