Class: Zoomus::Utils
- Inherits:
-
Object
- Object
- Zoomus::Utils
- Defined in:
- lib/zoomus/utils.rb
Class Method Summary collapse
- .argument_error(name) ⇒ Object
-
.define_bang_methods(klass) ⇒ Object
Dinamically defines bang methods for Actions modules.
- .extract_options!(array) ⇒ Object
- .parse_response(http_response) ⇒ Object
- .process_datetime_params!(params, options) ⇒ Object
- .raise_if_error!(response) ⇒ Object
- .require_params(params, options) ⇒ Object
Class Method Details
.argument_error(name) ⇒ Object
6 7 8 |
# File 'lib/zoomus/utils.rb', line 6 def argument_error(name) name ? ArgumentError.new("You must provide #{name}") : ArgumentError.new end |
.define_bang_methods(klass) ⇒ Object
Dinamically defines bang methods for Actions modules
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zoomus/utils.rb', line 35 def define_bang_methods(klass) klass.instance_methods.each do |m| klass.send(:define_method, "#{m}!") do |*args| begin response = send(m, *args) Utils.raise_if_error!(response) rescue Net::OpenTimeout, Net::ReadTimeout, Timeout::Error => _e raise ::Zoomus::GatewayTimeout.new end end end end |
.extract_options!(array) ⇒ Object
48 49 50 |
# File 'lib/zoomus/utils.rb', line 48 def (array) array.last.is_a?(::Hash) ? array.pop : {} end |
.parse_response(http_response) ⇒ Object
18 19 20 21 22 |
# File 'lib/zoomus/utils.rb', line 18 def parse_response(http_response) response = http_response.parsed_response # Mocked response returns a string response.kind_of?(Hash) ? response : JSON.parse(response) end |
.process_datetime_params!(params, options) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/zoomus/utils.rb', line 52 def process_datetime_params!(params, ) params = [params] unless params.is_a? Array params.each do |param| if [param] && [param].kind_of?(Time) [param] = [param].strftime("%FT%TZ") end end end |
.raise_if_error!(response) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/zoomus/utils.rb', line 10 def raise_if_error!(response) if response["error"] raise Error.new(response["error"]["message"]) else response end end |
.require_params(params, options) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/zoomus/utils.rb', line 24 def require_params(params, ) params = [params] unless params.is_a? Array params.each do |param| unless [param] raise argument_error(param.to_s) break end end end |