Module: Model::Tag

Extended by:
ActiveSupport::Concern
Included in:
Wechat::Tag
Defined in:
app/models/wechat/model/tag.rb

Constant Summary collapse

SYS_TAG =
['2'].freeze

Instance Method Summary collapse

Instance Method Details

#can_destroy?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/wechat/model/tag.rb', line 51

def can_destroy?
  SYS_TAG.include?(tag_id)
end

#remove_from_wechatObject



45
46
47
48
49
# File 'app/models/wechat/model/tag.rb', line 45

def remove_from_wechat
  app.api.tag_delete(self.tag_id)
rescue Wechat::WechatError => e
  logger.info e.message
end

#sync_nameObject



28
29
30
# File 'app/models/wechat/model/tag.rb', line 28

def sync_name
  self.name = tagging.name if tagging
end

#sync_to_wechatObject



36
37
38
39
40
41
42
43
# File 'app/models/wechat/model/tag.rb', line 36

def sync_to_wechat
  r = app.api.tag_create(self.name, self.tag_id)
  return unless r
  self.tag_id = r.dig('tag', 'id')
  self.save
rescue Wechat::WechatError => e
  logger.info e.message
end

#sync_to_wechat_laterObject



32
33
34
# File 'app/models/wechat/model/tag.rb', line 32

def sync_to_wechat_later
  TagJob.perform_later(self)
end