class SmsGlobal::Object::Base

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/sms_global/object/base.rb, line 6
def initialize(client)
  @client = client
end

Public Instance Methods

all(params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 14
def all(params = {})
  get(nil, params)
end
create(params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 18
def create(params = {})
  post(params)
end
delete(id) click to toggle source
# File lib/sms_global/object/base.rb, line 53
def delete(id)
  if method_supported?(:delete)
    url, action = build_url(child_path: object_name, child_id: id)
    Request.delete(@client, url, action)
  else
    raise SmsGlobal::NoSupportedMethod.new(:delete, object_methods)
  end
end
find(id) click to toggle source
# File lib/sms_global/object/base.rb, line 10
def find(id)
  get(id)
end
get(id, params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 26
def get(id, params = {})
  if method_supported?(:get)
    url, action = build_url(child_path: object_name, child_id: id)
    Request.get(@client, url, action, params)
  else
    raise SmsGlobal::NoSupportedMethod.new(:get, object_methods)
  end
end
patch(id, params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 44
def patch(id, params = {})
  if method_supported?(:patch)
    url, action = build_url(child_path: object_name, child_id: id)
    Request.patch(@client, url, action, params)
  else
    raise SmsGlobal::NoSupportedMethod.new(:patch, object_methods)
  end
end
post(params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 35
def post(params = {})
  if method_supported?(:post)
    url, action = build_url(child_path: object_name)
    Request.post(@client, url, action, params)
  else
    raise SmsGlobal::NoSupportedMethod.new(:post, object_methods)
  end
end
update(id, params = {}) click to toggle source
# File lib/sms_global/object/base.rb, line 22
def update(id, params = {})
  patch(id, params)
end

Private Instance Methods

action_builder(child_path = '', child_id = '') click to toggle source
# File lib/sms_global/object/base.rb, line 90
def action_builder(child_path = '', child_id = '')
  action = "/#{client.api_version}"
  action += "/#{child_path}" if !child_path.to_s.blank?
  action += "/#{child_id}" if !child_id.to_s.blank?
  return action
end
build_url(child_path: '', child_id: '') click to toggle source
# File lib/sms_global/object/base.rb, line 77
def build_url(child_path: '', child_id: '')
  url = url_builder(child_path, child_id)
  action = action_builder(child_path, child_id)
  return url, action
end
method_supported?(method) click to toggle source
# File lib/sms_global/object/base.rb, line 72
def method_supported?(method)
  return true if object_methods.include?(method)
  return false
end
object_methods() click to toggle source
# File lib/sms_global/object/base.rb, line 68
def object_methods
  self.class.const_get(:OBJECT_METHODS)
end
object_name() click to toggle source
# File lib/sms_global/object/base.rb, line 64
def object_name
  self.class.const_get(:OBJECT)
end
url_builder(child_path = '', child_id = '') click to toggle source
# File lib/sms_global/object/base.rb, line 83
def url_builder(child_path = '', child_id = '')
  url = "#{@client.url}/#{client.api_version}"
  url += "/#{child_path}" if !child_path.to_s.blank?
  url += "/#{child_id}" if !child_id.to_s.blank?
  return url
end