Module: TogglRb::EndpointDSL::ClassMethods
- Defined in:
- lib/toggl_rb/endpoint_dsl.rb
Constant Summary collapse
- ALLOWED_METHOD_TYPES =
%i[post get put patch].freeze
- ALLOWED_PRETTY =
ALLOWED_METHOD_TYPES.map { |s| ":#{s}" }.join(", ").freeze
Instance Method Summary collapse
- #method_added(method_name) ⇒ Object
- #method_query_params ⇒ Object
- #method_request_methods ⇒ Object
- #method_request_paths ⇒ Object
- #param(name, type, *other_args) ⇒ Object
- #param_definitions ⇒ Object
- #query_param(name, type, *other_args) ⇒ Object
- #request_method(method_type) ⇒ Object
- #request_path(path) ⇒ Object
Instance Method Details
#method_added(method_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 13 def method_added(method_name) return if @adding_method || !@current_path param_definitions[method_name] = @current_params || {} method_request_paths[method_name] = @current_path method_request_methods[method_name] = @current_method_type method_query_params[method_name] = @current_query_params || {} @current_params = nil # Reset for the next method @current_path = nil @current_method_type = nil super end |
#method_query_params ⇒ Object
41 42 43 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 41 def method_query_params @method_query_params ||= {} end |
#method_request_methods ⇒ Object
49 50 51 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 49 def method_request_methods @method_request_methods ||= {} end |
#method_request_paths ⇒ Object
45 46 47 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 45 def method_request_paths @method_request_paths ||= {} end |
#param(name, type, *other_args) ⇒ Object
53 54 55 56 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 53 def param(name, type, *other_args) @current_params ||= {} @current_params[name] = { type: type, other_args: other_args } end |
#param_definitions ⇒ Object
37 38 39 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 37 def param_definitions @param_definitions ||= {} end |
#query_param(name, type, *other_args) ⇒ Object
58 59 60 61 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 58 def query_param(name, type, *other_args) @current_query_params ||= {} @current_query_params[name] = { type: type, other_args: other_args } end |
#request_method(method_type) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 30 def request_method(method_type) method_type = method_type.to_sym return @current_method_type = method_type if ALLOWED_METHOD_TYPES.include?(method_type) raise ArgumentError, "method type: #{method_type} is not one of #{ALLOWED_PRETTY}" end |
#request_path(path) ⇒ Object
26 27 28 |
# File 'lib/toggl_rb/endpoint_dsl.rb', line 26 def request_path(path) @current_path = path end |