Class: Tag

Inherits:
LogicalModel
  • Object
show all
Defined in:
app/models/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'app/models/tag.rb', line 2

def name
  @name
end

Class Method Details

.account_tags(account_name) ⇒ Object

Returns all the tags associated with a given account



35
36
37
# File 'app/models/tag.rb', line 35

def self.()
  paginate(per_page: 999, account_name: )
end

.batch_add(tags, contact_ids, account_name, params = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/tag.rb', line 39

def self.batch_add(tags, contact_ids, , params = {})
  params.merge!({ account_name: , tags: tags, contact_ids: contact_ids })
  params = self.merge_key(params)

  response = nil
  Timeout::timeout(self.timeout/1000) do
    response = Typhoeus::Request.post("#{url_protocol_prefix}#{self.host}/v0/accounts/#{}/tags/batch_add", 
                                      :params => params, 
                                      :timeout => self.timeout)
  end

  if response.code == 201 || response.code == 202
    log_ok(response)
      return true
  elsif response.code == 400
    log_failed(response)
    ws_errors = ActiveSupport::JSON.decode(response.body)["errors"]
    ws_errors.each_key do |k|
      self.errors.add k, ws_errors[k]
    end
    return false
  else
    log_failed(response)
    return nil
  end
rescue Timeout::Error
  self.class.logger.warn "timeout"
  return nil
end

Instance Method Details

#idObject



25
26
27
# File 'app/models/tag.rb', line 25

def id
  self._id
end

#id=(id) ⇒ Object



29
30
31
# File 'app/models/tag.rb', line 29

def id= id
  self._id = id
end

#json_rootObject



17
18
19
# File 'app/models/tag.rb', line 17

def json_root
  :tag
end

#to_keyObject



21
22
23
# File 'app/models/tag.rb', line 21

def to_key
  [self._id]
end