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,45 +1,42 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'jsondoc'
|
3
3
|
|
4
|
-
module RingCentralSdk
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def retrieve_for_event(event, params={})
|
13
|
-
unless event.is_a? RingCentralSdk::REST::Event
|
14
|
-
fail 'retrieve_for_event requires RingCentralSdk::REST::Event argument'
|
4
|
+
module RingCentralSdk
|
5
|
+
module REST
|
6
|
+
# MessagesRetrieve is a class that will retrieve matching records for an event
|
7
|
+
class MessagesRetriever
|
8
|
+
attr_accessor :range
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
@range = 1.0 # minutes
|
15
12
|
end
|
16
|
-
url = event.doc.getAttr :event
|
17
|
-
last_updated_s = event.doc.getAttr('body.lastUpdated')
|
18
|
-
last_updated_dt = DateTime.iso8601(last_updated_s)
|
19
13
|
|
20
|
-
params
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
def retrieve_for_event(event, params = {})
|
15
|
+
unless event.is_a? RingCentralSdk::REST::Event
|
16
|
+
raise ArgumentError, 'retrieve_for_event requires RingCentralSdk::REST::Event argument'
|
17
|
+
end
|
18
|
+
url = event.doc.getAttr :event
|
19
|
+
last_updated_s = event.doc.getAttr('body.lastUpdated')
|
20
|
+
last_updated_dt = DateTime.iso8601(last_updated_s)
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
params[:dateFrom] = (last_updated_dt - (@range / 1440.0)).to_s
|
23
|
+
params[:dateTo] = (last_updated_dt + (@range / 1440.0)).to_s
|
24
|
+
params[:messageType] = 'SMS' if event.new_sms_count > 0
|
25
|
+
|
26
|
+
res = @client.http.get do |req|
|
27
|
+
req.url url
|
28
|
+
req.params = params
|
29
|
+
end
|
32
30
|
|
33
|
-
|
31
|
+
messages = []
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
messages.push rec
|
33
|
+
res.body['records'].each do |rec|
|
34
|
+
rec_last_modified_time = rec['lastModifiedTime']
|
35
|
+
rec_last_modified_time_dt = DateTime.iso8601(rec_last_modified_time)
|
36
|
+
messages.push(rec) if rec_last_modified_time_dt == last_updated_dt
|
40
37
|
end
|
38
|
+
messages
|
41
39
|
end
|
42
|
-
|
43
|
-
end
|
40
|
+
end
|
44
41
|
end
|
45
42
|
end
|
@@ -1,6 +1,11 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module RingCentralSdk
|
2
|
+
module REST
|
3
|
+
# Request is the module namespace for various API request helpers.
|
4
|
+
module Request
|
5
|
+
autoload :Base, 'ringcentral_sdk/rest/request/base'
|
6
|
+
autoload :Fax, 'ringcentral_sdk/rest/request/fax'
|
7
|
+
autoload :Inflator, 'ringcentral_sdk/rest/request/inflator'
|
8
|
+
autoload :Simple, 'ringcentral_sdk/rest/request/simple'
|
9
|
+
end
|
10
|
+
end
|
6
11
|
end
|
@@ -1,27 +1,32 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module RingCentralSdk
|
2
|
+
module REST
|
3
|
+
module Request
|
4
|
+
# Base class for various types of requests.
|
5
|
+
class Base
|
6
|
+
def method
|
7
|
+
'get' # HTTP methods
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def url
|
11
|
+
''
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
def params
|
15
|
+
{}
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
+
def headers
|
19
|
+
{}
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
def content_type
|
23
|
+
''
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
def body
|
27
|
+
'' # '' || Hash
|
28
|
+
end
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -4,112 +4,109 @@ require 'mime/types'
|
|
4
4
|
require 'mime_builder'
|
5
5
|
require 'multi_json'
|
6
6
|
|
7
|
-
module RingCentralSdk
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
7
|
+
module RingCentralSdk
|
8
|
+
module REST
|
9
|
+
module Request
|
10
|
+
# Helper to create a fax request
|
11
|
+
class Fax < RingCentralSdk::REST::Request::Base
|
12
|
+
attr_reader :msg
|
13
|
+
|
14
|
+
attr_reader :account_id
|
15
|
+
attr_reader :extension_id
|
16
|
+
|
17
|
+
def initialize(opts = {})
|
18
|
+
@metadata_part_encode_base64 = true
|
19
|
+
|
20
|
+
@msg = MIME::Multipart::Mixed.new
|
21
|
+
@msg.headers.delete('Content-Id')
|
22
|
+
|
23
|
+
add_path(opts)
|
24
|
+
add_part_meta(opts)
|
25
|
+
add_part_text(opts[:text])
|
26
|
+
add_parts(opts[:files])
|
27
|
+
add_parts(opts[:parts])
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def add_path(opts = {})
|
31
|
+
@account_id = opts[:accountId] ||= '~'
|
32
|
+
@extension_id = opts[:extensionId] ||= '~'
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
json_part.headers.delete('Content-Id')
|
38
|
-
json_part.headers.set('Content-Type', 'application/json')
|
39
|
-
json_part.headers.set('Content-Transfer-Encoding', 'base64') if @metadata_part_encode_base64
|
40
|
-
@msg.add(json_part)
|
41
|
-
true
|
42
|
-
end
|
35
|
+
def add_part_meta(opts = {})
|
36
|
+
meta = create_metadata opts
|
37
|
+
@msg.add MIMEBuilder::JSON.new(meta).mime
|
38
|
+
true
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def create_metadata(opts = {})
|
42
|
+
meta = {}
|
43
|
+
return meta unless opts.is_a?(Hash)
|
47
44
|
|
48
|
-
|
49
|
-
|
45
|
+
inf = RingCentralSdk::REST::Request::Inflator::ContactInfo.new
|
46
|
+
meta[:to] = inf.inflate_to_array opts[:to]
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
processed = {
|
49
|
+
accountId: 1,
|
50
|
+
extensionId: 1,
|
51
|
+
to: 1,
|
52
|
+
text: 1,
|
53
|
+
files: 1,
|
54
|
+
parts: 1
|
55
|
+
}
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
opts.each do |k, v|
|
58
|
+
meta[k] = v unless processed.key? k
|
59
|
+
end
|
63
60
|
|
64
|
-
|
65
|
-
|
61
|
+
meta
|
62
|
+
end
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
def add_part_text(text = nil, opts = {})
|
65
|
+
return if text.nil? || text.to_s.empty?
|
66
|
+
opts[:content_id_disable] = true
|
67
|
+
text_part = MIMEBuilder::Text.new text, opts
|
68
|
+
@msg.add text_part.mime
|
69
|
+
end
|
73
70
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
71
|
+
def add_parts(parts = [])
|
72
|
+
return if parts.nil?
|
73
|
+
unless parts.is_a? Array
|
74
|
+
raise 'invalid parameter[0]. needs to be an array'
|
75
|
+
end
|
76
|
+
parts.each do |part|
|
77
|
+
if part.is_a? MIME::Media
|
78
|
+
@msg.add part
|
79
|
+
elsif part.is_a?(String)
|
80
|
+
file_part = MIMEBuilder::Filepath.new part
|
81
|
+
@msg.add file_part.mime
|
82
|
+
elsif part.is_a? Hash
|
83
|
+
part[:content_id_disable] = true
|
84
|
+
part[:is_attachment] = true
|
85
|
+
if part.key? :filename
|
86
|
+
@msg.add MIMEBuilder::Filepath.new(part[:filename], part).mime
|
87
|
+
elsif part.key? :text
|
88
|
+
@msg.add MIMEBuilder::Text.new(part[:text], part).mime
|
89
|
+
end
|
90
|
+
end
|
94
91
|
end
|
95
92
|
end
|
96
|
-
end
|
97
|
-
end
|
98
93
|
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
def method
|
95
|
+
'post'
|
96
|
+
end
|
102
97
|
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
def url
|
99
|
+
"account/#{@account_id}/extension/#{@extension_id}/fax"
|
100
|
+
end
|
106
101
|
|
107
|
-
|
108
|
-
|
109
|
-
|
102
|
+
def content_type
|
103
|
+
@msg.headers.get('Content-Type').to_s
|
104
|
+
end
|
110
105
|
|
111
|
-
|
112
|
-
|
106
|
+
def body
|
107
|
+
@msg.body.to_s
|
108
|
+
end
|
109
|
+
end
|
113
110
|
end
|
114
111
|
end
|
115
112
|
end
|
@@ -1,3 +1,10 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
|
1
|
+
module RingCentralSdk
|
2
|
+
module REST
|
3
|
+
module Request
|
4
|
+
# Inflator is the namespace for inflator classes such as ContactInfo
|
5
|
+
module Inflator
|
6
|
+
autoload :ContactInfo, 'ringcentral_sdk/rest/request/inflator/contact_info'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
3
10
|
end
|
@@ -1,15 +1,22 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module RingCentralSdk
|
2
|
+
module REST
|
3
|
+
module Request
|
4
|
+
module Inflator
|
5
|
+
# ContactInfo class will inflate contact info to array
|
6
|
+
class ContactInfo
|
7
|
+
def inflate_to_array(any = nil)
|
8
|
+
contacts = []
|
9
|
+
if any.is_a?(Array)
|
10
|
+
contacts = any
|
11
|
+
elsif any.is_a?(Hash)
|
12
|
+
contacts = [any]
|
13
|
+
elsif any.is_a?(String) || any.is_a?(Integer)
|
14
|
+
contacts = [{ phoneNumber: any }]
|
15
|
+
end
|
16
|
+
contacts
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
|
-
return contacts
|
13
20
|
end
|
14
21
|
end
|
15
|
-
end
|
22
|
+
end
|
@@ -1,39 +1,29 @@
|
|
1
|
-
module RingCentralSdk
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@headers['Content-Type'] = 'application/json'
|
12
|
-
end
|
13
|
-
|
14
|
-
def content_type
|
15
|
-
ct = @headers.is_a?(Hash) \
|
16
|
-
? @headers['Content-Type'] || '' : 'application/json'
|
17
|
-
end
|
18
|
-
|
19
|
-
def method
|
20
|
-
@method
|
21
|
-
end
|
1
|
+
module RingCentralSdk
|
2
|
+
module REST
|
3
|
+
module Request
|
4
|
+
# Simple is a generic simple request class.
|
5
|
+
class Simple < RingCentralSdk::REST::Request::Base
|
6
|
+
attr_reader :method
|
7
|
+
attr_reader :url
|
8
|
+
attr_reader :params
|
9
|
+
attr_reader :headers
|
10
|
+
attr_reader :body
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
12
|
+
def initialize(opts = {})
|
13
|
+
@method = opts[:method]
|
14
|
+
@url = opts[:url]
|
15
|
+
@params = opts[:params]
|
16
|
+
@headers = opts[:headers]
|
17
|
+
@body = opts[:body].nil? ? {} : opts[:body]
|
18
|
+
if @body.is_a? Hash
|
19
|
+
@headers = {} unless @headers.is_a? Hash
|
20
|
+
@headers['Content-Type'] = 'application/json'
|
21
|
+
end
|
22
|
+
end
|
34
23
|
|
35
|
-
|
36
|
-
|
24
|
+
def content_type
|
25
|
+
@headers.is_a?(Hash) ? @headers['Content-Type'] || '' : 'application/json'
|
26
|
+
end
|
37
27
|
end
|
38
28
|
end
|
39
29
|
end
|