Class: DisqusApi::Namespace
- Inherits:
-
Object
- Object
- DisqusApi::Namespace
- Defined in:
- lib/disqus_api/namespace.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#specification ⇒ Object
readonly
Returns the value of attribute specification.
Instance Method Summary collapse
- #build_action_request(action, arguments = {}) ⇒ Request
-
#initialize(api, name) ⇒ Namespace
constructor
A new instance of Namespace.
- #method_missing(method_name, *args) ⇒ Object
-
#request_action(action, arguments = {}) ⇒ Hash
(also: #perform_action)
Response.
- #respond_to?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(api, name) ⇒ Namespace
Returns a new instance of Namespace.
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
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
#api ⇒ Object (readonly)
Returns the value of attribute api.
3 4 5 |
# File 'lib/disqus_api/namespace.rb', line 3 def api @api end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/disqus_api/namespace.rb', line 3 def name @name end |
#specification ⇒ Object (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
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.
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
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 |