class Rubeetup::Request
Represents API requests. Provides for their own validation and execution
Attributes
@return [String] method_path
the path of the Meetup API resource
@return [Lambda] multipart if present it contains the multipart POST logic
@return [Symbol] name the name of the request as input by the user
@return [Hash{Symbol=>String}] options holds the request’s options
@return [Rubeetup::Sender] sender the request’s chosen sender
Public Class Methods
@param [Hash{Symbol=>String}] args holds the request’s data @option args [Symbol] :name the full request’s name @option args [Hash{Symbol=>String}] :options holds the request’s options @option args [Symbol] :http_verb the request’s http_verb
# File lib/rubeetup/request.rb, line 47 def initialize(args = {}) @name = args[:name] @options = args[:options] validate_request @http_verb = args[:http_verb] @method_path = request_path.call(@options) @multipart = request_multipart @sender = Rubeetup::RequestSender.new end
Public Instance Methods
Completes this request @return [Array<Rubeetup::ResponseWrapper>] the request’s response
# File lib/rubeetup/request.rb, line 61 def execute sender.get_response(self) end
For debugging purposes
# File lib/rubeetup/request.rb, line 68 def to_s <<-DOC.gsub(/^ {8}/, '') \nREQUEST name => #{name} verb => #{http_verb} path => #{method_path} options => #{options.inspect}\n DOC end
Private Instance Methods
# File lib/rubeetup/request.rb, line 135 def error_class Rubeetup::RequestError end
# File lib/rubeetup/request.rb, line 107 def existence_message <<-DOC.gsub(/^ {8}/, '') The provided request => '#{name}' is an invalid request. This request does not exist in the catalog of supported requests. Please consult rubeetup/requests_lib/meetup_catalog.rb, or the provided documentation for the complete list of requests. DOC end
Uses sets to make sure that there is at least a set of required parameters which is a subset of the arguments passed to the request @return [Boolean] whether all the required arguments have been passed
# File lib/rubeetup/request.rb, line 98 def has_all_required_options? required_keys_sets = required_options.map do |elem| elem.respond_to?(:to_set) ? elem.to_set : Set[elem] end return true if required_keys_sets.empty? option_keys_set = options.keys.to_set required_keys_sets.any? { |set| set.subset? option_keys_set } end
# File lib/rubeetup/request.rb, line 116 def options_message <<-DOC.gsub(/^ {8}/, '') This request cannot be completed as is. The provided arguments => '#{options.inspect}' miss one or more required parameters. The request '#{name}' requires the following parameters: #{required_options_message} Please consult rubeetup/requests_lib/meetup_catalog.rb, or the provided documentation for the complete list of requests, and their respective required parameters. DOC end
# File lib/rubeetup/request.rb, line 129 def required_options_message str = '' required_options.each {|opt| str << opt.inspect + " OR "} str[0...-4] end
# File lib/rubeetup/request.rb, line 89 def validate_options fail error_class, options_message unless has_all_required_options? end
# File lib/rubeetup/request.rb, line 80 def validate_request verify_existence validate_options end
# File lib/rubeetup/request.rb, line 85 def verify_existence fail error_class, existence_message unless is_in_catalog? end