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.
591 592 593 594 |
# File 'lib/crawlora/client.rb', line 591 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
600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/crawlora/client.rb', line 600 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
596 597 598 |
# File 'lib/crawlora/client.rb', line 596 def respond_to_missing?(name, include_private = false) @operations.key?(name.to_s) || super end |