Class: DisqusApi::Api
- Inherits:
-
Object
- Object
- DisqusApi::Api
- Defined in:
- lib/disqus_api/api.rb
Constant Summary collapse
- DEFAULT_VERSION =
'3.0'
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#specifications ⇒ Object
readonly
Returns the value of attribute specifications.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #connection ⇒ Faraday::Connection
- #connection_options ⇒ Hash
-
#get(path, arguments = {}) ⇒ Object
Performs custom GET request.
-
#initialize(version = DEFAULT_VERSION, specifications = {}) ⇒ Api
constructor
A new instance of Api.
-
#method_missing(method_name, *args) ⇒ Object
DisqusApi.v3.—->><<—–.details.
-
#post(path, arguments = {}) ⇒ Object
Performs custom POST request.
- #respond_to?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(version = DEFAULT_VERSION, specifications = {}) ⇒ Api
Returns a new instance of Api.
8 9 10 11 12 13 14 15 16 17 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
DisqusApi.v3.—->><<—–.details
Forwards calls to API declared in YAML
58 59 60 |
# 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 |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/disqus_api/api.rb', line 4 def endpoint @endpoint end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
4 5 6 |
# File 'lib/disqus_api/api.rb', line 4 def namespaces @namespaces end |
#specifications ⇒ Object (readonly)
Returns the value of attribute specifications.
4 5 6 |
# File 'lib/disqus_api/api.rb', line 4 def specifications @specifications end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
4 5 6 |
# File 'lib/disqus_api/api.rb', line 4 def version @version end |
Instance Method Details
#connection ⇒ Faraday::Connection
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/disqus_api/api.rb', line 29 def connection Faraday.new() 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 ⇒ Hash
20 21 22 23 24 25 26 |
# File 'lib/disqus_api/api.rb', line 20 def { headers: { 'Accept' => "application/json", 'User-Agent' => "DisqusAgent"}, ssl: { verify: false }, url: @endpoint } end |
#get(path, arguments = {}) ⇒ Object
Performs custom GET request
44 45 46 |
# File 'lib/disqus_api/api.rb', line 44 def get(path, arguments = {}) perform_request { connection.get(path, arguments).body } end |
#post(path, arguments = {}) ⇒ Object
Performs custom POST request
51 52 53 |
# 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) ⇒ Boolean
62 63 64 |
# File 'lib/disqus_api/api.rb', line 62 def respond_to?(method_name, include_private = false) namespaces[method_name] || super end |