class RingCentralSdk::REST::SimpleClient
A simplified, but still generic, REST
interface.
NOTE: This is an experimental module.
client = RingCentralSdk::REST::Client.new
… simple = RingCentralSdk::REST::SimpleClient
client
simple.post(
path: 'sms', body: { from: {phoneNumber: '+16505551212'}, to: [{phoneNumber: '+14155551212'}], text: 'Hi There!' }
)
Attributes
client[RW]
Public Class Methods
new(client)
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 21 def initialize(client) @client = client end
Public Instance Methods
build_url(path)
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 73 def build_url(path) path = [path] unless path.is_a? Array unless path.empty? path0 = path[0].to_s if path0.index('/').nil? && path0.index('account') != 0 path.unshift('extension/~') if path0.index('extension') != 0 path.unshift('account/~') end end path.join('/') end
delete(opts = {})
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 38 def delete(opts = {}) @client.http.delete do |req| req.url build_url(opts[:path]) end end
get(opts = {})
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 44 def get(opts = {}) @client.http.get do |req| req.url build_url(opts[:path]) end end
inflate_request(req, opts = {})
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 62 def inflate_request(req, opts = {}) req.url build_url(opts[:path]) if opts.key? :body req.body = opts[:body] if opts[:body].is_a?(Hash) req.headers['Content-Type'] = 'application/json' end end req end
post(opts = {})
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 50 def post(opts = {}) @client.http.post do |req| req = inflate_request req, opts end end
put(opts = {})
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 56 def put(opts = {}) @client.http.put do |req| req = inflate_request req, opts end end
send(request)
click to toggle source
# File lib/ringcentral_sdk/rest/simple_client.rb, line 25 def send(request) return @client.request(request) if request.is_a? RingCentralSdk::Helpers::Request raise(ArgumentError, 'Request is not a ...Helpers::Request or Hash') unless request.is_a? Hash verb = request.key?(:verb) ? request[:verb].to_s.downcase : 'get' return get(request) if verb == 'get' return post(request) if verb == 'post' return put(request) if verb == 'put' return delete(request) if verb == 'delete' raise ArgumentError, "Method not supported #{verb}" end