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,45 +1,42 @@
1
1
  require 'date'
2
2
  require 'jsondoc'
3
3
 
4
- module RingCentralSdk::REST
5
- class MessagesRetriever
6
- attr_accessor :range
7
- def initialize(client)
8
- @client = client
9
- @range = 1.0 # minutes
10
- end
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.merge!(
21
- dateFrom: (last_updated_dt - (@range/1440.0)).to_s,
22
- dateTo: (last_updated_dt + (@range/1440.0)).to_s)
23
-
24
- if event.new_sms_count > 0
25
- params[:messageType] = 'SMS'
26
- end
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
- res = @client.http.get do |req|
29
- req.url url
30
- req.params = params
31
- end
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
- messages = []
31
+ messages = []
34
32
 
35
- res.body['records'].each do |rec|
36
- rec_last_modified_time = rec['lastModifiedTime']
37
- rec_last_modified_time_dt = DateTime.iso8601(rec_last_modified_time)
38
- if rec_last_modified_time_dt == last_updated_dt
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
- return messages
43
- end
40
+ end
44
41
  end
45
42
  end
@@ -1,6 +1,11 @@
1
- module RingCentralSdk::REST::Request
2
- autoload :Base, 'ringcentral_sdk/rest/request/base'
3
- autoload :Fax, 'ringcentral_sdk/rest/request/fax'
4
- autoload :Inflator, 'ringcentral_sdk/rest/request/inflator'
5
- autoload :Simple, 'ringcentral_sdk/rest/request/simple'
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::REST::Request
2
- class Base
3
- def method
4
- return 'get' # HTTP methods
5
- end
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
- def url
8
- return ''
9
- end
10
+ def url
11
+ ''
12
+ end
10
13
 
11
- def params
12
- return {}
13
- end
14
+ def params
15
+ {}
16
+ end
14
17
 
15
- def headers
16
- return {}
17
- end
18
+ def headers
19
+ {}
20
+ end
18
21
 
19
- def content_type
20
- return ''
21
- end
22
+ def content_type
23
+ ''
24
+ end
22
25
 
23
- def body
24
- return '' # '' || Hash
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::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
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
- def add_path(opts={})
28
- @account_id = opts[:accountId] ||= '~'
29
- @extension_id = opts[:extensionId] ||= '~'
30
- end
30
+ def add_path(opts = {})
31
+ @account_id = opts[:accountId] ||= '~'
32
+ @extension_id = opts[:extensionId] ||= '~'
33
+ end
31
34
 
32
- def add_part_meta(opts={})
33
- meta = create_metadata opts
34
- json = MultiJson.encode meta
35
- json = Base64.encode64(json) if @metadata_part_encode_base64
36
- json_part = MIME::Text.new(json)
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
- def create_metadata(opts={})
45
- meta = {}
46
- return meta unless opts.is_a?(Hash)
41
+ def create_metadata(opts = {})
42
+ meta = {}
43
+ return meta unless opts.is_a?(Hash)
47
44
 
48
- inf = RingCentralSdk::REST::Request::Inflator::ContactInfo.new
49
- meta[:to] = inf.inflate_to_array opts[:to]
45
+ inf = RingCentralSdk::REST::Request::Inflator::ContactInfo.new
46
+ meta[:to] = inf.inflate_to_array opts[:to]
50
47
 
51
- processed = {
52
- accountId: 1,
53
- extensionId: 1,
54
- to: 1,
55
- text: 1,
56
- files: 1,
57
- parts: 1
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
- opts.each do |k,v|
61
- meta[k] = v unless processed.key? k
62
- end
57
+ opts.each do |k, v|
58
+ meta[k] = v unless processed.key? k
59
+ end
63
60
 
64
- meta
65
- end
61
+ meta
62
+ end
66
63
 
67
- def add_part_text(text=nil, opts={})
68
- return unless !text.nil? && text.to_s.length>0
69
- opts[:content_id_disable] = true
70
- text_part = MIMEBuilder::Text.new(text, opts)
71
- @msg.add text_part.mime
72
- end
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
- def add_parts(parts=[])
75
- return if parts.nil?
76
- unless parts.is_a? Array
77
- raise 'invalid parameter[0]. needs to be an array'
78
- end
79
- parts.each do |part|
80
- if part.is_a? MIME::Media
81
- @msg.add part
82
- elsif part.is_a?(String)
83
- file_part = MIMEBuilder::Filepath.new(part)
84
- @msg.add file_part.mime
85
- elsif part.is_a? Hash
86
- part[:content_id_disable] = true
87
- part[:is_attachment] = true
88
- if part.key? :filename
89
- file_part = MIMEBuilder::Filepath.new(part[:filename], part)
90
- @msg.add file_part.mime
91
- elsif part.key? :text
92
- text_part = MIMEBuilder::Text.new(part[:text], part)
93
- @msg.add text_part.mime
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
- def method()
100
- 'post'
101
- end
94
+ def method
95
+ 'post'
96
+ end
102
97
 
103
- def url()
104
- "account/#{@account_id.to_s}/extension/#{@extension_id.to_s}/fax"
105
- end
98
+ def url
99
+ "account/#{@account_id}/extension/#{@extension_id}/fax"
100
+ end
106
101
 
107
- def content_type()
108
- @msg.headers.get('Content-Type').to_s
109
- end
102
+ def content_type
103
+ @msg.headers.get('Content-Type').to_s
104
+ end
110
105
 
111
- def body()
112
- @msg.body.to_s
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::REST::Request::Inflator
2
- autoload :ContactInfo, 'ringcentral_sdk/rest/request/inflator/contact_info'
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::REST::Request::Inflator
2
- class ContactInfo
3
- def inflate_to_array(any=nil)
4
- contacts = []
5
- if any.is_a?(Array)
6
- contacts = any
7
- elsif any.is_a?(Hash)
8
- contacts = [any]
9
- elsif any.is_a?(String) || any.is_a?(Integer)
10
- contacts = [{:phoneNumber=>any}]
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::REST::Request
2
- class Simple < RingCentralSdk::REST::Request::Base
3
- def initialize(opts = {})
4
- @method = opts[:method]
5
- @url = opts[:url]
6
- @params = opts[:params]
7
- @headers = opts[:headers]
8
- @body = opts[:body].nil? ? {} : opts[:body]
9
- if @body.is_a? Hash
10
- @headers = {} unless @headers.is_a? Hash
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
- def url
24
- @url
25
- end
26
-
27
- def params
28
- @params
29
- end
30
-
31
- def headers
32
- @headers
33
- end
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
- def body
36
- @body
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