Class: EricWeixin::MediaArticle

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/eric_weixin/media_article.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.common_query(options) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/eric_weixin/media_article.rb', line 37

def self.common_query options
  articles = self.all
  articles = articles.where(public_account_id: options[:public_account_id]) unless options[:public_account_id].blank?
  articles = articles.where("weixin_media_articles.tag like ?", "%#{options[:tag]}%") unless options[:tag].blank?
  unless options[:start_date].blank?
    start_date = options[:start_date].to_time
    start_date = start_date.change(hour: 0, min:0, sec:0)
    articles = articles.where("weixin_media_articles.created_at >= ?", start_date)
  end
  unless options[:end_date].blank?
    end_date = options[:end_date].to_time
    end_date = end_date.change(hour: 23, min:59, sec:59)
    articles = articles.where("weixin_media_articles.created_at <= ?", end_date)
  end
  articles
end

.create_media_article(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/eric_weixin/media_article.rb', line 15

def self.create_media_article options
  options = get_arguments_options options, [:tag, :thumb_media_id, :author, :title,
                                            :digest, :show_cover_pic, :is_first_article,
                                            :content, :content_source_url, :public_account_id],
                                  show_cover_pic: true, is_first_article: false
  transaction do
    media_article = ::EricWeixin::MediaArticle.new options
    media_article.save!
    media_article
  end
end

Instance Method Details

#update_media_article(options) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/models/eric_weixin/media_article.rb', line 27

def update_media_article options
  options = EricWeixin::MediaArticle.get_arguments_options options, [:tag, :thumb_media_id, :author, :title,
                                                                     :digest, :show_cover_pic, :is_first_article,
                                                                     :content, :content_source_url, :public_account_id]
  EricWeixin::MediaArticle.transaction do
    self.update! options
    self
  end
end