Module: CapsuleCRM::Taggable

Extended by:
ActiveSupport::Concern
Included in:
Case, Party
Defined in:
lib/capsule_crm/taggable.rb

Instance Method Summary collapse

Instance Method Details

#add_tag(tag_name) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/capsule_crm/taggable.rb', line 13

def add_tag(tag_name)
  if id
    CapsuleCRM::Connection.post(
      "/api/#{api_singular_name}/#{id}/tag/#{URI.encode(tag_name)}"
    )
  end
end

#api_singular_nameObject



29
30
31
32
33
# File 'lib/capsule_crm/taggable.rb', line 29

def api_singular_name
  class_name = self.class.superclass.to_s unless self.class.superclass == Object
  class_name ||= self.class.to_s
  class_name.demodulize.downcase.singularize
end

#remove_tag(tag_name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/capsule_crm/taggable.rb', line 21

def remove_tag(tag_name)
  if id
    CapsuleCRM::Connection.delete(
      "/api/#{api_singular_name}/#{id}/tag/#{URI.encode(tag_name)}"
    )
  end
end

#tagsObject



5
6
7
8
9
10
11
# File 'lib/capsule_crm/taggable.rb', line 5

def tags
  tags = CapsuleCRM::Connection.get(
    "/api/#{api_singular_name}/#{id}/tag"
  )['tags']['tag']
  tags = [tags] if tags.is_a? Hash
  tags.map { |item| CapsuleCRM::Tag.new(item) }
end