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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +70 -33
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +40 -76
- data/lib/ringcentral_sdk.rb +4 -3
- data/lib/ringcentral_sdk/rest.rb +18 -17
- data/lib/ringcentral_sdk/rest/cache.rb +9 -3
- data/lib/ringcentral_sdk/rest/cache/extensions.rb +91 -94
- data/lib/ringcentral_sdk/rest/client.rb +196 -202
- data/lib/ringcentral_sdk/rest/configuration.rb +91 -0
- data/lib/ringcentral_sdk/rest/event.rb +44 -43
- data/lib/ringcentral_sdk/rest/extension.rb +12 -9
- data/lib/ringcentral_sdk/rest/extension_presence.rb +73 -78
- data/lib/ringcentral_sdk/rest/messages.rb +40 -31
- data/lib/ringcentral_sdk/rest/messages_retriever.rb +30 -33
- data/lib/ringcentral_sdk/rest/request.rb +10 -5
- data/lib/ringcentral_sdk/rest/request/base.rb +24 -19
- data/lib/ringcentral_sdk/rest/request/fax.rb +88 -91
- data/lib/ringcentral_sdk/rest/request/inflator.rb +9 -2
- data/lib/ringcentral_sdk/rest/request/inflator/contact_info.rb +19 -12
- data/lib/ringcentral_sdk/rest/request/simple.rb +24 -34
- data/lib/ringcentral_sdk/rest/simple_client.rb +63 -78
- data/lib/ringcentral_sdk/rest/subscription.rb +223 -228
- data/test/test_base.rb +5 -5
- data/test/test_client.rb +87 -88
- data/test/test_event.rb +28 -11
- data/test/test_extension_presence.rb +64 -62
- data/test/test_helper_fax.rb +46 -47
- data/test/test_helper_inflator_contact_info.rb +8 -10
- data/test/test_helper_request.rb +1 -1
- data/test/test_setup.rb +24 -21
- data/test/test_subscription.rb +46 -48
- metadata +72 -33
- data/lib/ringcentral_sdk/rest/config.rb +0 -102
- data/test/test_config.rb +0 -29
@@ -1,123 +1,120 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'uri'
|
3
3
|
|
4
|
-
module RingCentralSdk
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@
|
21
|
+
|
22
|
+
def flush
|
23
|
+
@extensions_hash = {}
|
24
|
+
@extensions_num2id = {}
|
25
|
+
@last_retrieved = -1
|
40
26
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
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']
|
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
|
-
|
59
|
-
|
60
|
-
|
60
|
+
def retrieve_all
|
61
|
+
retrieve({}, true)
|
62
|
+
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
-
|
100
|
+
members = []
|
106
101
|
|
107
|
-
|
108
|
-
|
109
|
-
|
102
|
+
res = @client.http.get do |req|
|
103
|
+
req.url "account/#{account_id}/department/#{department_id}/members"
|
104
|
+
end
|
110
105
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
68
|
-
|
69
|
-
has_http = !url.index('http://').nil? && !url.index('https://').nil?
|
48
|
+
@messages = RingCentralSdk::REST::Messages.new self
|
49
|
+
end
|
70
50
|
|
71
|
-
|
72
|
-
|
51
|
+
def init_attributes
|
52
|
+
@http = nil
|
53
|
+
@user_agent = build_user_agent
|
73
54
|
end
|
74
55
|
|
75
|
-
|
76
|
-
|
56
|
+
def api_version_url
|
57
|
+
@config.server_url + URL_PREFIX + '/' + API_VERSION
|
77
58
|
end
|
78
59
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
86
|
-
if
|
87
|
-
built_url
|
88
|
-
|
89
|
-
|
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
|
-
|
94
|
-
|
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
|
-
|
97
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
118
|
-
|
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
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
131
|
+
unless token.is_a? OAuth2::AccessToken
|
132
|
+
raise 'Token is not a OAuth2::AccessToken'
|
133
|
+
end
|
135
134
|
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
141
|
-
|
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
|
-
|
146
|
-
|
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
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
|
169
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
192
|
-
|
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
|
-
|
199
|
-
method = 'get' if method.empty?
|
194
|
+
res = nil
|
200
195
|
|
201
|
-
|
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
|
-
|
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
|
-
|
217
|
-
|
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
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
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
|
-
|
230
|
-
|
231
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
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
|
-
|
246
|
-
|
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
|