class DisqusApi::Api

Constants

DEFAULT_VERSION

Attributes

endpoint[R]
namespaces[R]
specifications[R]
version[R]

Public Class Methods

new(version = DEFAULT_VERSION, specifications = {}) click to toggle source

@param [String] version @param [Hash] specifications API specifications

# File lib/disqus_api/api.rb, line 8
def initialize(version = DEFAULT_VERSION, specifications = {})
  @version = version
  @endpoint = "https://disqus.com/api/#@version/".freeze
  @specifications = ActiveSupport::HashWithIndifferentAccess.new(specifications)

  @namespaces = ActiveSupport::HashWithIndifferentAccess.new
  @specifications.keys.each do |namespace|
    @namespaces[namespace] = Namespace.new(self, namespace)
  end
end

Public Instance Methods

connection() click to toggle source

@return [Faraday::Connection]

# File lib/disqus_api/api.rb, line 29
def connection
  Faraday.new(connection_options) do |builder|
    builder.use Faraday::Request::Multipart
    builder.use Faraday::Request::UrlEncoded
    builder.use Faraday::Response::ParseJson

    builder.params.merge!(DisqusApi.config.slice(:api_secret, :api_key, :access_token))

    builder.adapter(*DisqusApi.adapter)
  end
end
connection_options() click to toggle source

@return [Hash]

# File lib/disqus_api/api.rb, line 20
def connection_options
  {
    headers: { 'Accept' => "application/json", 'User-Agent' => "DisqusAgent"},
    ssl: { verify: false },
    url: @endpoint
  }
end
get(path, arguments = {}) click to toggle source

Performs custom GET request @param [String] path @param [Hash] arguments

# File lib/disqus_api/api.rb, line 44
def get(path, arguments = {})
  perform_request { connection.get(path, arguments).body }
end
method_missing(method_name, *args) click to toggle source

DisqusApi.v3.---->>[users]<<—–.details

Forwards calls to API declared in YAML

# File lib/disqus_api/api.rb, line 58
def method_missing(method_name, *args)
  namespaces[method_name] or raise(ArgumentError, "No such namespace #{method_name}")
end
post(path, arguments = {}) click to toggle source

Performs custom POST request @param [String] path @param [Hash] arguments

# File lib/disqus_api/api.rb, line 51
def post(path, arguments = {})
  perform_request { connection.post(path, arguments).body }
end
respond_to?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/disqus_api/api.rb, line 62
def respond_to?(method_name, include_private = false)
  namespaces[method_name] || super
end

Private Instance Methods

perform_request() { || ... } click to toggle source
# File lib/disqus_api/api.rb, line 68
def perform_request
  yield.tap do |response|
    raise InvalidApiRequestError.new(response) if response['code'] != 0
  end