-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
41 lines (31 loc) · 859 Bytes
/
app.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
require 'bundler'
require 'open-uri'
Bundler.require
require_relative 'config/mailgun'
require_relative 'config/datamapper'
require_relative 'models/post'
# Just do nothing if someone hits the app's URL
get '/' do
end
def send_notification
@mg_client.send_message "#{ENV['MAILGUN_FROM'].split('@')[1]}", @message_params
end
def update_freddie(new_freddie)
post_to_update = Post.last
post_to_update.update(:title => new_freddie)
end
def get_freddie
doc = Nokogiri::HTML(open("http://www.mailchimp.com/replyall"))
@freddies = doc.css("div.freddie")
@active_freddie = @freddies.first['id']
if @active_freddie != old_freddie
send_notification # Send notification through Mailgun
update_freddie(@active_freddie)
else
p "No new Freddie yet"
end
end
def old_freddie
@freddie = Post.last
return @freddie['title']
end