Module: Giftbit::Util
- Included in:
- Request
- Defined in:
- lib/giftbit-rails/util.rb
Instance Method Summary collapse
- #argument_error(name) ⇒ Object
- #extract_errors(response) ⇒ Object
- #extract_params(args) ⇒ Object
- #raise_id_error(args) ⇒ Object
- #raise_id_or_uuid_error(args) ⇒ Object
- #raise_uuid_error(args) ⇒ Object
Instance Method Details
#argument_error(name) ⇒ Object
3 4 5 |
# File 'lib/giftbit-rails/util.rb', line 3 def argument_error(name) name ? ArgumentError.new("#{name} is required!") : ArgumentError.new end |
#extract_errors(response) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/giftbit-rails/util.rb', line 30 def extract_errors response parsed_response = response.parsed_response raise Giftbit::BadRequest.new(parsed_response) if response.code == 400 raise Giftbit::.new(parsed_response) if response.code == 401 raise Giftbit::CreditCardFailure.new(parsed_response) if response.code == 402 raise Giftbit::Forbidden.new(parsed_response) if response.code == 403 raise Giftbit::UnprocessableEntity.new(parsed_response) if response.code == 422 raise Giftbit::TooManyRequests.new(parsed_response) if response.code == 429 raise Giftbit::InternalServiceError.new(parsed_response) if response.code == 500 raise Giftbit::ServiceUnavailable.new(parsed_response) if response.code == 503 parsed_response end |
#extract_params(args) ⇒ Object
7 8 9 |
# File 'lib/giftbit-rails/util.rb', line 7 def extract_params(args) args.last.is_a?(::Hash) ? args.pop.with_indifferent_access : {} end |
#raise_id_error(args) ⇒ Object
17 18 19 20 21 |
# File 'lib/giftbit-rails/util.rb', line 17 def raise_id_error args params = extract_params(args) argument_error "id" if params[:id].blank? params end |
#raise_id_or_uuid_error(args) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/giftbit-rails/util.rb', line 23 def raise_id_or_uuid_error args params = extract_params(args) id = params[:id] || params[:uuid] argument_error "id or uuid" if id.blank? params end |
#raise_uuid_error(args) ⇒ Object
11 12 13 14 15 |
# File 'lib/giftbit-rails/util.rb', line 11 def raise_uuid_error args params = extract_params(args) argument_error "uuid" if params[:uuid].blank? params end |