Class: Zuora::Client
- Inherits:
-
Object
- Object
- Zuora::Client
- Defined in:
- lib/zuora/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
writeonly
Sets the attribute connection.
Instance Method Summary collapse
-
#get(url) ⇒ Faraday::Response
A response, with .headers, .status & .body.
-
#initialize(username, password, sandbox = false) ⇒ Zuora::Client
constructor
Creates a connection instance.
-
#post(url, params) ⇒ Faraday::Response
A response, with .headers, .status & .body.
-
#put(url, params) ⇒ 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zuora/client.rb', line 24 def initialize(username, password, sandbox = false) url = api_url sandbox response = connection(url).post do |req| req.url '/rest/v1/connections' req.headers['apiAccessKeyId'] = username req.headers['apiSecretAccessKey'] = password req.headers['Content-Type'] = 'application/json' end if response.status == 200 = response.headers['set-cookie'].split(' ')[0] @connection = connection(url) else fail ConnectionError, response.body['reasons'] end end |
Instance Attribute Details
#connection=(value) ⇒ Object
Sets the attribute connection
14 15 16 |
# File 'lib/zuora/client.rb', line 14 def connection=(value) @connection = value end |
Instance Method Details
#get(url) ⇒ Faraday::Response
Returns A response, with .headers, .status & .body.
44 45 46 47 48 49 50 |
# File 'lib/zuora/client.rb', line 44 def get(url) @connection.get do |req| req.url url req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = end end |
#post(url, params) ⇒ Faraday::Response
Returns A response, with .headers, .status & .body.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/zuora/client.rb', line 55 def post(url, params) response = @connection.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = req.body = JSON.generate params end response # if response.body['success'] # return response # else # raise ErrorResponse.new(response) # end end |
#put(url, params) ⇒ Faraday::Response
Returns A response, with .headers, .status & .body.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/zuora/client.rb', line 74 def put(url, params) response = @connection.put do |req| req.url url req.headers['Content-Type'] = 'application/json' req.headers['Cookie'] = req.body = JSON.generate params end response # if response.body['success'] # return response # else # raise ErrorResponse.new(response) # end end |