class DisqusApi::Request

Attributes

action[R]
api[R]
arguments[R]
namespace[R]
path[R]
type[R]

Public Class Methods

new(api, namespace, action, arguments = {}) click to toggle source

@param [DisqusApi::Api] api @param [String] namespace @param [String] action @param [Hash] arguments Request parameters

# File lib/disqus_api/request.rb, line 9
def initialize(api, namespace, action, arguments = {})
  @api = api
  @namespace = namespace.to_s
  @action = action.to_s
  @path = "#@namespace/#@action.json"

  # Request type GET or POST
  namespace_specification = @api.specifications[@namespace] or raise(ArgumentError, "No such namespace: #@namespace")
  @type = namespace_specification[@action].try(:to_sym) or raise(ArgumentError, "No such API path: #@path")

  # Set request parameters
  @arguments = arguments
end
perform(*args) click to toggle source

@see initialize @param [String, Symbol] request_type @return [Hash]

# File lib/disqus_api/request.rb, line 46
def self.perform(*args)
  self.new(*args).perform
end

Public Instance Methods

perform(arguments = {}) click to toggle source

Returns plain JSON response received from Disqus @param [Hash] arguments @return [String]

# File lib/disqus_api/request.rb, line 34
def perform(arguments = {})
  case type.to_sym
  when :post, :get
    api.public_send(type, path, @arguments.merge(arguments))
  else
    raise ArgumentError, "Unregistered request type #{request_type}"
  end
end
response(arguments = {}) click to toggle source

Returns Disqus API response proxy @param [Symbol] request_type @param [Hash] arguments @return [String]

# File lib/disqus_api/request.rb, line 27
def response(arguments = {})
  Response.new(self, arguments)
end