ringcentral_sdk 0.5.2 → 1.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 +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
@@ -1,160 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'mime'
|
3
|
-
require 'mime/types'
|
4
|
-
require 'multi_json'
|
5
|
-
|
6
|
-
module RingCentralSdk::Helpers
|
7
|
-
class CreateFaxRequest < RingCentralSdk::Helpers::Request
|
8
|
-
attr_reader :msg
|
9
|
-
|
10
|
-
def initialize(path_params=nil, metadata=nil, options=nil)
|
11
|
-
|
12
|
-
@msg = MIME::Multipart::Mixed.new
|
13
|
-
@msg.headers.delete('Content-Id')
|
14
|
-
|
15
|
-
@path_params = path_params
|
16
|
-
|
17
|
-
if metadata.is_a?(Hash) || metadata.is_a?(String)
|
18
|
-
add_metadata(metadata)
|
19
|
-
end
|
20
|
-
|
21
|
-
if options.is_a?(Hash)
|
22
|
-
if options.has_key?(:file_name)
|
23
|
-
add_file(options[:file_name], options[:file_content_type], options[:base64_encode])
|
24
|
-
elsif options.has_key?(:text)
|
25
|
-
add_file_text(options[:text])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def add_metadata(meta=nil)
|
31
|
-
base64_encode = true
|
32
|
-
meta = inflate_metadata(meta)
|
33
|
-
json = MultiJson.encode(meta)
|
34
|
-
json = Base64.encode64(json) if base64_encode
|
35
|
-
json_part = MIME::Text.new(json)
|
36
|
-
json_part.headers.delete('Content-Id')
|
37
|
-
json_part.headers.set('Content-Type', 'application/json')
|
38
|
-
json_part.headers.set('Content-Transfer-Encoding', 'base64') if base64_encode
|
39
|
-
@msg.add(json_part)
|
40
|
-
return true
|
41
|
-
end
|
42
|
-
|
43
|
-
def inflate_metadata(meta=nil)
|
44
|
-
if meta.is_a?(String)
|
45
|
-
meta = MultiJson.decode(meta,:symbolize_keys=>true)
|
46
|
-
end
|
47
|
-
if meta.is_a?(Hash)
|
48
|
-
inf = RingCentralSdk::Helpers::Inflator::ContactInfo.new
|
49
|
-
|
50
|
-
if meta.has_key?(:to)
|
51
|
-
meta[:to] = inf.inflate_to_array( meta[:to] )
|
52
|
-
elsif meta.has_key?("to")
|
53
|
-
meta["to"] = inf.inflate_to_array( meta["to"] )
|
54
|
-
else
|
55
|
-
meta[:to] = inf.inflate_to_array( nil )
|
56
|
-
end
|
57
|
-
end
|
58
|
-
return meta
|
59
|
-
end
|
60
|
-
|
61
|
-
def add_file_text(text=nil, charset='UTF-8')
|
62
|
-
return unless text.is_a?(String)
|
63
|
-
text_part = MIME::Text.new(text,'plain')
|
64
|
-
text_part.headers.delete('Content-Id')
|
65
|
-
@msg.add(text_part)
|
66
|
-
end
|
67
|
-
|
68
|
-
def add_file(file_name, content_type=nil, base64_encode=false)
|
69
|
-
file_part = get_file_part(file_name, content_type, base64_encode)
|
70
|
-
|
71
|
-
@msg.add(file_part)
|
72
|
-
return true
|
73
|
-
end
|
74
|
-
|
75
|
-
def get_file_part(file_name, content_type=nil, base64_encode=false)
|
76
|
-
file_bytes = get_file_bytes(file_name)
|
77
|
-
|
78
|
-
file_part = base64_encode \
|
79
|
-
? MIME::Text.new(Base64.encode64(file_bytes)) \
|
80
|
-
: MIME::Application.new(file_bytes)
|
81
|
-
|
82
|
-
file_part.headers.delete('Content-Id')
|
83
|
-
file_part.headers.set('Content-Type', get_file_content_type(file_name, content_type))
|
84
|
-
file_part.headers.set('Content-Disposition', get_attachment_content_disposition(file_name))
|
85
|
-
file_part.headers.set('Content-Transfer-Encoding', 'base64') if base64_encode
|
86
|
-
return file_part
|
87
|
-
end
|
88
|
-
|
89
|
-
def get_file_bytes(file_name=nil)
|
90
|
-
unless File.file?(file_name.to_s)
|
91
|
-
raise "File \"#{file_name.to_s}\" does not exist or cannot be read"
|
92
|
-
end
|
93
|
-
|
94
|
-
# file_bytes = RUBY_VERSION < '1.9' \ # 1.8.7 removed due to subscription
|
95
|
-
# ? File.open(file_name, 'rb') { |f| f.read } \
|
96
|
-
# : File.open(file_name, 'rb:BINARY') { |f| f.read }
|
97
|
-
|
98
|
-
file_bytes = File.open(file_name, 'rb:BINARY') { |f| f.read }
|
99
|
-
|
100
|
-
return file_bytes
|
101
|
-
end
|
102
|
-
|
103
|
-
def get_file_content_type(file_name=nil, content_type=nil)
|
104
|
-
return (content_type.is_a?(String) && content_type =~ /^[^\/\s]+\/[^\/\s]+/) \
|
105
|
-
? content_type : MIME::Types.type_for(file_name).first.content_type || 'application/octet-stream'
|
106
|
-
end
|
107
|
-
|
108
|
-
def get_attachment_content_disposition(file_name=nil)
|
109
|
-
base_name = File.basename(file_name.to_s)
|
110
|
-
if base_name.is_a?(String) && base_name.length>0
|
111
|
-
return "attachment; filename=\"#{base_name}\""
|
112
|
-
else
|
113
|
-
return 'attachment'
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def method()
|
118
|
-
return 'post'
|
119
|
-
end
|
120
|
-
|
121
|
-
def url()
|
122
|
-
|
123
|
-
vals = {:account_id => '~', :extension_id => '~'}
|
124
|
-
|
125
|
-
if @path_params.is_a?(Hash)
|
126
|
-
vals.keys.each do |key|
|
127
|
-
next unless @path_params.has_key?(key)
|
128
|
-
if @path_params[key].is_a?(String) && @path_params[key].length>0
|
129
|
-
vals[key] = @path_params[key]
|
130
|
-
elsif @path_params[key].is_a?(Integer) && @path_params[key]>0
|
131
|
-
vals[key] = @path_params[key].to_s
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
return "account/#{vals[:account_id].to_s}/extension/#{vals[:extension_id].to_s}/fax"
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
def content_type()
|
141
|
-
return @msg.headers.get('Content-Type').to_s
|
142
|
-
end
|
143
|
-
|
144
|
-
def body()
|
145
|
-
return @msg.body.to_s
|
146
|
-
end
|
147
|
-
|
148
|
-
# Experimental
|
149
|
-
#def _add_file(file_name=nil)
|
150
|
-
# if file_name.is_a?(String) && File.file?(file_name)
|
151
|
-
# file_msg = MIME::DiscreteMediaFactory.create(file_name)
|
152
|
-
# file_msg.headers.delete('Content-Id')
|
153
|
-
# @msg.add(file_msg)
|
154
|
-
# return true
|
155
|
-
# end
|
156
|
-
# return false
|
157
|
-
#end
|
158
|
-
#private :_add_file
|
159
|
-
end
|
160
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RingCentralSdk::Helpers
|
2
|
-
class Messages
|
3
|
-
def initialize(rcapi)
|
4
|
-
@rcapi = rcapi
|
5
|
-
end
|
6
|
-
def create(opts)
|
7
|
-
response = @rcapi.client.post do |req|
|
8
|
-
req.url 'account/~/extension/~/sms'
|
9
|
-
req.headers['Content-Type'] = 'application/json'
|
10
|
-
req.body = {
|
11
|
-
:from => { :phoneNumber => opts[:from].to_s },
|
12
|
-
:to => [ { :phoneNumber => opts[:to].to_s } ],
|
13
|
-
:text => opts[:text].to_s
|
14
|
-
}
|
15
|
-
end
|
16
|
-
return response
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
module RingCentralSdk::Helpers
|
2
|
-
autoload :CreateFaxRequest, 'ringcentral_sdk/helpers/fax'
|
3
|
-
autoload :ExtensionPresence, 'ringcentral_sdk/helpers/extension_presence'
|
4
|
-
autoload :Inflator, 'ringcentral_sdk/helpers/inflator'
|
5
|
-
autoload :Messages, 'ringcentral_sdk/helpers/messages'
|
6
|
-
autoload :Request, 'ringcentral_sdk/helpers/request'
|
7
|
-
end
|