Class: RingCentralSdk::REST::SimpleClient
- Inherits:
-
Object
- Object
- RingCentralSdk::REST::SimpleClient
- Defined in:
- lib/ringcentral_sdk/rest/simple_client.rb
Overview
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!'
}
)
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #build_url(path) ⇒ Object
- #delete(opts = {}) ⇒ Object
- #get(opts = {}) ⇒ Object
- #inflate_request(req, opts = {}) ⇒ Object
-
#initialize(client) ⇒ SimpleClient
constructor
A new instance of SimpleClient.
- #post(opts = {}) ⇒ Object
- #put(opts = {}) ⇒ Object
- #send(request) ⇒ Object
Constructor Details
#initialize(client) ⇒ SimpleClient
Returns a new instance of SimpleClient.
21 22 23 |
# File 'lib/ringcentral_sdk/rest/simple_client.rb', line 21 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
19 20 21 |
# File 'lib/ringcentral_sdk/rest/simple_client.rb', line 19 def client @client end |
Instance Method Details
#build_url(path) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# 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 = {}) ⇒ Object
38 39 40 41 42 |
# 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 = {}) ⇒ Object
44 45 46 47 48 |
# 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 = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# 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 = {}) ⇒ Object
50 51 52 53 54 |
# 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 = {}) ⇒ Object
56 57 58 59 60 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# 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 |