Class: SevenRooms::Authentication
- Inherits:
-
Object
- Object
- SevenRooms::Authentication
- Includes:
- DefaultErrorContainer, ApiHelpers
- Defined in:
- app/services/seven_rooms/authentication.rb
Instance Method Summary collapse
-
#auth_request ⇒ Object
Sends an authentication request to the SevenRooms API.
Methods included from ApiHelpers
#api_uri, #auth_headers, #common_headers, #find_seven_rooms_vendor_application, #parse_user_or_guest_full_name, #parsed_vendor_name, #send_error_availability_notification_to_staff, #sevenrooms_credit_card_error?, #standardize_or_default_phone
Methods included from DefaultErrorContainer
#error, #error_message_simple, #merge_errors
Instance Method Details
#auth_request ⇒ Object
Sends an authentication request to the SevenRooms API.
Returns a ServiceResult object containing the response data if the request is successful, otherwise returns a ServiceResult object with errors and an error message.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/seven_rooms/authentication.rb', line 13 def auth_request begin res = DefaultFaradayClient.create_faraday_connection.post do |req| req.url "#{api_uri}/auth" req.headers.update(auth_headers) req.body = URI.encode_www_form(request_body) end rescue Faraday::Error => e = "Error occurred while making a request to SevenRooms: #{e.}" errors.add(:base, ) return ServiceResult.new errors: errors, message: end res_json = JSON.parse(res.body) if res.status != 200 || res_json['status'] != 200 = res_json['msg'] APMErrorHandler.report("#{self.class} #{}") unless SevenRooms::ErrorMessages::KNOWN_ERRORS.include?() errors.add(:base, ) return ServiceResult.new errors: errors, message: end ServiceResult.new data: res_json['data'] end |