zuora_rest_client 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,8 @@ module ZuoraRestClient
17
17
  entity_name: nil,
18
18
  logger: Logger.new($stdout),
19
19
  log_level: :error,
20
- log: true }
20
+ log: true,
21
+ api_proxy_port: nil }
21
22
 
22
23
  def initialize(username, password, environment = :production, options = {})
23
24
  @username = username
@@ -45,7 +46,7 @@ module ZuoraRestClient
45
46
  end
46
47
 
47
48
  def rest_get(path, zuora_version = nil)
48
- response = rest_connection.get do |request|
49
+ response = rest_connection(use_api_proxy?(path)).get do |request|
49
50
  request.url [ ZUORA_REST_MAJOR_VERSION, path ].join('/')
50
51
  request.headers = rest_headers(zuora_version)
51
52
  end
@@ -78,7 +79,7 @@ module ZuoraRestClient
78
79
  end
79
80
 
80
81
  def rest_post(path, post_data = nil, zuora_version = nil, is_json = true)
81
- response = rest_connection.post do |request|
82
+ response = rest_connection(use_api_proxy?(path)).post do |request|
82
83
  request.url [ ZUORA_REST_MAJOR_VERSION, path ].join('/')
83
84
  request.headers = rest_headers(zuora_version)
84
85
  request.body = MultiJson.dump(post_data) if !post_data.nil? && is_json
@@ -88,7 +89,7 @@ module ZuoraRestClient
88
89
  end
89
90
 
90
91
  def rest_put(path, put_data = nil, zuora_version = nil, is_json = true)
91
- response = rest_connection.put do |request|
92
+ response = rest_connection(use_api_proxy?(path)).put do |request|
92
93
  request.url [ ZUORA_REST_MAJOR_VERSION, path ].join('/')
93
94
  request.headers = rest_headers(zuora_version)
94
95
  request.body = MultiJson.dump(put_data) if !put_data.nil? && is_json
@@ -98,7 +99,7 @@ module ZuoraRestClient
98
99
  end
99
100
 
100
101
  def rest_delete(path, zuora_version = nil)
101
- response = rest_connection.delete do |request|
102
+ response = rest_connection(use_api_proxy?(path)).delete do |request|
102
103
  request.url [ ZUORA_REST_MAJOR_VERSION, path ].join('/')
103
104
  request.headers = rest_headers(zuora_version)
104
105
  end
@@ -153,8 +154,13 @@ module ZuoraRestClient
153
154
  end
154
155
  end
155
156
 
156
- def rest_connection
157
- Faraday.new(url: zuora_endpoint.rest) do |faraday|
157
+ def rest_connection(use_api_proxy = false)
158
+ rest_endpoint_uri = Addressable::URI.parse(zuora_endpoint.rest)
159
+ if use_api_proxy
160
+ rest_endpoint_uri.path = '/'
161
+ rest_endpoint_uri.port = @options[:api_proxy_port] || 443
162
+ end
163
+ Faraday.new(url: rest_endpoint_uri.to_s) do |faraday|
158
164
  faraday.use FaradayMiddleware::FollowRedirects
159
165
  faraday.request :multipart
160
166
  faraday.response :detailed_logger, logger
@@ -172,6 +178,11 @@ module ZuoraRestClient
172
178
  headers
173
179
  end
174
180
 
181
+ def use_api_proxy?(path)
182
+ @environment.to_s.start_with?('services') &&
183
+ (path.start_with?('/action/') || path.start_with?('/object/'))
184
+ end
185
+
175
186
  def zuora_endpoint
176
187
  if @environment.is_a? Symbol
177
188
  if @environment.to_s.start_with?('services')
@@ -1,3 +1,3 @@
1
1
  module ZuoraRestClient
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Massad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-29 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler