Class: DisqusApi::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/disqus_api/namespace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, name) ⇒ Namespace

Returns a new instance of Namespace.

Parameters:

  • api (Api)
  • name (String, Symbol)


7
8
9
10
11
12
# File 'lib/disqus_api/namespace.rb', line 7

def initialize(api, name)
  @api = api
  @name = name
  @specification = @api.specifications[@name]
  @specification or raise(ArgumentError, "No such namespace <#@name>")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

DisqusApi.v3.users.—->><<—–

Forwards all API calls under a specific namespace



32
33
34
35
36
37
38
# File 'lib/disqus_api/namespace.rb', line 32

def method_missing(method_name, *args)
  if specification.has_key?(method_name.to_s)
    request_action(method_name, *args)
  else
    raise NoMethodError, "No action #{method_name} registered for #@name namespace"
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



3
4
5
# File 'lib/disqus_api/namespace.rb', line 3

def api
  @api
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/disqus_api/namespace.rb', line 3

def name
  @name
end

#specificationObject (readonly)

Returns the value of attribute specification.



3
4
5
# File 'lib/disqus_api/namespace.rb', line 3

def specification
  @specification
end

Instance Method Details

#build_action_request(action, arguments = {}) ⇒ Request

Parameters:

  • action (String, Symbol)
  • arguments (Hash) (defaults to: {})

    Action params

Returns:



17
18
19
# File 'lib/disqus_api/namespace.rb', line 17

def build_action_request(action, arguments = {})
  Request.new(api, name, action, arguments)
end

#request_action(action, arguments = {}) ⇒ Hash Also known as: perform_action

Returns response.

Parameters:

  • action (String, Symbol, Hash)
  • arguments (Hash) (defaults to: {})

Returns:

  • (Hash)

    response



24
25
26
# File 'lib/disqus_api/namespace.rb', line 24

def request_action(action, arguments = {})
  build_action_request(action, arguments).response
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/disqus_api/namespace.rb', line 40

def respond_to?(method_name, include_private = false)
  specification[method_name.to_s] || super
end