Class: Zuora::Rest::Client
- Inherits:
-
Object
- Object
- Zuora::Rest::Client
- Defined in:
- lib/zuora/rest/client.rb
Instance Method Summary collapse
-
#initialize(username, password, sandbox = false) ⇒ Zuora::Client
constructor
Creates a connection instance.
-
#method ⇒ Faraday::Response
A response, with .headers, .status & .body.
Constructor Details
#initialize(username, password, sandbox = false) ⇒ Zuora::Client
Creates a connection instance. Makes an initial HTTP request to fetch session token. Subsequent requests made with .get, .post, and .put contain the authenticated session id in their headers.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zuora/rest/client.rb', line 19 def initialize(username, password, sandbox = false) base_url = api_url sandbox conn = connection base_url response = conn.post do |req| set_auth_request_headers! req, username, password end case response.status when 200 @auth_cookie = response.headers['set-cookie'].split(' ')[0] @connection = conn when 429 sleep(Zuora::RETRY_WAITING_PERIOD) return initialize(username, password, sandbox) else fail Zuora::Rest::ConnectionError, response.body['reasons'] end end |
Instance Method Details
#method ⇒ Faraday::Response
Returns A response, with .headers, .status & .body.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zuora/rest/client.rb', line 41 [:get, :delete].each do |method| define_method(method) do |url| response = @connection.send(method) do |req| set_request_headers! req, url end # Handle rate limiting return handle_rate_limiting(method, url) if response.status == 429 fail_or_response(response) end end |