Sha256: 3d54c2276aa5a97b4fc47a2ca4aede3b28e17614c4f961253545e1d77f5cdaf3

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

module DisqusApi
  class Namespace
    attr_reader :api, :name, :specification

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

    # @param [String, Symbol] action
    # @param [Hash] arguments Action params
    # @return [Request]
    def build_action_request(action, arguments = {})
      Request.new(api, name, action, arguments)
    end

    # @param [String, Symbol, Hash] action
    # @param [Hash] arguments
    # @return [Hash] response
    def request_action(action, arguments = {})
      build_action_request(action, arguments).response
    end
    alias_method :perform_action, :request_action

    # DisqusApi.v3.users.---->>[details]<<-----
    #
    # Forwards all API calls under a specific namespace
    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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disqus_api-0.0.8 lib/disqus_api/namespace.rb
disqus_api-0.0.7 lib/disqus_api/namespace.rb
disqus_api-0.0.6 lib/disqus_api/namespace.rb
disqus_api-0.0.5 lib/disqus_api/namespace.rb
disqus_api-0.0.4 lib/disqus_api/namespace.rb
disqus_api-0.0.3 lib/disqus_api/namespace.rb
disqus_api-0.0.2 lib/disqus_api/namespace.rb