ZOHOCRMSDK2_0 3.0.0 → 4.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03d299e56d131411933e4782f22b1dc9fa09c876cd65a499ee60bd4fed382c68
4
- data.tar.gz: fb7567e5159da8d9c02ef5c81dc70e93b5156c46503559709c75a59115db254e
3
+ metadata.gz: 95865623be0d4e3e6d16852e488ae76ca600dd87ca4172a5d1ffc8e1295a3fc8
4
+ data.tar.gz: b73357f1f0a84c80eaaeb536448f1909b5234c284bc77d8f45d096f6e3d1fd55
5
5
  SHA512:
6
- metadata.gz: 7767ac62c6088b5fd12a0b96f431cbf7b8d2d1e7d02edfd087e5b3e642b70a1a95bef570ed54954dd2d7899807e64aabbd33069c0086607a4343858c52d98bf7
7
- data.tar.gz: 669b4d9ee236a466f57a04f5248bae2e98e1a6a937f2332802604105e7a71aeb971abf55ea1ca257aab26de939166322f9d8737045a3ced9bdfa165c3aa74810
6
+ metadata.gz: c3fe08e3bdeb1104f3840d07e8865e38262255783dfcef8310a5a590e56069337c80c5ba5dbec0161a086a45475ef79f382e469d9a217aff948e4163d5f6b7ae
7
+ data.tar.gz: 395d864f10ee6dba4807305e95badbad33e7c8b55218fe9775dbadf9b305adca35a09c755c27d84b7943b5a9955a7b69e1594b57a9aa60c8cf0ffa8f6d11596b
@@ -23,61 +23,68 @@ module ZOHOCRMSDK
23
23
  # @param redirect_url [string] A String containing the OAuth redirect URL.
24
24
  # @param id [string] A String containing ID
25
25
 
26
- def initialize(client_id:, client_secret:, grant_token: nil, refresh_token: nil, redirect_url: nil,id: nil)
27
- error ={}
28
- unless client_id.is_a?(String)
29
- error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_ID
26
+ def initialize(client_id: nil, client_secret: nil, grant_token: nil, refresh_token: nil, redirect_url: nil, id: nil, access_token: nil)
27
+ error = {}
30
28
 
31
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
29
+ if grant_token.nil? && refresh_token.nil? && id.nil? && access_token.nil?
30
+ raise SDKException.new(code:Constants::MANDATORY_VALUE_ERROR, message:Constants::MANDATORY_KEY_ERROR, details:Constants::OAUTH_MANDATORY_KEYS)
31
+ end
32
32
 
33
- error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
33
+ if id.nil? and access_token.nil?
34
+ unless client_id.is_a?(String)
35
+ error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_ID
34
36
 
35
- raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
37
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
36
38
 
37
- end
39
+ error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
38
40
 
39
- unless client_secret.is_a?(String)
40
- error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_SECRET
41
+ raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
41
42
 
42
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
43
+ end
43
44
 
44
- error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
45
+ unless client_secret.is_a?(String)
46
+ error[Constants::ERROR_HASH_FIELD] = Constants::CLIENT_SECRET
45
47
 
46
- raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
48
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
47
49
 
48
- end
50
+ error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
49
51
 
50
- if !grant_token.nil? && !grant_token.is_a?(String)
51
- error[Constants::ERROR_HASH_FIELD] = Constants::GRANT_TOKEN
52
+ raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
52
53
 
53
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
54
+ end
54
55
 
55
- error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
56
+ if !grant_token.nil? && !grant_token.is_a?(String)
57
+ error[Constants::ERROR_HASH_FIELD] = Constants::GRANT_TOKEN
56
58
 
57
- raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
59
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
58
60
 
59
- end
61
+ error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
60
62
 
61
- if !refresh_token.nil? && !refresh_token.is_a?(String)
62
- error[Constants::ERROR_HASH_FIELD] = Constants::REFRESH_TOKEN
63
+ raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
63
64
 
64
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
65
+ end
65
66
 
66
- error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
67
+ if !refresh_token.nil? && !refresh_token.is_a?(String)
68
+ error[Constants::ERROR_HASH_FIELD] = Constants::REFRESH_TOKEN
67
69
 
68
- raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
70
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
69
71
 
70
- end
72
+ error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
71
73
 
72
- if !redirect_url.nil? && !redirect_url.is_a?(String)
73
- error[Constants::ERROR_HASH_FIELD] = Constants::REDIRECT_URL
74
+ raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
74
75
 
75
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
76
+ end
76
77
 
77
- error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
78
+ if !redirect_url.nil? && !redirect_url.is_a?(String)
79
+ error[Constants::ERROR_HASH_FIELD] = Constants::REDIRECT_URL
78
80
 
79
- raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
81
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
82
+
83
+ error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
84
+
85
+ raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
80
86
 
87
+ end
81
88
  end
82
89
 
83
90
  if !id.nil? && !id.is_a?(String)
@@ -91,15 +98,16 @@ module ZOHOCRMSDK
91
98
 
92
99
  end
93
100
 
94
- if grant_token.nil? && refresh_token.nil?
95
- error[Constants::ERROR_HASH_FIELD] = Constants::TYPE
101
+ if !access_token.nil? && !access_token.is_a?(String)
102
+ error[Constants::ERROR_HASH_FIELD] = Constants::ACCESS_TOKEN
96
103
 
97
- error[Constants::ERROR_HASH_EXPECTED_TYPE] = Constants::EXPECTED_TOKEN_TYPES
104
+ error[Constants::ERROR_HASH_EXPECTED_TYPE] = String
98
105
 
99
106
  error[Constants::ERROR_HASH_CLASS] = OAuthToken.class
100
107
 
101
108
  raise SDKException.new(Constants::INPUT_ERROR, nil, error, nil)
102
109
  end
110
+
103
111
  @client_id = client_id
104
112
 
105
113
  @client_secret = client_secret
@@ -110,7 +118,7 @@ module ZOHOCRMSDK
110
118
 
111
119
  @grant_token = grant_token
112
120
 
113
- @access_token = nil
121
+ @access_token = access_token
114
122
 
115
123
  @expires_in = nil
116
124
 
@@ -140,7 +148,7 @@ module ZOHOCRMSDK
140
148
 
141
149
  if oauth_token.nil?
142
150
  token = @refresh_token.nil? ? generate_access_token(user, store).access_token : refresh_access_token(user, store).access_token
143
- elsif oauth_token.expires_in.to_f - get_current_time_in_millis < 5000
151
+ elsif !oauth_token.expires_in.nil? && oauth_token.expires_in.to_f - get_current_time_in_millis < 5000
144
152
  SDKLog::SDKLogger.info(Constants::REFRESH_TOKEN_MESSAGE)
145
153
  token = oauth_token.refresh_access_token(user, store).access_token
146
154
  else
@@ -193,8 +201,6 @@ module ZOHOCRMSDK
193
201
 
194
202
  json_body[Constants::CLIENT_SECRET] = @client_secret
195
203
 
196
- json_body[Constants::REDIRECT_URI] = @redirect_url if !@redirect_url.nil?
197
-
198
204
  json_body[Constants::GRANT_TYPE] = Constants::REFRESH_TOKEN
199
205
 
200
206
  json_body[Constants::REFRESH_TOKEN] = @refresh_token
@@ -204,9 +210,11 @@ module ZOHOCRMSDK
204
210
  begin
205
211
  parse_response(response)
206
212
 
207
- generate_id()
213
+ if @id.nil?
214
+ generate_id()
215
+ end
208
216
 
209
- store.save_token(user,self)
217
+ store.save_token(user, self)
210
218
  rescue SDKException => e
211
219
  raise e
212
220
  rescue StandardError => e
@@ -268,7 +276,7 @@ module ZOHOCRMSDK
268
276
  id = ""
269
277
  email = Initializer.get_initializer.user.email
270
278
  environment = Initializer.get_initializer.environment.name
271
- id = id + "ruby_" +email[0..email.index(Constants::AT) - 1] + Constants::UNDERSCORE
279
+ id = id + (Constants::RUBY) + email[0..email.index(Constants::AT) - 1] + Constants::UNDERSCORE
272
280
  id = id + environment + Constants::UNDERSCORE + @refresh_token[@refresh_token.length-4..@refresh_token.length-1]
273
281
  @id = id
274
282
  end
@@ -8,7 +8,7 @@ module ZOHOCRMSDK
8
8
  # @param message A String containing the Exception error message.
9
9
  # @param details A hash containing the error response.
10
10
  # @param cause An Exception class instance.
11
- def initialize(code, message, details = nil, cause = nil)
11
+ def initialize(code:, message:, details: nil, cause: nil)
12
12
  @code = code
13
13
  @message = message
14
14
  @cause = cause
@@ -17,7 +17,7 @@ module ZOHOCRMSDK
17
17
  @@json_details
18
18
  end
19
19
 
20
- def self.initialize(user:, environment:, token:, store:, sdk_config:, resources_path:, log: nil, request_proxy: nil)
20
+ def self.initialize(user:, environment:, token:, store: nil, sdk_config: nil, resources_path: nil, log: nil, request_proxy: nil)
21
21
  error = {}
22
22
 
23
23
  require_relative 'user_signature'
@@ -55,7 +55,7 @@ module ZOHOCRMSDK
55
55
 
56
56
  require_relative '../../api/authenticator/store/token_store'
57
57
 
58
- unless store.is_a?(Store::TokenStore)
58
+ if !store.nil? && !store.is_a?(Store::TokenStore)
59
59
  error[Constants::ERROR_HASH_FIELD] = 'store'
60
60
 
61
61
  error[Constants::ERROR_HASH_EXPECTED_TYPE] = Store::TokenStore
@@ -66,7 +66,7 @@ module ZOHOCRMSDK
66
66
 
67
67
  require_relative 'sdk_config'
68
68
 
69
- unless sdk_config.is_a?(SDKConfig)
69
+ if !sdk_config.nil? && !sdk_config.is_a?(SDKConfig)
70
70
  error[Constants::ERROR_HASH_FIELD] = 'sdk_config'
71
71
 
72
72
  error[Constants::ERROR_HASH_EXPECTED_TYPE] = SDKConfig
@@ -75,20 +75,30 @@ module ZOHOCRMSDK
75
75
 
76
76
  end
77
77
 
78
- if !request_proxy.nil? && !sdk_config.is_a?(RequestProxy)
79
-
78
+ if !request_proxy.nil? && !request_proxy.is_a?(RequestProxy)
80
79
  raise SDKException.new(Constants::INITIALIZATION_ERROR, Constants::REQUEST_PROXY_ERROR, nil, nil)
81
80
  end
82
81
 
83
- if resources_path.nil? || resources_path.empty?
84
- raise SDKException.new(Constants::INITIALIZATION_ERROR, Constants::RESOURCE_PATH_ERROR_MESSAGE, nil, nil)
82
+ if store.nil?
83
+ require_relative '../../api/authenticator/store/file_store'
84
+
85
+ store = Store::FileStore.new(File.join(Dir.pwd, Constants::TOKEN_FILE))
86
+
87
+ end
88
+
89
+ if sdk_config.nil?
90
+ sdk_config = SDKConfig.new()
91
+ end
92
+
93
+ if resources_path.nil?
94
+ resources_path = Dir.pwd
85
95
  end
86
96
 
87
97
  if !File.directory?(resources_path)
88
98
  raise SDKException.new(Constants::INITIALIZATION_ERROR, Constants::RESOURCE_PATH_INVALID_ERROR_MESSAGE, nil, nil)
89
99
  end
90
100
 
91
- log = SDKLog::Log.initialize(level: Levels::INFO, path: File.join(Dir.pwd, Constants::LOGFILE_NAME)) if log.nil?
101
+ log = SDKLog::Log.initialize(level: Levels::INFO, path: File.join(Dir.pwd, Constants::LOG_FILE_NAME)) if log.nil?
92
102
  SDKLog::SDKLogger.initialize(log)
93
103
 
94
104
  @@initializer = Initializer.new
@@ -157,7 +157,7 @@ module ZOHOCRMSDK
157
157
 
158
158
  ZOHO_SDK = 'X-ZOHO-SDK'
159
159
 
160
- SDK_VERSION = '3.0.0'
160
+ SDK_VERSION = '4.0.0'
161
161
 
162
162
  ZOHO_API_VERSION = '2.0'
163
163
 
@@ -571,7 +571,9 @@ module ZOHOCRMSDK
571
571
 
572
572
  KEY_MODIFIED = 'key_modified'
573
573
 
574
- LOGFILE_NAME = 'SDKLogs.log'
574
+ LOG_FILE_NAME = 'sdk_logs.log'
575
+
576
+ TOKEN_FILE = "sdk_tokens.txt"
575
577
 
576
578
  INITIALIZATION_ERROR = 'INITIALIZATION ERROR'
577
579
 
@@ -635,5 +637,8 @@ module ZOHOCRMSDK
635
637
 
636
638
  SKIP_MODULES = ['deals']
637
639
 
640
+ RUBY = "ruby_"
641
+
642
+ OAUTH_MANDATORY_KEYS = ["grant_token", "refresh_token", "id", "access_token"]
638
643
  end
639
644
  end
data/src/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ZOHOCRMSDK
2
- VERSION = '3.0.0'
2
+ VERSION = '4.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZOHOCRMSDK2_0
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZOHO CRM API TEAM
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-24 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cgi