Class: ZuoraAPI::Basic
Constant Summary
Constants inherited from Login
Login::CONNECTION_EXCEPTIONS, Login::CONNECTION_READ_EXCEPTIONS, Login::ENVIRONMENTS, Login::MIN_Endpoint, Login::REGIONS, Login::XML_SAVE_OPTIONS, Login::ZUORA_API_ERRORS
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#session ⇒ Object
Returns the value of attribute session.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes inherited from Login
#bearer_token, #current_error, #current_session, #entity_id, #environment, #errors, #hostname, #oauth_session_expires_at, #region, #status, #tenant_id, #tenant_name, #timeout_sleep, #url, #user_info, #wsdl_number, #zconnect_provider
Instance Method Summary collapse
-
#initialize(username: nil, password: nil, session: nil, **keyword_args) ⇒ Basic
constructor
A new instance of Basic.
- #new_session(auth_type: :basic, debug: false, zuora_track_id: nil) ⇒ Object
Methods inherited from Login
#aqua_endpoint, #aqua_query, #checkJRStatus, #createJournalRun, #dateFormat, #describe_call, endpoints, environments, #fileURL, #getDataSourceExport, #getFileById, #get_catalog, #get_entity_id, #get_file, #get_full_nav, #get_identity, #get_oauth_client, #get_session, #get_zconnect_accesstoken, #is_prod_env, #query, #raise_errors, #refresh_nav, regions, #reporting_url, #rest_call, #rest_domain, #rest_endpoint, #set_nav, #soap_call, #update_create_tenant, #update_environment, #update_region, #update_zconnect_provider
Constructor Details
#initialize(username: nil, password: nil, session: nil, **keyword_args) ⇒ Basic
Returns a new instance of Basic.
4 5 6 7 8 9 10 |
# File 'lib/zuora_api/logins/basic.rb', line 4 def initialize(username: nil, password: nil, session: nil, **keyword_args) self.username = username self.password = password self.current_session = session raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Basic Login but either 'Username' or 'Password' were not passed.") if self.current_session.blank? && (self.password.blank? && self.username.blank?) super end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/zuora_api/logins/basic.rb', line 3 def password @password end |
#session ⇒ Object
Returns the value of attribute session.
3 4 5 |
# File 'lib/zuora_api/logins/basic.rb', line 3 def session @session end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/zuora_api/logins/basic.rb', line 3 def username @username end |
Instance Method Details
#new_session(auth_type: :basic, debug: false, zuora_track_id: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/zuora_api/logins/basic.rb', line 12 def new_session(auth_type: :basic, debug: false, zuora_track_id: nil) raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Basic Login, does not support Authentication of Type: #{auth_type}") if auth_type != :basic raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Request Basic Login but either 'Username' or 'Password' were not passed.") if (self.password.blank? && self.username.blank?) tries ||= 2 request = Nokogiri::XML::Builder.new do |xml| xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' =>"http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:api' => "http://api.zuora.com/" ) do xml['SOAP-ENV'].Header xml['SOAP-ENV'].Body do xml['api'].login do xml['api'].username self.username xml['api'].password self.password xml['api'].entityId self.entity_id if !self.entity_id.blank? end end end end input_xml = Nokogiri::XML(request.to_xml(:save_with => XML_SAVE_OPTIONS).strip) input_xml.xpath('//ns1:session', 'ns1' =>'http://api.zuora.com/').children.remove Rails.logger.debug('Connect') {"SOAP XML: #{input_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug headers = { 'Content-Type' => "text/xml; charset=utf-8" } headers['Zuora-Track-Id'] = zuora_track_id if zuora_track_id.present? response_query = HTTParty.post(self.url,:body => request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, :headers => headers, :timeout => 10) output_xml = Nokogiri::XML(response_query.body) Rails.logger.debug('Connect') {"Response Code: #{response_query.code} SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}"} if debug if !response_query.success? self.current_session = nil if output_xml.namespaces.size > 0 && output_xml.xpath('//soapenv:Fault').size > 0 self.current_error = output_xml.xpath('//fns:FaultMessage', 'fns' =>'http://fault.api.zuora.com/').text if self.current_error.include?('deactivated') self.status = 'Deactivated' self.current_error = 'Deactivated user login, please check with Zuora tenant administrator' self.errors[:username] = self.current_error elsif self.current_error.include?('inactive') self.status = 'Inactive' self.current_error = 'Inactive user login, please check with Zuora tenant administrator' self.errors[:username] = self.current_error elsif self.current_error.include?("invalid username or password") || self.current_error.include?("Invalid login. User name and password do not match.") self.status = 'Invalid Login' self.current_error = 'Invalid login, please check username and password or URL endpoint' self.errors[:username] = self.current_error self.errors[:password] = self.current_error elsif self.current_error.include?('unsupported version') self.status = 'Unsupported API Version' self.current_error = 'Unsupported API version, please verify URL endpoint' self.errors[:url] = self.current_error elsif self.current_error.include?('invalid api version') self.status = 'Invalid API Version' self.current_error = 'Invalid API version, please verify URL endpoint' self.errors[:url] = self.current_error elsif self.current_error.include?('invalid session') self.status = 'Invalid Session' self.current_error = 'Session invalid, please update session and verify URL endpoint' self.errors[:session] = self.current_error elsif self.current_error.include?('Your IP address') self.status = 'Restricted IP' self.current_error = 'IP restricted, contact Zuora tenant administrator and remove IP restriction' self.errors[:base] = self.current_error elsif self.current_error.include?('This account has been locked') self.status = 'Locked' self.current_error = 'Locked user login, please wait or navigate to Zuora to unlock user' self.errors[:username] = self.current_error elsif self.current_error.include?('Entity not exist:') self.status = 'Entity Missing' self.errors[:base] = self.current_error else self.status = 'Unknown' self.current_error = output_xml.xpath('//faultstring').text if self.current_error.blank? self.errors[:base] = self.current_error end else self.status = 'Unknown' self.current_error = output_xml.xpath('//faultstring').text if self.current_error.blank? self.errors[:base] = self.current_error end else #Username & password combo retrieved_session = output_xml.xpath('//ns1:Session', 'ns1' =>'http://api.zuora.com/').text raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new("No session found for api call.", response_query) if retrieved_session.blank? self.status = 'Active' self.current_session = retrieved_session end return self.status rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex if !tries.zero? tries -= 1 Rails.logger.info {"#{ex.class} Timed out will retry after 5 seconds"} sleep(self.timeout_sleep) retry else self.current_error = "Request timed out. Try again" self.status = 'Timeout' return self.status end rescue EOFError if self.url.match?(/.*services\d{1,}.zuora.com*/) self.current_error = "Services tenant '#{self.url.scan(/.*\/\/(services\d{1,}).zuora.com*/).last.first}' is no longer available." self.status = 'Not Available' return self.status end end |