ringcentral_sdk 1.3.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile.lock +70 -33
  4. data/{LICENSE.txt → LICENSE.md} +0 -0
  5. data/README.md +40 -76
  6. data/lib/ringcentral_sdk.rb +4 -3
  7. data/lib/ringcentral_sdk/rest.rb +18 -17
  8. data/lib/ringcentral_sdk/rest/cache.rb +9 -3
  9. data/lib/ringcentral_sdk/rest/cache/extensions.rb +91 -94
  10. data/lib/ringcentral_sdk/rest/client.rb +196 -202
  11. data/lib/ringcentral_sdk/rest/configuration.rb +91 -0
  12. data/lib/ringcentral_sdk/rest/event.rb +44 -43
  13. data/lib/ringcentral_sdk/rest/extension.rb +12 -9
  14. data/lib/ringcentral_sdk/rest/extension_presence.rb +73 -78
  15. data/lib/ringcentral_sdk/rest/messages.rb +40 -31
  16. data/lib/ringcentral_sdk/rest/messages_retriever.rb +30 -33
  17. data/lib/ringcentral_sdk/rest/request.rb +10 -5
  18. data/lib/ringcentral_sdk/rest/request/base.rb +24 -19
  19. data/lib/ringcentral_sdk/rest/request/fax.rb +88 -91
  20. data/lib/ringcentral_sdk/rest/request/inflator.rb +9 -2
  21. data/lib/ringcentral_sdk/rest/request/inflator/contact_info.rb +19 -12
  22. data/lib/ringcentral_sdk/rest/request/simple.rb +24 -34
  23. data/lib/ringcentral_sdk/rest/simple_client.rb +63 -78
  24. data/lib/ringcentral_sdk/rest/subscription.rb +223 -228
  25. data/test/test_base.rb +5 -5
  26. data/test/test_client.rb +87 -88
  27. data/test/test_event.rb +28 -11
  28. data/test/test_extension_presence.rb +64 -62
  29. data/test/test_helper_fax.rb +46 -47
  30. data/test/test_helper_inflator_contact_info.rb +8 -10
  31. data/test/test_helper_request.rb +1 -1
  32. data/test/test_setup.rb +24 -21
  33. data/test/test_subscription.rb +46 -48
  34. metadata +72 -33
  35. data/lib/ringcentral_sdk/rest/config.rb +0 -102
  36. data/test/test_config.rb +0 -29
@@ -1,123 +1,120 @@
1
1
  require 'time'
2
2
  require 'uri'
3
3
 
4
- module RingCentralSdk::REST::Cache
5
- class Extensions
6
- attr_accessor :client
7
- attr_accessor :account_id
8
- attr_reader :extensions_hash
9
- attr_reader :extensions_num2id
10
- attr_reader :last_retrieved
4
+ module RingCentralSdk
5
+ module REST
6
+ module Cache
7
+ # Extensions cache is a local store that can retrieve all
8
+ # extensions for use locally
9
+ class Extensions
10
+ attr_accessor :client
11
+ attr_accessor :account_id
12
+ attr_reader :extensions_hash
13
+ attr_reader :extensions_num2id
14
+ attr_reader :last_retrieved
11
15
 
12
- def initialize(client)
13
- @client = client
14
- @account_id = '~'
15
- flush()
16
- end
17
-
18
- def flush
19
- @extensions_hash = {}
20
- @extensions_num2id = {}
21
- @last_retrieved = -1
22
- end
23
-
24
- def retrieve(params={}, retrieve_all=true)
25
- @last_retrieved = Time.now.to_i
26
- uri = URI.parse "account/#{@account_id}/extension"
27
- if params.length > 0
28
- uri.query = URI.encode_www_form params
29
- end
30
- res = @client.http.get do |req|
31
- req.url uri.to_s
32
- if retrieve_all
33
- req.params['page'] = 1
34
- req.params['perPage'] = 1000
16
+ def initialize(client)
17
+ @client = client
18
+ @account_id = '~'
19
+ flush
35
20
  end
36
- end
37
- res.body['records'].each do |extension|
38
- if extension.key?('id') && extension['id'] > 0
39
- @extensions_hash[extension['id'].to_s] = extension
21
+
22
+ def flush
23
+ @extensions_hash = {}
24
+ @extensions_num2id = {}
25
+ @last_retrieved = -1
40
26
  end
41
- end
42
- if retrieve_all
43
- while res.body.key?('navigation') && res.body['navigation'].key?('nextPage')
27
+
28
+ def retrieve(params = {}, retrieve_all = true)
29
+ @last_retrieved = Time.now.to_i
30
+ uri = URI.parse "account/#{@account_id}/extension"
31
+ uri.query = URI.encode_www_form(params) unless params.empty?
44
32
  res = @client.http.get do |req|
45
- req.url res.body['navigation']['nextPage']['uri']
33
+ req.url uri.to_s
34
+ if retrieve_all
35
+ req.params['page'] = 1
36
+ req.params['perPage'] = 1000
37
+ end
46
38
  end
47
- res.body['records'].each do |extension|
39
+ load_extensions(res.body['records'])
40
+ if retrieve_all
41
+ while res.body.key?('navigation') && res.body['navigation'].key?('nextPage')
42
+ res = @client.http.get do |req|
43
+ req.url res.body['navigation']['nextPage']['uri']
44
+ end
45
+ load_extensions(res.body['records'])
46
+ end
47
+ end
48
+ inflate_num2id
49
+ @extensions_hash
50
+ end
51
+
52
+ def load_extensions(api_extensions)
53
+ api_extensions.each do |extension|
48
54
  if extension.key?('id') && extension['id'] > 0
49
55
  @extensions_hash[extension['id'].to_s] = extension
50
56
  end
51
57
  end
52
58
  end
53
- end
54
- inflate_num2id()
55
- return @extensions_hash
56
- end
57
59
 
58
- def retrieve_all()
59
- retrieve({}, true)
60
- end
60
+ def retrieve_all
61
+ retrieve({}, true)
62
+ end
61
63
 
62
- def inflate_num2id()
63
- num2id = {}
64
- @extensions_hash.each do |k,v|
65
- if v.key?('id') && v['id'] > 0 &&
66
- v.key?('extensionNumber') && v['extensionNumber'].length>0
67
- num2id[v['extensionNumber']] = v['id'].to_s
64
+ def inflate_num2id
65
+ num2id = {}
66
+ @extensions_hash.each do |_, v|
67
+ if v.key?('id') && v['id'] > 0 && v.key?('extensionNumber') && !v['extensionNumber'].empty?
68
+ num2id[v['extensionNumber']] = v['id'].to_s
69
+ end
70
+ end
71
+ @extensions_num2id = num2id
72
+ num2id
68
73
  end
69
- end
70
- @extensions_num2id = num2id
71
- return num2id
72
- end
73
74
 
74
- def get_extension_by_id(extension_id)
75
- if !extension_id.is_a?(String)
76
- extension_id = extension_id.to_s
77
- end
78
- if @extensions_hash.key? extension_id
79
- return @extensions_hash[extension_id]
80
- end
81
- return nil
82
- end
75
+ def get_extension_by_id(extension_id)
76
+ extension_id = extension_id.to_s unless extension_id.is_a? String
77
+ return @extensions_hash[extension_id] if @extensions_hash.key? extension_id
78
+ nil
79
+ end
83
80
 
84
- def get_extension_by_number(extension_number)
85
- if !extension_number.is_a?(String)
86
- extension_number = extension_number.to_s
87
- end
88
- if @extensions_num2id.key?(extension_number)
89
- extension_id = @extensions_num2id[extension_number]
90
- if @extensions_hash.key?(extension_id)
91
- return @extensions_hash[extension_id]
81
+ def get_extension_by_number(extension_number)
82
+ unless extension_number.is_a? String
83
+ extension_number = extension_number.to_s
84
+ end
85
+ if @extensions_num2id.key?(extension_number)
86
+ extension_id = @extensions_num2id[extension_number]
87
+ if @extensions_hash.key?(extension_id)
88
+ return @extensions_hash[extension_id]
89
+ end
90
+ end
91
+ nil
92
92
  end
93
- end
94
- return nil
95
- end
96
93
 
97
- def get_department_members(department_id)
98
- if !department_id.is_a?(String)
99
- department_id = department_id.to_s
100
- end
101
- if department_id !~ /^[0-9]+$/
102
- raise 'department_id parameter must be a positive integer'
103
- end
94
+ def get_department_members(department_id)
95
+ department_id = department_id.to_s unless department_id.is_a? String
96
+ if department_id !~ /^[0-9]+$/
97
+ raise 'department_id parameter must be a positive integer'
98
+ end
104
99
 
105
- members = []
100
+ members = []
106
101
 
107
- res = @client.http.get do |req|
108
- req.url "account/#{account_id}/department/#{department_id}/members"
109
- end
102
+ res = @client.http.get do |req|
103
+ req.url "account/#{account_id}/department/#{department_id}/members"
104
+ end
110
105
 
111
- if res.body.key? 'records'
112
- res.body['records'].each do |extension|
113
- if extension.key? 'id'
114
- member = get_extension_by_id extension['id']
115
- members.push member unless member.nil?
106
+ if res.body.key? 'records'
107
+ res.body['records'].each do |extension|
108
+ if extension.key? 'id'
109
+ member = get_extension_by_id extension['id']
110
+ members.push member unless member.nil?
111
+ end
112
+ end
116
113
  end
114
+
115
+ members
117
116
  end
118
117
  end
119
-
120
- return members
121
118
  end
122
119
  end
123
120
  end
@@ -2,252 +2,246 @@ require 'base64'
2
2
  require 'faraday'
3
3
  require 'faraday_middleware'
4
4
  require 'faraday_middleware/oauth2_refresh'
5
+ require 'faraday_middleware-request-retry'
6
+ require 'multi_json'
5
7
  require 'oauth2'
6
8
 
7
- require 'pp'
8
-
9
- module RingCentralSdk::REST
10
- class Client
11
- ACCESS_TOKEN_TTL = 600 # 10 minutes
12
- REFRESH_TOKEN_TTL = 36000 # 10 hours
13
- REFRESH_TOKEN_TTL_REMEMBER = 604800 # 1 week
14
- ACCOUNT_PREFIX = '/account/'
15
- ACCOUNT_ID = '~'
16
- AUTHZ_ENDPOINT = '/restapi/oauth/authorize'
17
- TOKEN_ENDPOINT = '/restapi/oauth/token'
18
- REVOKE_ENDPOINT = '/restapi/oauth/revoke'
19
- API_VERSION = 'v1.0'
20
- URL_PREFIX = '/restapi'
21
- DEFAULT_LANGUAGE = 'en-us'
22
-
23
- attr_reader :app_config
24
- attr_reader :http
25
- attr_reader :logger
26
- attr_reader :oauth2client
27
- attr_reader :user_agent
28
- attr_reader :messages
29
-
30
- attr_reader :instance_headers
31
-
32
- def initialize(app_key='', app_secret='', server_url=RingCentralSdk::RC_SERVER_SANDBOX, opts={})
33
- init_attributes()
34
- self.set_app_config( RingCentralSdk::REST::ConfigApp.new(
35
- app_key, app_secret, server_url, opts) )
36
-
37
- if opts.key?(:username) && opts.key?(:password)
38
- extension = opts.key?(:extension) ? opts[:extension] : ''
39
- authorize_password(opts[:username], extension, opts[:password])
40
- end
41
-
42
- @instance_headers = opts[:headers] || {}
43
- if opts.key? :logger
44
- @logger = opts[:logger]
45
- else
46
- @logger = Logger.new(STDOUT)
47
- @logger.level = :info
48
- end
49
-
50
- @messages = RingCentralSdk::REST::Messages.new self
51
- end
52
-
53
- def set_app_config(new_app_config)
54
- @app_config = new_app_config
55
- @oauth2client = new_oauth2_client()
56
- end
57
-
58
- def init_attributes()
59
- @http = nil
60
- @user_agent = get_user_agent()
61
- end
62
-
63
- def api_version_url()
64
- return @app_config.server_url + URL_PREFIX + '/' + API_VERSION
65
- end
9
+ module RingCentralSdk
10
+ module REST
11
+ # Client is the RingCentral REST API client class which handles
12
+ # HTTP requests with built-in OAuth handling
13
+ class Client
14
+ ACCESS_TOKEN_TTL = 600 # 10 minutes
15
+ REFRESH_TOKEN_TTL = 36_000 # 10 hours
16
+ REFRESH_TOKEN_TTL_REMEMBER = 604_800 # 1 week
17
+ ACCOUNT_PREFIX = '/account/'.freeze
18
+ ACCOUNT_ID = '~'.freeze
19
+ AUTHZ_ENDPOINT = '/restapi/oauth/authorize'.freeze
20
+ TOKEN_ENDPOINT = '/restapi/oauth/token'.freeze
21
+ REVOKE_ENDPOINT = '/restapi/oauth/revoke'.freeze
22
+ API_VERSION = 'v1.0'.freeze
23
+ URL_PREFIX = '/restapi'.freeze
24
+ DEFAULT_LANGUAGE = 'en-us'.freeze
25
+
26
+ attr_reader :config
27
+ attr_reader :http
28
+ attr_reader :logger
29
+ attr_reader :oauth2client
30
+ attr_reader :user_agent
31
+ attr_reader :messages
32
+
33
+ def initialize
34
+ init_attributes
35
+
36
+ raise ArgumentError, 'Config block not given' unless block_given?
37
+ @config = RingCentralSdk::REST::Configuration.new
38
+ yield config
39
+ @config.inflate
40
+
41
+ @logger = @config.logger
42
+ @oauth2client = new_oauth2_client
43
+
44
+ unless @config.username.to_s.empty?
45
+ authorize_password @config.username, @config.extension, @config.password
46
+ end
66
47
 
67
- def create_url(url, add_server=false, add_method=nil, add_token=false)
68
- built_url = ''
69
- has_http = !url.index('http://').nil? && !url.index('https://').nil?
48
+ @messages = RingCentralSdk::REST::Messages.new self
49
+ end
70
50
 
71
- if add_server && ! has_http
72
- built_url += @app_config.server_url
51
+ def init_attributes
52
+ @http = nil
53
+ @user_agent = build_user_agent
73
54
  end
74
55
 
75
- if url.index(URL_PREFIX).nil? && ! has_http
76
- built_url += URL_PREFIX + '/' + API_VERSION + '/'
56
+ def api_version_url
57
+ @config.server_url + URL_PREFIX + '/' + API_VERSION
77
58
  end
78
59
 
79
- if url.index('/') == 0
80
- if built_url =~ /\/$/
81
- built_url += url.gsub(/^\//, '')
82
- else
83
- built_url += url
60
+ def create_url(url, add_server = false, add_method = nil, add_token = false)
61
+ built_url = ''
62
+ has_http = !url.index('http://').nil? && !url.index('https://').nil?
63
+
64
+ built_url += @config.server_url if add_server && !has_http
65
+
66
+ if url.index(URL_PREFIX).nil? && !has_http
67
+ built_url += URL_PREFIX + '/' + API_VERSION + '/'
84
68
  end
85
- else # no /
86
- if built_url =~ /\/$/
87
- built_url += url
88
- else
89
- built_url += '/' + url
69
+
70
+ if url.index('/') == 0
71
+ if built_url =~ %r{/$}
72
+ built_url += url.gsub(%r{^/+}, '')
73
+ else
74
+ built_url += url
75
+ end
76
+ else # no /
77
+ if built_url =~ %r{/$}
78
+ built_url += url
79
+ else
80
+ built_url += '/' << url
81
+ end
90
82
  end
83
+
84
+ built_url
91
85
  end
92
86
 
93
- return built_url
94
- end
87
+ def create_urls(urls, add_server = false, add_method = nil, add_token = false)
88
+ raise(ArgumentError, 'URLs is not an array') unless urls.is_a? Array
89
+ built_urls = []
90
+ urls.each do |url|
91
+ built_urls.push(create_url(url, add_server, add_method, add_token))
92
+ end
93
+ built_urls
94
+ end
95
95
 
96
- def create_urls(urls, add_server=false, add_method=nil, add_token=false)
97
- unless urls.is_a?(Array)
98
- raise "URLs is not an array"
96
+ def authorize_url(opts = {})
97
+ @oauth2client.auth_code.authorize_url(_add_redirect_uri(opts))
99
98
  end
100
- built_urls = []
101
- urls.each do |url|
102
- built_urls.push(create_url(url, add_server, add_method, add_token))
99
+
100
+ def authorize_code(code, params = {})
101
+ token = @oauth2client.auth_code.get_token(code, _add_redirect_uri(params))
102
+ set_token(token)
103
+ token
103
104
  end
104
- return built_urls
105
- end
106
105
 
107
- def authorize_url(opts = {})
108
- @oauth2client.auth_code.authorize_url(_add_redirect_uri(opts))
109
- end
106
+ def _add_redirect_uri(opts = {})
107
+ if !opts.key?(:redirect_uri) && !@config.redirect_url.to_s.empty?
108
+ opts[:redirect_uri] = @config.redirect_url.to_s
109
+ end
110
+ opts
111
+ end
110
112
 
111
- def authorize_code(code, params = {})
112
- token = @oauth2client.auth_code.get_token(code, _add_redirect_uri(params))
113
- set_token(token)
114
- return token
115
- end
113
+ def authorize_password(username, extension = '', password = '', params = {})
114
+ token = @oauth2client.password.get_token(username, password, {
115
+ extension: extension,
116
+ headers: { 'Authorization' => 'Basic ' + api_key }
117
+ }.merge(params))
118
+ set_token token
119
+ token
120
+ end
116
121
 
117
- def _add_redirect_uri(opts = {})
118
- if !opts.key?(:redirect_uri) && @app_config.redirect_url.to_s.length > 0
119
- opts[:redirect_uri] = @app_config.redirect_url.to_s
122
+ def token
123
+ @http ? @http.builder.app.oauth2_token : nil
120
124
  end
121
- return opts
122
- end
123
125
 
124
- def authorize_password(username, extension = '', password = '', params = {})
125
- token = @oauth2client.password.get_token(username, password, {
126
- extension: extension,
127
- headers: {'Authorization' => 'Basic ' + get_api_key()}}.merge(params))
128
- set_token(token)
129
- return token
130
- end
126
+ def set_token(token)
127
+ if token.is_a? Hash
128
+ token = OAuth2::AccessToken.from_hash(@oauth2client, token)
129
+ end
131
130
 
132
- def authorize_user(user, params = {})
133
- authorize_password(user.username, user.extension, user.password, params)
134
- end
131
+ unless token.is_a? OAuth2::AccessToken
132
+ raise 'Token is not a OAuth2::AccessToken'
133
+ end
135
134
 
136
- def token
137
- return @http ? @http.builder.app.oauth2_token : nil
138
- end
135
+ @http = Faraday.new(url: api_version_url) do |conn|
136
+ conn.request :oauth2_refresh, token
137
+ conn.request :multipart
138
+ conn.request :url_encoded
139
+ conn.request :json
140
+ conn.headers['User-Agent'] = @user_agent
141
+ if @config.headers.is_a? Hash
142
+ @config.headers.each do |k, v|
143
+ conn.headers[k] = v
144
+ end
145
+ end
146
+ conn.headers['RC-User-Agent'] = @user_agent
147
+ conn.headers['SDK-User-Agent'] = @user_agent
148
+ conn.response :json, content_type: /\bjson$/
149
+ conn.response :logger, @config.logger
150
+ if @config.retry
151
+ conn.use FaradayMiddleware::Request::Retry, @config.retry_options
152
+ end
153
+ conn.adapter Faraday.default_adapter
154
+ end
139
155
 
140
- def set_token(token)
141
- if token.is_a? Hash
142
- token = OAuth2::AccessToken::from_hash(@oauth2client, token)
156
+ token_string = MultiJson.encode token.to_hash
157
+ @config.logger.info("SET_TOKEN: #{token_string}")
143
158
  end
144
159
 
145
- unless token.is_a? OAuth2::AccessToken
146
- raise "Token is not a OAuth2::AccessToken"
160
+ def new_oauth2_client
161
+ OAuth2::Client.new(
162
+ @config.app_key,
163
+ @config.app_secret,
164
+ site: @config.server_url,
165
+ authorize_url: AUTHZ_ENDPOINT,
166
+ token_url: TOKEN_ENDPOINT
167
+ )
147
168
  end
148
169
 
149
- @http = Faraday.new(url: api_version_url()) do |conn|
150
- conn.request :oauth2_refresh, token
151
- conn.request :multipart
152
- conn.request :url_encoded
153
- conn.request :json
154
- conn.headers['User-Agent'] = @user_agent
155
- if @instance_headers.is_a? Hash
156
- @instance_headers.each do |k,v|
157
- conn.headers[k] = v
158
- end
170
+ def set_oauth2_client(client = nil)
171
+ if client.nil?
172
+ @oauth2client = new_oauth2_client
173
+ elsif client.is_a? OAuth2::Client
174
+ @oauth2client = client
175
+ else
176
+ raise ArgumentError, 'client is not an OAuth2::Client'
159
177
  end
160
- conn.headers['RC-User-Agent'] = @user_agent
161
- conn.headers['SDK-User-Agent'] = @user_agent
162
- conn.response :json, content_type: /\bjson$/
163
- conn.response :logger
164
- conn.adapter Faraday.default_adapter
165
178
  end
166
- end
167
179
 
168
- def new_oauth2_client()
169
- return OAuth2::Client.new(@app_config.key, @app_config.secret,
170
- site: @app_config.server_url,
171
- authorize_url: AUTHZ_ENDPOINT,
172
- token_url: TOKEN_ENDPOINT)
173
- end
174
-
175
- def set_oauth2_client(client=nil)
176
- if client.nil?
177
- @oauth2client = new_oauth2_client()
178
- elsif client.is_a? OAuth2::Client
179
- @oauth2client = client
180
- else
181
- fail "client is not an OAuth2::Client"
180
+ def api_key
181
+ Base64.encode64("#{@config.app_key}:#{@config.app_secret}").gsub(/\s/, '')
182
182
  end
183
- end
184
183
 
185
- def get_api_key()
186
- api_key = (@app_config.key.is_a?(String) && @app_config.secret.is_a?(String)) \
187
- ? Base64.encode64("#{@app_config.key}:#{@app_config.secret}").gsub(/\s/,'') : ''
188
- return api_key
189
- end
184
+ def send_request(request_sdk = {})
185
+ if request_sdk.is_a? Hash
186
+ request_sdk = RingCentralSdk::REST::Request::Simple.new request_sdk
187
+ elsif !request_sdk.is_a? RingCentralSdk::REST::Request::Base
188
+ raise ArgumentError, 'Request is not a RingCentralSdk::REST::Request::Base'
189
+ end
190
190
 
191
- def send_request(request_sdk = {})
192
- if request_sdk.is_a? Hash
193
- request_sdk = RingCentralSdk::REST::Request::Simple.new(request_sdk)
194
- elsif !request_sdk.is_a? RingCentralSdk::REST::Request::Base
195
- fail 'Request is not a RingCentralSdk::REST::Request::Base'
196
- end
191
+ method = request_sdk.method.to_s.downcase
192
+ method = 'get' if method.empty?
197
193
 
198
- method = request_sdk.method.to_s.downcase
199
- method = 'get' if method.empty?
194
+ res = nil
200
195
 
201
- res = nil
196
+ case method
197
+ when 'delete'
198
+ res = @http.delete { |req| req = inflate_request(req, request_sdk) }
199
+ when 'get'
200
+ res = @http.get { |req| req = inflate_request(req, request_sdk) }
201
+ when 'post'
202
+ res = @http.post { |req| req = inflate_request(req, request_sdk) }
203
+ when 'put'
204
+ res = @http.put { |req| req = inflate_request(req, request_sdk) }
205
+ else
206
+ raise "method [#{method}] not supported"
207
+ end
202
208
 
203
- case method
204
- when 'delete'
205
- res = @http.delete { |req| req = inflate_request(req, request_sdk) }
206
- when 'get'
207
- res = @http.get { |req| req = inflate_request(req, request_sdk) }
208
- when 'post'
209
- res = @http.post { |req| req = inflate_request(req, request_sdk) }
210
- when 'put'
211
- res = @http.put { |req| req = inflate_request(req, request_sdk) }
212
- else
213
- fail "method [#{method}] not supported"
209
+ res
214
210
  end
215
211
 
216
- return res
217
- end
212
+ def inflate_request(req_faraday, req_sdk)
213
+ req_faraday.url req_sdk.url
214
+ req_faraday.body = req_sdk.body if req_sdk.body
215
+ if req_sdk.params.is_a? Hash
216
+ req_sdk.params.each { |k, v| req_faraday.params[k] = v }
217
+ end
218
+ if req_sdk.headers.is_a? Hash
219
+ req_sdk.headers.each { |k, v| req_faraday.headers[k] = v }
220
+ end
218
221
 
219
- def inflate_request(req_faraday, req_sdk)
220
- req_faraday.url req_sdk.url
221
- req_faraday.body = req_sdk.body if req_sdk.body
222
- if req_sdk.params.is_a? Hash
223
- req_sdk.params.each { |k,v| req_faraday.params[k] = v }
224
- end
225
- if req_sdk.headers.is_a? Hash
226
- req_sdk.headers.each { |k,v| req_faraday.headers[k] = v }
222
+ ct = req_sdk.content_type
223
+ if !ct.nil? && !ct.to_s.strip.empty?
224
+ req_faraday.headers['Content-Type'] = ct.to_s
225
+ end
226
+ req_faraday
227
227
  end
228
228
 
229
- ct = req_sdk.content_type
230
- if !ct.nil? && ct.to_s.length > 0
231
- req_faraday.headers['Content-Type'] = ct.to_s
229
+ def build_user_agent
230
+ ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
231
+ (RUBY_ENGINE rescue nil || 'ruby'),
232
+ RUBY_VERSION,
233
+ RUBY_PLATFORM
234
+ ]
235
+ ua.strip
232
236
  end
233
- return req_faraday
234
- end
235
237
 
236
- def get_user_agent()
237
- ua = "ringcentral-sdk-ruby/#{RingCentralSdk::VERSION} %s/%s %s" % [
238
- (RUBY_ENGINE rescue nil or "ruby"),
239
- RUBY_VERSION,
240
- RUBY_PLATFORM
241
- ]
242
- return ua.strip
243
- end
238
+ def create_subscription
239
+ RingCentralSdk::REST::Subscription.new self
240
+ end
244
241
 
245
- def create_subscription()
246
- return RingCentralSdk::REST::Subscription.new(self)
242
+ alias authorize authorize_password
243
+ alias login authorize_password
244
+ private :api_version_url
247
245
  end
248
-
249
- alias_method :authorize, :authorize_password
250
- alias_method :login, :authorize_password
251
- private :api_version_url
252
246
  end
253
247
  end