Class: DisqusApi::Request
- Inherits:
-
Object
- Object
- DisqusApi::Request
- Defined in:
- lib/disqus_api/request.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(api, namespace, action, arguments = {}) ⇒ Request
constructor
A new instance of Request.
-
#perform(arguments = {}) ⇒ String
Returns plain JSON response received from Disqus.
-
#response(arguments = {}) ⇒ String
Returns Disqus API response proxy.
Constructor Details
#initialize(api, namespace, action, arguments = {}) ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def action @action end |
#api ⇒ Object (readonly)
Returns the value of attribute api.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def api @api end |
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def arguments @arguments end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def namespace @namespace end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/disqus_api/request.rb', line 3 def type @type end |
Class Method Details
.perform(*args) ⇒ Hash
46 47 48 |
# File 'lib/disqus_api/request.rb', line 46 def self.perform(*args) self.new(*args).perform end |
Instance Method Details
#perform(arguments = {}) ⇒ String
Returns plain JSON response received from Disqus
34 35 36 37 38 39 40 41 |
# 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 |