Module: Model::AppSync

Extended by:
ActiveSupport::Concern
Included in:
Wechat::Agency, Wechat::App
Defined in:
app/models/wechat/model/app_sync.rb

Instance Method Summary collapse

Instance Method Details

#access_token_valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'app/models/wechat/model/app_sync.rb', line 15

def access_token_valid?
  return false unless access_token_expires_at.acts_like?(:time)
  access_token_expires_at > Time.current
end

#sync_from_menuObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/wechat/model/app_sync.rb', line 20

def sync_from_menu
  r = api.menu
  present_menus = r.dig('menu', 'button')
  present_menus.each do |present_menu|
    if present_menu['sub_button'].present?
      parent = self.menus.build(type: 'ParentMenu', name: present_menu['name'])
      present_menu['sub_button'].each do |sub|
        parent.children.build(appid: appid, name: sub['name'], menu_type: sub['type'], value: sub['url'] || sub['key'])
      end
      parent.save
    end
  end
end