Class: SmsGlobal::Object::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_global/object/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/sms_global/object/base.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/sms_global/object/base.rb', line 4

def client
  @client
end

Instance Method Details

#all(params = {}) ⇒ Object



14
15
16
# File 'lib/sms_global/object/base.rb', line 14

def all(params = {})
  get(nil, params)
end

#create(params = {}) ⇒ Object



18
19
20
# File 'lib/sms_global/object/base.rb', line 18

def create(params = {})
  post(params)
end

#delete(id) ⇒ Object



53
54
55
56
57
58
59
60
# 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) ⇒ Object



10
11
12
# File 'lib/sms_global/object/base.rb', line 10

def find(id)
  get(id)
end

#get(id, params = {}) ⇒ Object



26
27
28
29
30
31
32
33
# 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 = {}) ⇒ Object



44
45
46
47
48
49
50
51
# 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 = {}) ⇒ Object



35
36
37
38
39
40
41
42
# 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 = {}) ⇒ Object



22
23
24
# File 'lib/sms_global/object/base.rb', line 22

def update(id, params = {})
  patch(id, params)
end