ringcentral_sdk 0.5.2 → 1.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +96 -0
- data/README.md +66 -92
- data/Rakefile +3 -3
- data/lib/ringcentral_sdk/{cache → rest/cache}/extensions.rb +17 -19
- data/lib/ringcentral_sdk/rest/cache.rb +3 -0
- data/lib/ringcentral_sdk/{platform.rb → rest/client.rb} +61 -55
- data/lib/ringcentral_sdk/rest/config.rb +93 -0
- data/lib/ringcentral_sdk/rest/extension.rb +12 -0
- data/lib/ringcentral_sdk/rest/extension_presence.rb +104 -0
- data/lib/ringcentral_sdk/rest/messages.rb +46 -0
- data/lib/ringcentral_sdk/{helpers/request.rb → rest/request/base.rb} +2 -2
- data/lib/ringcentral_sdk/rest/request/fax.rb +121 -0
- data/lib/ringcentral_sdk/{helpers → rest/request}/inflator/contact_info.rb +1 -1
- data/lib/ringcentral_sdk/rest/request/inflator.rb +3 -0
- data/lib/ringcentral_sdk/rest/request.rb +5 -0
- data/lib/ringcentral_sdk/{simple.rb → rest/simple_client.rb} +10 -10
- data/lib/ringcentral_sdk/{subscription.rb → rest/subscription.rb} +8 -8
- data/lib/ringcentral_sdk/rest.rb +15 -0
- data/lib/ringcentral_sdk.rb +3 -7
- data/mkdocs.yml +30 -0
- data/ringcentral_sdk-0.5.2.gem +0 -0
- data/ringcentral_sdk.gemspec +31 -0
- data/test/{test_helper.rb → test_base.rb} +3 -3
- data/test/{test_platform.rb → test_client.rb} +58 -28
- data/test/test_config.rb +29 -0
- data/test/test_extension_presence.rb +154 -0
- data/test/test_helper_fax.rb +42 -39
- data/test/test_helper_inflator_contact_info.rb +3 -3
- data/test/test_helper_request.rb +3 -4
- data/test/test_setup.rb +4 -4
- data/test/test_subscription.rb +9 -9
- metadata +95 -48
- data/lib/ringcentral_sdk/cache.rb +0 -3
- data/lib/ringcentral_sdk/helpers/extension_presence.rb +0 -129
- data/lib/ringcentral_sdk/helpers/fax.rb +0 -160
- data/lib/ringcentral_sdk/helpers/inflator.rb +0 -3
- data/lib/ringcentral_sdk/helpers/messages.rb +0 -19
- data/lib/ringcentral_sdk/helpers.rb +0 -7
@@ -4,8 +4,8 @@ require 'faraday_middleware'
|
|
4
4
|
require 'faraday_middleware/oauth2_refresh'
|
5
5
|
require 'oauth2'
|
6
6
|
|
7
|
-
module RingCentralSdk
|
8
|
-
class
|
7
|
+
module RingCentralSdk::REST
|
8
|
+
class Client
|
9
9
|
|
10
10
|
ACCESS_TOKEN_TTL = 600 # 10 minutes
|
11
11
|
REFRESH_TOKEN_TTL = 36000 # 10 hours
|
@@ -18,37 +18,39 @@ module RingCentralSdk
|
|
18
18
|
API_VERSION = 'v1.0'
|
19
19
|
URL_PREFIX = '/restapi'
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
attr_reader
|
24
|
-
attr_reader
|
25
|
-
attr_reader
|
26
|
-
attr_reader
|
27
|
-
|
21
|
+
attr_reader :app_config
|
22
|
+
attr_reader :http
|
23
|
+
attr_reader :oauth2client
|
24
|
+
attr_reader :token
|
25
|
+
attr_reader :user_agent
|
26
|
+
attr_reader :messages
|
27
|
+
|
28
|
+
def initialize(app_key='', app_secret='', server_url=RingCentralSdk::RC_SERVER_SANDBOX, opts={})
|
29
|
+
init_attributes()
|
30
|
+
app_config = RingCentralSdk::REST::ConfigApp.new(app_key, app_secret, server_url, opts)
|
31
|
+
app_config(app_config)
|
32
|
+
|
33
|
+
if opts.key?(:username) && opts.key?(:password)
|
34
|
+
extension = opts.key?(:extension) ? opts[:extension] : ''
|
35
|
+
authorize_password(opts[:username], extension, opts[:password])
|
36
|
+
end
|
28
37
|
|
29
|
-
|
38
|
+
@messages = RingCentralSdk::REST::Messages.new(self)
|
39
|
+
end
|
30
40
|
|
31
|
-
def
|
32
|
-
@
|
33
|
-
@app_secret = app_secret.to_s
|
34
|
-
@server_url = server_url
|
35
|
-
@token = nil
|
36
|
-
@client = nil
|
37
|
-
@redirect_uri = ''
|
38
|
-
@user_agent = get_user_agent()
|
41
|
+
def app_config(app_config)
|
42
|
+
@app_config = app_config
|
39
43
|
@oauth2client = new_oauth2_client()
|
40
|
-
if opts.is_a?(Hash)
|
41
|
-
@redirect_uri = opts.has_key?(:redirect_uri) ? opts[:redirect_uri] : ''
|
42
|
-
if opts.has_key?(:username) && opts.has_key?(:password)
|
43
|
-
extension = opts.has_key?(:extension) ? opts[:extension] : ''
|
44
|
-
authorize_password(opts[:username], extension, opts[:password])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
@messages = RingCentralSdk::Helpers::Messages.new(self)
|
48
44
|
end
|
49
45
|
|
50
|
-
def
|
51
|
-
|
46
|
+
def init_attributes()
|
47
|
+
@token = nil
|
48
|
+
@http = nil
|
49
|
+
@user_agent = get_user_agent()
|
50
|
+
end
|
51
|
+
|
52
|
+
def api_version_url()
|
53
|
+
return @app_config.server_url + URL_PREFIX + '/' + API_VERSION
|
52
54
|
end
|
53
55
|
|
54
56
|
def create_url(url, add_server=false, add_method=nil, add_token=false)
|
@@ -56,7 +58,7 @@ module RingCentralSdk
|
|
56
58
|
has_http = !url.index('http://').nil? && !url.index('https://').nil?
|
57
59
|
|
58
60
|
if add_server && ! has_http
|
59
|
-
built_url += @server_url
|
61
|
+
built_url += @app_config.server_url
|
60
62
|
end
|
61
63
|
|
62
64
|
if url.index(URL_PREFIX).nil? && ! has_http
|
@@ -92,21 +94,22 @@ module RingCentralSdk
|
|
92
94
|
end
|
93
95
|
|
94
96
|
def authorize_url(opts={})
|
95
|
-
|
96
|
-
opts[:redirect_uri] = @redirect_uri.to_s
|
97
|
-
end
|
98
|
-
@oauth2client.auth_code.authorize_url(opts)
|
97
|
+
@oauth2client.auth_code.authorize_url(_add_redirect_uri(opts))
|
99
98
|
end
|
100
99
|
|
101
100
|
def authorize_code(code, opts={})
|
102
|
-
|
103
|
-
opts[:redirect_uri] = @redirect_uri.to_s
|
104
|
-
end
|
105
|
-
token = @oauth2client.auth_code.get_token(code, opts)
|
101
|
+
token = @oauth2client.auth_code.get_token(code, _add_redirect_uri(opts))
|
106
102
|
set_token(token)
|
107
103
|
return token
|
108
104
|
end
|
109
105
|
|
106
|
+
def _add_redirect_uri(opts={})
|
107
|
+
if !opts.key?(:redirect_uri) && @app_config.redirect_url.to_s.length > 0
|
108
|
+
opts[:redirect_uri] = @app_config.redirect_url.to_s
|
109
|
+
end
|
110
|
+
return opts
|
111
|
+
end
|
112
|
+
|
110
113
|
def authorize_password(username, extension='', password='', remember=false)
|
111
114
|
token = @oauth2client.password.get_token(username, password, {
|
112
115
|
:extension => extension,
|
@@ -115,6 +118,10 @@ module RingCentralSdk
|
|
115
118
|
return token
|
116
119
|
end
|
117
120
|
|
121
|
+
def authorize_user(user, remember=false)
|
122
|
+
authorize_password(user.username, user.extension, user.password)
|
123
|
+
end
|
124
|
+
|
118
125
|
def set_token(token)
|
119
126
|
if token.is_a?(Hash)
|
120
127
|
token = OAuth2::AccessToken::from_hash(@oauth2client, token)
|
@@ -124,9 +131,9 @@ module RingCentralSdk
|
|
124
131
|
raise "Token is not a OAuth2::AccessToken"
|
125
132
|
end
|
126
133
|
|
127
|
-
@token
|
134
|
+
@token = token
|
128
135
|
|
129
|
-
@
|
136
|
+
@http = Faraday.new(:url => api_version_url()) do |conn|
|
130
137
|
conn.request :oauth2_refresh, @token
|
131
138
|
conn.request :json
|
132
139
|
conn.request :url_encoded
|
@@ -138,8 +145,8 @@ module RingCentralSdk
|
|
138
145
|
end
|
139
146
|
|
140
147
|
def new_oauth2_client()
|
141
|
-
return OAuth2::Client.new(@
|
142
|
-
:site => @server_url,
|
148
|
+
return OAuth2::Client.new(@app_config.key, @app_config.secret,
|
149
|
+
:site => @app_config.server_url,
|
143
150
|
:authorize_url => AUTHZ_ENDPOINT,
|
144
151
|
:token_url => TOKEN_ENDPOINT)
|
145
152
|
end
|
@@ -150,26 +157,26 @@ module RingCentralSdk
|
|
150
157
|
elsif client.is_a?(OAuth2::Client)
|
151
158
|
@oauth2client = client
|
152
159
|
else
|
153
|
-
|
160
|
+
fail "client is not an OAuth2::Client"
|
154
161
|
end
|
155
162
|
end
|
156
163
|
|
157
164
|
def get_api_key()
|
158
|
-
api_key = (@
|
159
|
-
? Base64.encode64("#{@
|
165
|
+
api_key = (@app_config.key.is_a?(String) && @app_config.secret.is_a?(String)) \
|
166
|
+
? Base64.encode64("#{@app_config.key}:#{@app_config.secret}").gsub(/[\s\t\r\n]/,'') : ''
|
160
167
|
return api_key
|
161
168
|
end
|
162
169
|
|
163
|
-
def send_request(
|
164
|
-
unless
|
165
|
-
|
170
|
+
def send_request(request=nil)
|
171
|
+
unless request.is_a?(RingCentralSdk::REST::Request::Base)
|
172
|
+
fail 'Request is not a RingCentralSdk::REST::Request::Base'
|
166
173
|
end
|
167
174
|
|
168
|
-
if
|
169
|
-
resp = @
|
170
|
-
req.url
|
171
|
-
req.headers['Content-Type'] =
|
172
|
-
req.body =
|
175
|
+
if request.method.downcase == 'post'
|
176
|
+
resp = @http.post do |req|
|
177
|
+
req.url request.url
|
178
|
+
req.headers['Content-Type'] = request.content_type if request.content_type
|
179
|
+
req.body = request.body if request.body
|
173
180
|
end
|
174
181
|
return resp
|
175
182
|
end
|
@@ -185,12 +192,11 @@ module RingCentralSdk
|
|
185
192
|
end
|
186
193
|
|
187
194
|
def create_subscription()
|
188
|
-
return RingCentralSdk::Subscription.new(self)
|
195
|
+
return RingCentralSdk::REST::Subscription.new(self)
|
189
196
|
end
|
190
197
|
|
191
198
|
alias_method :authorize, :authorize_password
|
192
199
|
alias_method :login, :authorize_password
|
193
|
-
|
194
|
-
private :get_api_version_url
|
200
|
+
private :api_version_url
|
195
201
|
end
|
196
202
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
|
3
|
+
module RingCentralSdk::REST
|
4
|
+
class Config
|
5
|
+
attr_accessor :user
|
6
|
+
attr_accessor :app
|
7
|
+
attr_accessor :env
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@app = RingCentralSdk::REST::ConfigApp.new
|
11
|
+
@user = RingCentralSdk::REST::ConfigUser.new
|
12
|
+
@env = RingCentralSdk::REST::ConfigEnvRc.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_dotenv
|
16
|
+
Dotenv.load
|
17
|
+
@app.load_env()
|
18
|
+
@user.load_env()
|
19
|
+
@env.load_env()
|
20
|
+
return self
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module RingCentralSdk::REST
|
26
|
+
class ConfigUser
|
27
|
+
attr_accessor :username
|
28
|
+
attr_accessor :extension
|
29
|
+
attr_accessor :password
|
30
|
+
|
31
|
+
def load_env
|
32
|
+
@username = ENV['RC_USER_USERNAME']
|
33
|
+
@extension = ENV['RC_USER_EXTENSION']
|
34
|
+
@password = ENV['RC_USER_PASSWORD']
|
35
|
+
end
|
36
|
+
|
37
|
+
def nilify
|
38
|
+
@username = ''
|
39
|
+
@extension = ''
|
40
|
+
@password = ''
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module RingCentralSdk::REST
|
46
|
+
class ConfigApp
|
47
|
+
attr_accessor :key
|
48
|
+
attr_accessor :secret
|
49
|
+
attr_accessor :server_url
|
50
|
+
attr_accessor :redirect_url
|
51
|
+
|
52
|
+
def initialize(app_key='', app_secret='', server_url=RingCentralSdk::RC_SERVER_SANDBOX, opts={})
|
53
|
+
@key = app_key
|
54
|
+
@secret = app_secret
|
55
|
+
@server_url = server_url
|
56
|
+
if opts.key?(:redirect_url)
|
57
|
+
@redirect_url = opts[:redirect_url]
|
58
|
+
elsif opts.key?(:redirect_uri)
|
59
|
+
@redirect_url = opts[:redirect_uri]
|
60
|
+
else
|
61
|
+
@redirect_url = ''
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_env
|
66
|
+
['RC_APP_KEY', 'RC_APP_SECRET', 'RC_APP_SERVER_URL', 'RC_APP_REDIRECT_URL'].each do |var|
|
67
|
+
if !ENV.key?(var)
|
68
|
+
fail "environment variable '#{var}' not found"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@key = ENV['RC_APP_KEY']
|
73
|
+
@secret = ENV['RC_APP_SECRET']
|
74
|
+
@server_url = ENV['RC_APP_SERVER_URL']
|
75
|
+
@redirect_url = ENV['RC_APP_REDIRECT_URL']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
module RingCentralSdk::REST
|
81
|
+
class ConfigEnvRc
|
82
|
+
attr_accessor :data
|
83
|
+
def initialize
|
84
|
+
@data = {}
|
85
|
+
end
|
86
|
+
def load_env
|
87
|
+
ENV.each do |k,v|
|
88
|
+
next unless k.index('RC_') == 0
|
89
|
+
@data[k] = v
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RingCentralSdk::REST
|
2
|
+
class Extension
|
3
|
+
attr_reader :extension_id
|
4
|
+
attr_reader :presence
|
5
|
+
attr_accessor :client
|
6
|
+
def initialize(extension_id, opts={})
|
7
|
+
@extension_id = extension_id
|
8
|
+
@client = opts.has_key?(:client) ? opts[:client] : nil
|
9
|
+
@presence = RingCentralSdk::REST::ExtensionPresence.new(extension_id, opts)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module RingCentralSdk::REST
|
2
|
+
class ExtensionPresence
|
3
|
+
attr_accessor :client
|
4
|
+
attr_accessor :account_id
|
5
|
+
attr_accessor :extension_id
|
6
|
+
attr_accessor :presence_data
|
7
|
+
|
8
|
+
def initialize(extension_id, opts={})
|
9
|
+
@client = opts.key?(:client) ? opts[:client] : nil
|
10
|
+
@account_id = '~'
|
11
|
+
@extension_id = extension_id.to_s
|
12
|
+
@presence_data = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve()
|
16
|
+
if @extension_id !~ /^[0-9]+$/
|
17
|
+
raise "extension_id is not an integer"
|
18
|
+
end
|
19
|
+
|
20
|
+
res = @client.http.get do |req|
|
21
|
+
req.url "account/#{@account_id}/extension/#{@extension_id}/presence"
|
22
|
+
end
|
23
|
+
|
24
|
+
@presence_data = res.body
|
25
|
+
|
26
|
+
return @presence_data
|
27
|
+
end
|
28
|
+
|
29
|
+
def department_calls_enable(enable)
|
30
|
+
retrieve()
|
31
|
+
|
32
|
+
if !@presence_data.key?('dndStatus')
|
33
|
+
raise 'invalid presence info'
|
34
|
+
end
|
35
|
+
|
36
|
+
current_status = @presence_data['dndStatus']
|
37
|
+
new_status = new_status_dnd_department_calls(current_status, enable)
|
38
|
+
|
39
|
+
if current_status != new_status
|
40
|
+
update({:dndStatus => new_status})
|
41
|
+
end
|
42
|
+
|
43
|
+
return new_status
|
44
|
+
end
|
45
|
+
|
46
|
+
def department_calls_enabled?(reload=false)
|
47
|
+
if reload
|
48
|
+
retrieve()
|
49
|
+
elsif !@presence_data.key?('dndStatus')
|
50
|
+
retrieve()
|
51
|
+
end
|
52
|
+
|
53
|
+
current_status = @presence_data['dndStatus']
|
54
|
+
|
55
|
+
status_enabled = {
|
56
|
+
'DoNotAcceptAnyCalls' => false,
|
57
|
+
'DoNotAcceptDepartmentCalls' => false,
|
58
|
+
'TakeAllCalls' => true,
|
59
|
+
'TakeDepartmentCallsOnly' => true
|
60
|
+
}
|
61
|
+
|
62
|
+
return status_enabled.key?(current_status) ?
|
63
|
+
status_enabled[current_status] : nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def update(body=nil)
|
67
|
+
if body.nil?
|
68
|
+
raise 'HTTP request body is required to update presence'
|
69
|
+
end
|
70
|
+
|
71
|
+
res = @client.http.put do |req|
|
72
|
+
req.url "account/#{@account_id}/extension/#{@extension_id}/presence"
|
73
|
+
req.headers['Content-Type'] = 'application/json'
|
74
|
+
req.body = body
|
75
|
+
end
|
76
|
+
|
77
|
+
@presence_data = res.body
|
78
|
+
|
79
|
+
return @presence_data
|
80
|
+
end
|
81
|
+
|
82
|
+
def new_status_dnd_department_calls(current_status, enable)
|
83
|
+
new_statuses = {
|
84
|
+
:enable => {
|
85
|
+
'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly',
|
86
|
+
'DoNotAcceptDepartmentCalls' => 'TakeAllCalls'
|
87
|
+
},
|
88
|
+
:disable => {
|
89
|
+
'TakeAllCalls' => 'DoNotAcceptDepartmentCalls',
|
90
|
+
'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls'
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
action = enable ? :enable : :disable
|
95
|
+
|
96
|
+
new_status = current_status
|
97
|
+
|
98
|
+
new_status = new_statuses[action][current_status.to_s] \
|
99
|
+
if new_statuses[action].key?(current_status.to_s)
|
100
|
+
|
101
|
+
return new_status
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RingCentralSdk::REST
|
2
|
+
class Messages
|
3
|
+
attr_reader :sms
|
4
|
+
attr_reader :fax
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@sms = RingCentralSdk::REST::MessagesSMS.new(client)
|
9
|
+
@fax = RingCentralSdk::REST::MessagesFax.new(client)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module RingCentralSdk::REST
|
15
|
+
class MessagesSMS
|
16
|
+
def initialize(client)
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(opts)
|
21
|
+
response = @client.http.post do |req|
|
22
|
+
req.url 'account/~/extension/~/sms'
|
23
|
+
req.headers['Content-Type'] = 'application/json'
|
24
|
+
req.body = {
|
25
|
+
:from => { :phoneNumber => opts[:from].to_s },
|
26
|
+
:to => [ { :phoneNumber => opts[:to].to_s } ],
|
27
|
+
:text => opts[:text].to_s
|
28
|
+
}
|
29
|
+
end
|
30
|
+
return response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module RingCentralSdk::REST
|
36
|
+
class MessagesFax
|
37
|
+
def initialize(client)
|
38
|
+
@client = client
|
39
|
+
end
|
40
|
+
|
41
|
+
def create(opts)
|
42
|
+
fax = RingCentralSdk::REST::Request::Fax.new(opts)
|
43
|
+
return @client.send_request(fax)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'mime'
|
3
|
+
require 'mime/types'
|
4
|
+
require 'mime_builder'
|
5
|
+
require 'multi_json'
|
6
|
+
|
7
|
+
module RingCentralSdk::REST::Request
|
8
|
+
class Fax < RingCentralSdk::REST::Request::Base
|
9
|
+
attr_reader :msg
|
10
|
+
|
11
|
+
attr_reader :account_id
|
12
|
+
attr_reader :extension_id
|
13
|
+
|
14
|
+
def initialize(opts={})
|
15
|
+
@metadata_part_encode_base64 = true
|
16
|
+
|
17
|
+
@msg = MIME::Multipart::Mixed.new
|
18
|
+
@msg.headers.delete('Content-Id')
|
19
|
+
|
20
|
+
add_path(opts)
|
21
|
+
add_part_meta(opts)
|
22
|
+
add_part_text(opts[:text])
|
23
|
+
add_parts(opts[:files])
|
24
|
+
add_parts(opts[:parts])
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_path(opts={})
|
28
|
+
if opts.key?(:accountId) && opts[:accountId].to_s.length>0
|
29
|
+
@account_id = opts[:accountId]
|
30
|
+
else
|
31
|
+
@account_id = '~'
|
32
|
+
end
|
33
|
+
if opts.key?(:extensionId) && opts[:extensionId].to_s.length>0
|
34
|
+
@extension_id = opts[:extensionId]
|
35
|
+
else
|
36
|
+
@extension_id = '~'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_part_meta(opts={})
|
41
|
+
meta = create_metadata opts
|
42
|
+
json = MultiJson.encode meta
|
43
|
+
json = Base64.encode64(json) if @metadata_part_encode_base64
|
44
|
+
json_part = MIME::Text.new(json)
|
45
|
+
json_part.headers.delete('Content-Id')
|
46
|
+
json_part.headers.set('Content-Type', 'application/json')
|
47
|
+
json_part.headers.set('Content-Transfer-Encoding', 'base64') if @metadata_part_encode_base64
|
48
|
+
@msg.add(json_part)
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_metadata(opts={})
|
53
|
+
meta = {}
|
54
|
+
return meta unless opts.is_a?(Hash)
|
55
|
+
|
56
|
+
inf = RingCentralSdk::REST::Request::Inflator::ContactInfo.new
|
57
|
+
meta[:to] = inf.inflate_to_array opts[:to]
|
58
|
+
|
59
|
+
processed = {
|
60
|
+
:accountId => 1,
|
61
|
+
:extensionId => 1,
|
62
|
+
:to => 1,
|
63
|
+
:text => 1,
|
64
|
+
:files => 1,
|
65
|
+
:parts => 1
|
66
|
+
}
|
67
|
+
|
68
|
+
opts.each do |k,v|
|
69
|
+
meta[k] = v unless processed.key?(k)
|
70
|
+
end
|
71
|
+
|
72
|
+
meta
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_part_text(text=nil, opts={})
|
76
|
+
return unless !text.nil? && text.to_s.length>0
|
77
|
+
opts[:content_id_disable] = true
|
78
|
+
text_part = MIMEBuilder::Text.new(text, opts)
|
79
|
+
@msg.add(text_part.mime)
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_parts(parts=[])
|
83
|
+
return if parts.nil?
|
84
|
+
unless parts.is_a?(Array)
|
85
|
+
raise 'invalid parameter[0]. needs to be an array'
|
86
|
+
end
|
87
|
+
parts.each do |part|
|
88
|
+
if part.is_a?(String)
|
89
|
+
file_part = MIMEBuilder::Filepath.new(part)
|
90
|
+
@msg.add(file_part.mime)
|
91
|
+
elsif part.is_a? Hash
|
92
|
+
part[:content_id_disable] = true
|
93
|
+
part[:is_attachment] = true
|
94
|
+
if part.key? :filename
|
95
|
+
file_part = MIMEBuilder::Filepath.new(part[:filename], part)
|
96
|
+
@msg.add(file_part.mime)
|
97
|
+
elsif part.key? :text
|
98
|
+
text_part = MIMEBuilder::Text.new(part[:text], part)
|
99
|
+
@msg.add(text_part.mime)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def method()
|
106
|
+
'post'
|
107
|
+
end
|
108
|
+
|
109
|
+
def url()
|
110
|
+
"account/#{@account_id.to_s}/extension/#{@extension_id.to_s}/fax"
|
111
|
+
end
|
112
|
+
|
113
|
+
def content_type()
|
114
|
+
@msg.headers.get('Content-Type').to_s
|
115
|
+
end
|
116
|
+
|
117
|
+
def body()
|
118
|
+
@msg.body.to_s
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
class
|
3
|
-
attr_accessor :
|
1
|
+
module RingCentralSdk::REST
|
2
|
+
class SimpleClient
|
3
|
+
attr_accessor :client
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
7
|
end
|
8
8
|
|
9
9
|
def send(request)
|
10
10
|
if request.is_a?(RingCentralSdk::Helpers::Request)
|
11
|
-
return @
|
11
|
+
return @client.request(request)
|
12
12
|
elsif ! request.is_a?(Hash)
|
13
13
|
raise "Request is not a RingCentralSdk::Helpers::Request or Hash"
|
14
14
|
end
|
@@ -29,19 +29,19 @@ module RingCentralSdk
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def delete(opts={})
|
32
|
-
return @
|
32
|
+
return @client.http.delete do |req|
|
33
33
|
req.url build_url(opts[:path])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
def get(opts={})
|
38
|
-
return @
|
38
|
+
return @client.http.get do |req|
|
39
39
|
req.url build_url(opts[:path])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def post(opts={})
|
44
|
-
return @
|
44
|
+
return @client.http.post do |req|
|
45
45
|
req.url build_url(opts[:path])
|
46
46
|
if opts.has_key?(:body)
|
47
47
|
req.body = opts[:body]
|
@@ -53,7 +53,7 @@ module RingCentralSdk
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def put(opts={})
|
56
|
-
return @
|
56
|
+
return @client.http.put do |req|
|
57
57
|
req.url build_url(opts[:path])
|
58
58
|
if opts.has_key?(:body)
|
59
59
|
req.body = opts[:body]
|