Class: Crawlora::OperationGroup
- Inherits:
-
Object
- Object
- Crawlora::OperationGroup
- Defined in:
- lib/crawlora/client.rb
Overview
Dispatches client.bing.search(…) style calls to the underlying operation id, validating that supplied keyword params are accepted.
Constant Summary collapse
- REQUEST_OPTIONS =
%i[_response_type _timeout _headers].freeze
Instance Method Summary collapse
-
#initialize(client, operations) ⇒ OperationGroup
constructor
A new instance of OperationGroup.
- #method_missing(name, **params) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(client, operations) ⇒ OperationGroup
Returns a new instance of OperationGroup.
626 627 628 629 |
# File 'lib/crawlora/client.rb', line 626 def initialize(client, operations) @client = client @operations = operations end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, **params) ⇒ Object
635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/crawlora/client.rb', line 635 def method_missing(name, **params) operation_id = @operations[name.to_s] return super if operation_id.nil? response_type = params.delete(:_response_type) || "auto" timeout = params.delete(:_timeout) headers = params.delete(:_headers) allowed = allowed_params(operation_id) unknown = params.keys.map(&:to_s) - allowed raise ArgumentError, "unexpected parameter(s) for #{operation_id}: #{unknown.sort.join(", ")}" unless unknown.empty? @client.request(operation_id, params, response_type: response_type, timeout: timeout, headers: headers) end |
Instance Method Details
#respond_to_missing?(name, include_private = false) ⇒ Boolean
631 632 633 |
# File 'lib/crawlora/client.rb', line 631 def respond_to_missing?(name, include_private = false) @operations.key?(name.to_s) || super end |