zuora_connect 1.3.0a → 1.3.0b
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 539b14028c8efc7b82b7ce290d961b98f5312dda
|
4
|
+
data.tar.gz: ca9cdeef30c05a7a5466f7fefc5702c78cd92f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab991527b2acafd51e4073179437cb30aaac6bb1d84cdf0d3978a03ea0583bd1713286e55261fb0795fc89c5ea00d8bb96a979210e96640943680730456d6499
|
7
|
+
data.tar.gz: 3123bf76dd8c2c50f3616ac79ceb9f7083dab16ef26b1f24e6f00d8a2460ae47170196530702607364d0fff55bbbefe00deb119b6de99ac389984339356c912f
|
@@ -5,7 +5,6 @@ module ZuoraConnect
|
|
5
5
|
attr_accessor :options, :mode, :logins, :valid, :task_data, :last_refresh, :username, :password, :s3_client, :api_version
|
6
6
|
|
7
7
|
def init
|
8
|
-
@api_version = self.access_token.include? ("@") ? "v1" : "v2"
|
9
8
|
@options = Hash.new
|
10
9
|
@logins = Hash.new
|
11
10
|
if ZuoraConnect.configuration.use_s3
|
@@ -26,6 +25,7 @@ module ZuoraConnect
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def new_session(session: {}, username: self.access_token, password: self.refresh_token)
|
28
|
+
@api_version = (username.include?("@") ? "v1" : "v2")
|
29
29
|
@username = username
|
30
30
|
@password = password
|
31
31
|
@last_refresh = session["#{self.id}::last_refresh"]
|
@@ -41,14 +41,14 @@ module ZuoraConnect
|
|
41
41
|
self.mode = ZuoraConnect.configuration.dev_mode_mode
|
42
42
|
else
|
43
43
|
if session.nil? || (!session.nil? && self.id != session["appInstance"].to_i) || session["#{self.id}::task_data"].blank? || ( session["#{self.id}::last_refresh"].blank? || session["#{self.id}::last_refresh"].to_i < ZuoraConnect.configuration.timeout.ago.to_i )
|
44
|
-
Rails.logger.debug("REFRESHING - Session Nil") if session.nil?
|
45
|
-
Rails.logger.debug("REFRESHING - AppInstance ID does not match session id") if (!session.nil? && self.id != session["appInstance"].to_i)
|
46
|
-
Rails.logger.debug("REFRESHING - Task Data Blank") if session["#{self.id}::task_data"].blank?
|
47
|
-
Rails.logger.debug("REFRESHING - No Time on Cookie") if session["#{self.id}::last_refresh"].blank?
|
48
|
-
Rails.logger.debug("REFRESHING - Session Old") if (session["#{self.id}::last_refresh"].blank? || session["#{self.id}::last_refresh"].to_i < ZuoraConnect.configuration.timeout.ago.to_i )
|
44
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - Session Nil") if session.nil?
|
45
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - AppInstance ID(#{self.id}) does not match session id(#{session["appInstance"].to_i})") if (!session.nil? && self.id != session["appInstance"].to_i)
|
46
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - Task Data Blank") if session["#{self.id}::task_data"].blank?
|
47
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - No Time on Cookie") if session["#{self.id}::last_refresh"].blank?
|
48
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - Session Old") if (session["#{self.id}::last_refresh"].blank? || session["#{self.id}::last_refresh"].to_i < ZuoraConnect.configuration.timeout.ago.to_i )
|
49
49
|
self.refresh(session)
|
50
50
|
else
|
51
|
-
Rails.logger.debug("REBUILDING")
|
51
|
+
Rails.logger.debug("[#{self.id}] REBUILDING")
|
52
52
|
build_task(session["#{self.id}::task_data"], session)
|
53
53
|
end
|
54
54
|
end
|
@@ -92,7 +92,7 @@ module ZuoraConnect
|
|
92
92
|
if self.api_version == "v1"
|
93
93
|
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:basic_auth => auth = {:username => self.username, :password => self.password})
|
94
94
|
else
|
95
|
-
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.
|
95
|
+
response = HTTParty.get(ZuoraConnect.configuration.url + "/api/#{self.api_version}/tools/tasks/#{self.id}.json",:body => {:access_token => self.access_token})
|
96
96
|
end
|
97
97
|
if response.code == 200
|
98
98
|
@last_refresh = Time.now.to_i
|
@@ -101,9 +101,13 @@ module ZuoraConnect
|
|
101
101
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Communicating with Connect", response.body, response.code)
|
102
102
|
end
|
103
103
|
rescue
|
104
|
-
self.
|
105
|
-
|
106
|
-
|
104
|
+
if self.api_version == "v2" && count < 2 && response.code == 401
|
105
|
+
self.refresh_oauth
|
106
|
+
count += 1
|
107
|
+
retry
|
108
|
+
else
|
109
|
+
raise
|
110
|
+
end
|
107
111
|
end
|
108
112
|
|
109
113
|
def build_task(task_data, session)
|
@@ -155,11 +159,9 @@ module ZuoraConnect
|
|
155
159
|
end
|
156
160
|
|
157
161
|
def refresh_oauth
|
158
|
-
Rails.logger.debug("REFRESHING - OAuth")
|
162
|
+
Rails.logger.debug("[#{self.id}] REFRESHING - OAuth")
|
159
163
|
params = {
|
160
164
|
:grant_type => "refresh_token",
|
161
|
-
:client_id => ZuoraConnect.configuration.oauth_client_id,
|
162
|
-
:client_secret => ZuoraConnect.configuration.oauth_client_secret,
|
163
165
|
:redirect_uri => ZuoraConnect.configuration.oauth_client_redirect_uri,
|
164
166
|
:refresh_token => self.refresh_token
|
165
167
|
}
|
@@ -168,7 +170,7 @@ module ZuoraConnect
|
|
168
170
|
if response.code == 200
|
169
171
|
self.refresh_token = response_body["refresh_token"]
|
170
172
|
self.access_token = response_body["access_token"]
|
171
|
-
self.
|
173
|
+
self.oauth_expires_at = Time.at(response_body["created_at"].to_i) + response_body["expires_in"].seconds
|
172
174
|
self.save
|
173
175
|
else
|
174
176
|
raise ZuoraConnect::Exceptions::ConnectCommunicationError.new("Error Refreshing Access Token", response.body, response.code)
|
@@ -10,17 +10,17 @@ module ZuoraConnect
|
|
10
10
|
|
11
11
|
def authenticate_app_api_request
|
12
12
|
start_time = Time.now
|
13
|
-
|
14
|
-
@appinstance = ZuoraConnect::AppInstance.where(:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
if !params[:access_token].blank?
|
14
|
+
@appinstance = ZuoraConnect::AppInstance.where(:api_token => params[:access_token]).first
|
15
|
+
check_instance
|
16
|
+
else
|
17
|
+
authenticate_or_request_with_http_basic do |username, password|
|
18
|
+
@appinstance = ZuoraConnect::AppInstance.where(:token => password).first
|
19
|
+
@appinstance ||= ZuoraConnect::AppInstance.where(:api_token => password).first
|
20
|
+
check_instance
|
21
21
|
end
|
22
22
|
end
|
23
|
-
Rails.logger.debug("Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
|
23
|
+
Rails.logger.debug("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s")
|
24
24
|
end
|
25
25
|
|
26
26
|
def authenticate_connect_app_request
|
@@ -37,7 +37,7 @@ module ZuoraConnect
|
|
37
37
|
@appinstance.new_session(:session =>instance_data_lookup(@appinstance.id))
|
38
38
|
I18n.locale = session["#{@appinstance.id}::user::locale"] ? session["#{@appinstance.id}::user::locale"] : @appinstance.locale
|
39
39
|
Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
|
40
|
-
Rails.logger.debug("Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
|
40
|
+
Rails.logger.debug("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s")
|
41
41
|
end
|
42
42
|
|
43
43
|
def persist_connect_app_session
|
@@ -76,10 +76,10 @@ module ZuoraConnect
|
|
76
76
|
if @appinstance.blank?
|
77
77
|
Apartment::Tenant.switch!("public")
|
78
78
|
Apartment::Tenant.create(values["appInstance"].to_s)
|
79
|
-
@appinstance = ZuoraConnect::AppInstance.create!(:id => values["appInstance"].to_i, :access_token => values["access_token"], :
|
79
|
+
@appinstance = ZuoraConnect::AppInstance.create!(:api_token => values[:api_token],:id => values["appInstance"].to_i, :access_token => values["access_token"], :token => values["refresh_token"] , :refresh_token => values["refresh_token"].blank?, :oauth_expires_at => values["expires"])
|
80
80
|
end
|
81
|
-
if @appinstance.access_token.blank? || @appinstance.refresh_token.blank?
|
82
|
-
@appinstance.update_attributes(:access_token =>
|
81
|
+
if (@appinstance.access_token.blank? || @appinstance.access_token != (values["access_token"].blank? ? values["user"] : values["access_token"]) )|| (@appinstance.refresh_token.blank? || @appinstance.refresh_token != (values["refresh_token"].blank? ? values["key"] : values["refresh_token"])) || @appinstance.api_token.blank?
|
82
|
+
@appinstance.update_attributes(:access_token => values["access_token"], :refresh_token => values["refresh_token"], :oauth_expires_at => values["expires"],:api_token => values["api_token"])
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -110,5 +110,17 @@ module ZuoraConnect
|
|
110
110
|
end
|
111
111
|
|
112
112
|
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def check_instance
|
117
|
+
if !@appinstance.blank?
|
118
|
+
@appinstance.new_session(:session => instance_data_lookup(@appinstance.id))
|
119
|
+
Thread.current[:appinstance] = @appinstance
|
120
|
+
return @appinstance.valid
|
121
|
+
else
|
122
|
+
render text: "Access Denied", status: :unauthorized
|
123
|
+
end
|
124
|
+
end
|
113
125
|
end
|
114
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.0b
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- db/migrate/20161024220705_add_token_to_app_instance.rb
|
161
161
|
- db/migrate/20170131211919_add_sessions_table.rb
|
162
162
|
- db/migrate/20170411200303_add_expiration_to_app_instance.rb
|
163
|
+
- db/migrate/20170413191512_add_new_api_token.rb
|
163
164
|
- lib/tasks/zuora_connect_tasks.rake
|
164
165
|
- lib/zuora_connect.rb
|
165
166
|
- lib/zuora_connect/configuration.rb
|