lib/ringcentral_sdk/rest/messages.rb in ringcentral_sdk-2.0.3 vs lib/ringcentral_sdk/rest/messages.rb in ringcentral_sdk-2.1.0
- old
+ new
@@ -5,36 +5,40 @@
attr_reader :sms
attr_reader :fax
def initialize(client)
@client = client
- @sms = RingCentralSdk::REST::MessagesSMS.new(client)
- @fax = RingCentralSdk::REST::MessagesFax.new(client)
+ @sms = RingCentralSdk::REST::MessagesSMS.new client
+ @fax = RingCentralSdk::REST::MessagesFax.new client
end
end
end
end
module RingCentralSdk
module REST
- # MessagesSMS provides a helper for SMS messages
+ # MessagesSMS provides a helper for SMS and MMS messages
class MessagesSMS
def initialize(client)
@client = client
end
def create(opts)
- response = @client.http.post do |req|
- req.url 'account/~/extension/~/sms'
- req.headers['Content-Type'] = 'application/json'
- req.body = {
- from: { phoneNumber: opts[:from].to_s },
- to: [{ phoneNumber: opts[:to].to_s }],
- text: opts[:text].to_s
- }
+ req = RingCentralSdk::REST::Request::SMS.new
+ req.add_metadata({
+ to: opts[:to],
+ from: opts[:from],
+ text: opts[:text]
+ })
+ if opts.key? :media
+ if opts[:media].is_a? String
+ req.add_file opts[:media]
+ elsif opts[:media].is_a? Array
+ req.add_files opts[:media]
+ end
end
- response
+ @client.send_request req
end
end
end
end
@@ -45,11 +49,32 @@
def initialize(client)
@client = client
end
def create(opts)
- fax = RingCentralSdk::REST::Request::Fax.new opts
- @client.send_request fax
+ req = RingCentralSdk::REST::Request::Fax.new
+ meta = {}
+
+ skip = {text: 1, files: 1}
+
+ opts.each do |k,v|
+ meta[k] = v unless skip.key? k
+ end
+
+ req.add_metadata meta
+
+ if opts.key? :text
+ req.add_text opts[:text]
+ end
+
+ if opts.key? :files
+ if opts[:files].is_a? String
+ req.add_file opts[:files]
+ elsif opts[:files].is_a? Array
+ req.add_files opts[:files]
+ end
+ end
+ @client.send_request req
end
end
end
end