Sha256: 8570f1154f59c8bd0a0bfbd0ef7784caade99f29c8e7c86dc5034276c98bf4a2

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

module ForemLite
  class Client
    include HTTParty
    base_uri "https://dev.to/api/"

    #
    # Create a new client object with your Forem API key.
    #
    # @param [String] api_key <Forem/Dev.to API Key>
    #
    def initialize(api_key = nil)
      self.class.default_options[:headers] = {"api-key" => api_key} if api_key
    end

    #
    # Retrieve a list of articles.
    #
    # @return [Array<Object>] collection of ForemLite::Article objects
    #
    def articles
      self.class.get("/articles").tap { |z| ForemLite::Article.new(z) }
    end

    #
    # Retrieve a single published article given its id.
    #
    # @param [Integer, String] id <a string or integer representing the article id>
    #
    # @return [Object] a FormCli::Article object
    #
    def article(id)
      ForemLite::Article.new(self.class.get("/articles/#{id}"))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forem_lite-0.0.2 lib/forem_lite/client.rb