-
Notifications
You must be signed in to change notification settings - Fork 22
/
bullish.rb
69 lines (54 loc) · 1.27 KB
/
bullish.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
require './services/email'
require './services/log'
require './editions/morning'
require './editions/afternoon'
require './editions/free'
require './editions/edition'
require './services/sample'
require './services/archive'
require './services/log'
require './services/config'
# buy high sell low
class Bullish
attr_reader :edition
def initialize(edition = Editions::Edition.new)
@edition = edition
end
def self.free_edition
new(Editions::Free.new)
end
def self.morning_edition
new(Editions::Morning.new)
end
def self.afternoon_edition
new(Editions::Afternoon.new)
end
def archive
return unless edition.premium?
subject = edition.subject
content = edition.content
Services::Sample.new.upload(content)
Services::Archive.new.upload(subject, content)
rescue StandardError => e
Services::Log.error(e.message)
end
# send email to subscribers
# retry 3 times when fail
def post
return unless edition.send?
retries ||= 0
Services::Email.new(edition).post && archive
rescue StandardError => e
retries += 1
retry if retries < 3
Services::Log.error(e.message)
raise e
end
def save
edition.save
end
def save_template
edition.save_template
end
end