class Textmagic::REST::ListResource

Public Class Methods

new(path, client) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
 6 def initialize(path, client)
 7   custom_names = {
 8       'Replies' => 'Reply'
 9   }
10   @path, @client = path, client
11   resource_name = self.class.name.split('::')[-1]
12   instance_name = custom_names.fetch(resource_name, resource_name.chop)
13 
14   parent_module = self.class.to_s.split('::')[-2]
15   full_module_path = if parent_module == 'REST'
16                        Textmagic::REST
17                      else
18                        Textmagic::REST.const_get parent_module
19                      end
20 
21   @instance_class = full_module_path.const_get instance_name
22   @list_key, @instance_id_key = to_underscore_case(resource_name), 'id'
23 end

Public Instance Methods

create(params={}) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
47 def create(params={})
48   response = @client.post "#{@path}", params
49   @instance_class.new "#{@path}", @client, response
50 end
delete(uid, params={}) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
57 def delete(uid, params={})
58   raise "Can't delete a resource without a REST Client" unless @client
59   response = @client.delete "#{@path}/#{uid}", params
60 end
get(uid, params={}) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
42 def get(uid, params={})
43   response = @client.get "#{@path}/#{uid}", params
44   @instance_class.new "#{@path}", @client, response
45 end
list(params={}) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
29 def list(params={})
30   if params.key?('search') or params.key?(:search)
31     [:search, 'search'].each do |search|
32       params.delete(search)
33     end
34     path = "#{@path}" << '/search'
35   else
36     path = "#{@path}"
37   end
38   response = @client.get path, params
39   PaginateResource.new "#{@path}", @client, response, @instance_class
40 end
update(uid, params={}) click to toggle source
   # File lib/textmagic-ruby/rest/list_resource.rb
52 def update(uid, params={})
53   response = @client.put "#{@path}/#{uid}", params
54   @instance_class.new "#{@path}", @client, response
55 end