Class: QiitaPicks::Generator
- Inherits:
-
Object
- Object
- QiitaPicks::Generator
- Defined in:
- lib/qiita_picks/generator.rb
Instance Method Summary collapse
- #generate_from_email_weekly_popular(opts = {}) ⇒ Object
- #generate_from_email_weekly_stocked(opts = {}) ⇒ Object
- #generate_from_list_hatebu_popular(opts = {}) ⇒ Object
- #generate_from_list_hatebu_recent(opts = {}) ⇒ Object
- #generate_from_list_tag_items(tag, opts = {}) ⇒ Object
- #generate_from_list_user_items(username, opts = {}) ⇒ Object
- #generate_from_list_user_stocks(username, opts = {}) ⇒ Object
- #generate_from_url(url = [], opts = {}) ⇒ Object
-
#initialize(params = {}) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(params = {}) ⇒ Generator
Returns a new instance of Generator.
9 10 11 12 13 14 15 16 |
# File 'lib/qiita_picks/generator.rb', line 9 def initialize(params={}) params[:email] ||= '' params[:password] ||= '' params[:access_token] ||= '' @email = params[:email] @mailer = QiitaPicks::Mailer.new(params[:email], params[:password]) @qiita = Qiita::Client.new(access_token: params[:access_token]) end |
Instance Method Details
#generate_from_email_weekly_popular(opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/qiita_picks/generator.rb', line 23 def generate_from_email_weekly_popular(opts={}) opts[:limit] ||= 1 opts[:deliver] ||= false @mailer.weekly_popular(opts[:limit]).each do |mail| @basename = mail[:date].strftime QiitaPicks::FILE_BASENAME_EMAIL_WEEKLY_POPULAR @subject = mail[:date].strftime QiitaPicks::EMAIL_SUBJECT_EMAIL_WEEKLY_POPULAR opts[:deliver] ? generate_and_deliver(url: mail[:url]) : generate(url: mail[:url]) end end |
#generate_from_email_weekly_stocked(opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/qiita_picks/generator.rb', line 33 def generate_from_email_weekly_stocked(opts={}) opts[:limit] ||= 1 opts[:deliver] ||= false @mailer.weekly_stocked(opts[:limit]).each do |mail| @basename = mail[:date].strftime QiitaPicks::FILE_BASENAME_EMAIL_WEEKLY_STOCKED @subject = mail[:date].strftime(QiitaPicks::EMAIL_SUBJECT_EMAIL_WEEKLY_STOCKED).gsub(/<SUBJECT>/, mail[:subject]) opts[:deliver] ? generate_and_deliver(url: mail[:url]) : generate(url: mail[:url]) end end |
#generate_from_list_hatebu_popular(opts = {}) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/qiita_picks/generator.rb', line 73 def generate_from_list_hatebu_popular(opts={}) opts[:deliver] ||= false @basename = Time.now.strftime QiitaPicks::FILE_BASENAME_LIST_HATEBU_POPULAR @subject = Time.now.strftime QiitaPicks::EMAIL_SUBJECT_LIST_HATEBU_POPULAR url = QiitaPicks::Picker.hatebu_bookmark_url opts[:tag], :popular opts[:deliver] ? generate_and_deliver(url: url) : generate(url: url) end |
#generate_from_list_hatebu_recent(opts = {}) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/qiita_picks/generator.rb', line 81 def generate_from_list_hatebu_recent(opts={}) opts[:deliver] ||= false @basename = Time.now.strftime QiitaPicks::FILE_BASENAME_LIST_HATEBU_RECENT @subject = Time.now.strftime QiitaPicks::EMAIL_SUBJECT_LIST_HATEBU_RECENT url = QiitaPicks::Picker.hatebu_bookmark_url opts[:tag], :recent opts[:deliver] ? generate_and_deliver(url: url) : generate(url: url) end |
#generate_from_list_tag_items(tag, opts = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/qiita_picks/generator.rb', line 43 def generate_from_list_tag_items(tag, opts={}) opts[:page] ||= 1 opts[:per_page] ||= 20 opts[:deliver] ||= false @basename = Time.now.strftime QiitaPicks::FILE_BASENAME_LIST_TAG_ITEMS @subject = Time.now.strftime(QiitaPicks::EMAIL_SUBJECT_LIST_TAG_ITEMS).gsub(/<TAG>/, tag.capitalize) items = @qiita.list_tag_items(tag, page: opts[:page], per_page: opts[:per_page]).body opts[:deliver] ? generate_and_deliver(items: items) : generate(items: items) end |
#generate_from_list_user_items(username, opts = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/qiita_picks/generator.rb', line 53 def generate_from_list_user_items(username, opts={}) opts[:page] ||= 1 opts[:per_page] ||= 20 opts[:deliver] ||= false @basename = Time.now.strftime QiitaPicks::FILE_BASENAME_LIST_USER_ITEMS @subject = Time.now.strftime(QiitaPicks::EMAIL_SUBJECT_LIST_USER_ITEMS).gsub(/<USERNAME>/, username) items = @qiita.list_user_items(username, page: opts[:page], per_page: opts[:per_page]).body opts[:deliver] ? generate_and_deliver(items: items) : generate(items: items) end |
#generate_from_list_user_stocks(username, opts = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/qiita_picks/generator.rb', line 63 def generate_from_list_user_stocks(username, opts={}) opts[:page] ||= 1 opts[:per_page] ||= 20 opts[:deliver] ||= false @basename = Time.now.strftime QiitaPicks::FILE_BASENAME_LIST_USER_STOCKS @subject = Time.now.strftime(QiitaPicks::EMAIL_SUBJECT_LIST_USER_STOCKS).gsub(/<USERNAME>/, username) items = @qiita.list_user_stocks(username, page: opts[:page], per_page: opts[:per_page]).body opts[:deliver] ? generate_and_deliver(items: items) : generate(items: items) end |
#generate_from_url(url = [], opts = {}) ⇒ Object
18 19 20 21 |
# File 'lib/qiita_picks/generator.rb', line 18 def generate_from_url(url=[], opts={}) opts[:deliver] ||= false opts[:deliver] ? generate_and_deliver(url: url) : generate(url: url) end |