订阅功能, 由于 sendcloud 的问题未测试
This commit is contained in:
parent
23f07094bf
commit
2ec5f8e82a
3
Gemfile
3
Gemfile
|
@ -26,6 +26,8 @@ gem 'nokogiri'
|
|||
gem 'angularjs-rails'
|
||||
gem 'figaro'
|
||||
gem 'rqrcode-with-patches', require: 'rqrcode'
|
||||
gem 'sidekiq'
|
||||
gem 'rest-client'
|
||||
|
||||
group :development do
|
||||
gem 'quiet_assets'
|
||||
|
@ -39,6 +41,7 @@ group :test do
|
|||
gem 'capybara'
|
||||
gem 'mongoid-rspec', :require => false
|
||||
gem 'database_cleaner'
|
||||
gem 'rspec-sidekiq'
|
||||
end
|
||||
|
||||
group :test, :development do
|
||||
|
|
|
@ -9,7 +9,7 @@ class Comment
|
|||
belongs_to :post
|
||||
|
||||
validates :name, presence: true
|
||||
validates :email, confirmation: true,:format => /@/
|
||||
validates :email, presence: true,:format => /@/
|
||||
validates :content, presence: true
|
||||
validates_presence_of :post_id
|
||||
end
|
||||
|
|
|
@ -22,6 +22,12 @@ class Post
|
|||
validates :content, :presence=>true, :length => { :minimum=> 30 }
|
||||
validates :type, :presence=>true, :inclusion => { :in => [ TECH, LIFE, CREATOR ] }
|
||||
|
||||
after_create do
|
||||
unless ENV['SENDCLOUD_USER']
|
||||
NewPostWorker.perform_async(self.title, Subscribe.subscribe_list)
|
||||
end
|
||||
end
|
||||
|
||||
def content_html
|
||||
self.class.render_html(self.content)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class Subscribe
|
||||
include Mongoid::Document
|
||||
field :email, type: String
|
||||
field :enable, type: Mongoid::Boolean, default: true
|
||||
|
||||
validates :email, presence: true, format: /@/
|
||||
|
||||
def self.subscribe_list
|
||||
Subscribe.all.map(&:email).join(";")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,28 @@
|
|||
class NewPostWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(title, to)
|
||||
send_mail(title, to)
|
||||
end
|
||||
|
||||
def send_mail(title, to)
|
||||
response = RestClient.post "https://sendcloud.sohu.com/webapi/mail.send.xml",
|
||||
{
|
||||
:api_user => "postmaster@#{ENV['SENDCLOUD_USER']}.sendcloud.org",
|
||||
:api_key => ENV['SENDCLOUD_PASSWORD'],
|
||||
:from => ENV['SENDCLOUD_FROM'],
|
||||
:fromname => ENV['SENDCLOUD_FROMNAME'],
|
||||
:to => to,
|
||||
:subject => "#{ENV['SITE_NAME']} 又写了新博客"
|
||||
:html => <<-EOF
|
||||
<p>hi, 我是李亚飞, 很高兴告诉你:</p>
|
||||
|
||||
<p>#{ENV['SITE_NAME']} 新博客到了: #{title}</p>
|
||||
|
||||
<p>具体内容请访问: http://yafeilee.me</p>
|
||||
EOF
|
||||
}
|
||||
return response
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :subscribe do
|
||||
email "MyString"
|
||||
enable false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Subscribe do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue