@@ -40,3 +40,4 @@ gem 'mongo_mapper' | |||||
gem 'bson_ext' | gem 'bson_ext' | ||||
gem 'haml-rails' | gem 'haml-rails' | ||||
gem 'mm-multi-parameter-attributes' | gem 'mm-multi-parameter-attributes' | ||||
gem 'feedzirra' |
@@ -40,9 +40,20 @@ GEM | |||||
coffee-script-source | coffee-script-source | ||||
execjs | execjs | ||||
coffee-script-source (1.3.3) | coffee-script-source (1.3.3) | ||||
curb (0.7.18) | |||||
erubis (2.7.0) | erubis (2.7.0) | ||||
execjs (1.4.0) | execjs (1.4.0) | ||||
multi_json (~> 1.0) | multi_json (~> 1.0) | ||||
feedzirra (0.0.31) | |||||
activesupport (>= 3.0.8) | |||||
builder (~> 3.0.0) | |||||
curb (~> 0.7.15) | |||||
i18n (>= 0.5.0) | |||||
loofah (~> 1.0.0) | |||||
nokogiri (~> 1.4.4) | |||||
rake (>= 0.9.2) | |||||
rdoc (~> 3.8) | |||||
sax-machine (~> 0.0.20) | |||||
haml (3.1.6) | haml (3.1.6) | ||||
haml-rails (0.3.4) | haml-rails (0.3.4) | ||||
actionpack (~> 3.0) | actionpack (~> 3.0) | ||||
@@ -56,6 +67,8 @@ GEM | |||||
railties (>= 3.2.0, < 5.0) | railties (>= 3.2.0, < 5.0) | ||||
thor (~> 0.14) | thor (~> 0.14) | ||||
json (1.7.3) | json (1.7.3) | ||||
loofah (1.0.0) | |||||
nokogiri (>= 1.3.3) | |||||
mail (2.4.4) | mail (2.4.4) | ||||
i18n (>= 0.4.0) | i18n (>= 0.4.0) | ||||
mime-types (~> 1.16) | mime-types (~> 1.16) | ||||
@@ -71,6 +84,7 @@ GEM | |||||
activesupport (~> 3.0) | activesupport (~> 3.0) | ||||
plucky (~> 0.4.0) | plucky (~> 0.4.0) | ||||
multi_json (1.3.6) | multi_json (1.3.6) | ||||
nokogiri (1.4.7) | |||||
plucky (0.4.4) | plucky (0.4.4) | ||||
mongo (~> 1.5) | mongo (~> 1.5) | ||||
polyglot (0.3.3) | polyglot (0.3.3) | ||||
@@ -104,6 +118,8 @@ GEM | |||||
railties (~> 3.2.0) | railties (~> 3.2.0) | ||||
sass (>= 3.1.10) | sass (>= 3.1.10) | ||||
tilt (~> 1.3) | tilt (~> 1.3) | ||||
sax-machine (0.0.20) | |||||
nokogiri (> 0.0.0) | |||||
sprockets (2.1.3) | sprockets (2.1.3) | ||||
hike (~> 1.2) | hike (~> 1.2) | ||||
rack (~> 1.0) | rack (~> 1.0) | ||||
@@ -124,6 +140,7 @@ PLATFORMS | |||||
DEPENDENCIES | DEPENDENCIES | ||||
bson_ext | bson_ext | ||||
coffee-rails (~> 3.2.1) | coffee-rails (~> 3.2.1) | ||||
feedzirra | |||||
haml-rails | haml-rails | ||||
jquery-rails | jquery-rails | ||||
mm-multi-parameter-attributes | mm-multi-parameter-attributes | ||||
@@ -45,7 +45,7 @@ class FeedsController < ApplicationController | |||||
respond_to do |format| | respond_to do |format| | ||||
if @feed.save | if @feed.save | ||||
format.html { redirect_to'/', notice: 'Feed was successfully created.' } | |||||
format.html { redirect_to '/', notice: 'Feed was successfully created.' } | |||||
format.json { render json: @feed, status: :created, location: @feed } | format.json { render json: @feed, status: :created, location: @feed } | ||||
else | else | ||||
format.html { render action: "new" } | format.html { render action: "new" } | ||||
@@ -81,4 +81,10 @@ class FeedsController < ApplicationController | |||||
format.json { head :no_content } | format.json { head :no_content } | ||||
end | end | ||||
end | end | ||||
def fetch | |||||
@feed = Feed.find(params[:id]) | |||||
@feed.get | |||||
redirect_to '/', notice: 'Feed fetched OK' | |||||
end | |||||
end | end |
@@ -1,11 +1,52 @@ | |||||
class Feed | class Feed | ||||
include MongoMapper::Document | include MongoMapper::Document | ||||
key :title, String, :default => "[New feed - hasn't been fetched yet]" | |||||
key :link, String | |||||
key :last_fetched, Time, :default => nil | |||||
key :title, String, :default => "[New feed - hasn't been fetched yet]" | |||||
key :feed_url, String # The URL of the RSS feed, not the website that owns it | |||||
key :url, String # The URL of website. Called "link" in RSS 2.0 | |||||
key :description, String | |||||
key :last_fetched, Time, :default => nil | |||||
timestamps! | timestamps! | ||||
many :posts | |||||
validates :title, :presence => true | validates :title, :presence => true | ||||
validates_format_of :link, :with => URI::regexp(%w(http https)), :message => "must be a valid URL" | |||||
validates_format_of :feed_url, :with => URI::regexp(%w(http https)), :message => "must be a valid URL" | |||||
after_create :get | |||||
# Fetch and parse feed contents from web | |||||
def get | |||||
Feedzirra::Feed.add_common_feed_entry_element('georss:point', :as => :point) | |||||
feed = Feedzirra::Feed.fetch_and_parse(@feed_url) | |||||
self.set( | |||||
:title => feed.title, | |||||
:url => feed.url, | |||||
:description => feed.description, | |||||
:last_fetched => Time.now | |||||
) | |||||
feed.entries.each do |e| | |||||
# puts "#{e.title} point: #{e.point}" | |||||
latlng = e.point.split(' ') | |||||
self.posts << Post.create( | |||||
:title => e.title, | |||||
:url => e.url, | |||||
:author => e.author, | |||||
:summary => e.summary, | |||||
:content => e.content, | |||||
:published => e.published, | |||||
:loc => { | |||||
:lng => latlng[1].to_f, | |||||
:lat => latlng[0].to_f | |||||
} | |||||
) | |||||
end | |||||
end | |||||
end | end |
@@ -0,0 +1,14 @@ | |||||
class Post | |||||
include MongoMapper::Document | |||||
key :title, String | |||||
key :url, String | |||||
key :author, String | |||||
key :summary, String | |||||
key :content, String | |||||
key :published, Time | |||||
key :loc, Hash # { lng, lat } | |||||
timestamps! | |||||
belongs_to :feed | |||||
end |
@@ -14,7 +14,7 @@ | |||||
= f.text_field :title | = f.text_field :title | ||||
.field | .field | ||||
= f.label "URL" | = f.label "URL" | ||||
= f.text_field :link, :size => 120 | |||||
= f.text_field :feed_url, :size => 120 | |||||
= f.submit 'Save' | = f.submit 'Save' | ||||
-# | -# | ||||
.field | .field | ||||
@@ -3,8 +3,9 @@ | |||||
%table | %table | ||||
%tr | %tr | ||||
%th Title | %th Title | ||||
%th Link | |||||
%th Last fetched | |||||
%th Feed URL | |||||
%th Posts | |||||
%th Fetched | |||||
%th | %th | ||||
%th | %th | ||||
%th | %th | ||||
@@ -12,7 +13,8 @@ | |||||
- @feeds.each do |feed| | - @feeds.each do |feed| | ||||
%tr | %tr | ||||
%td= link_to feed.title, feed | %td= link_to feed.title, feed | ||||
%td= link_to feed.link, feed.link | |||||
%td= link_to feed.feed_url, feed.feed_url | |||||
%td= feed.posts.size | |||||
%td | %td | ||||
- if feed.last_fetched.nil? | - if feed.last_fetched.nil? | ||||
never | never | ||||
@@ -20,7 +22,7 @@ | |||||
= time_ago_in_words feed.last_fetched | = time_ago_in_words feed.last_fetched | ||||
ago | ago | ||||
%td= link_to 'Edit', edit_feed_path(feed) | %td= link_to 'Edit', edit_feed_path(feed) | ||||
%td= link_to 'Destroy', feed, :confirm => 'Are you sure?', :method => :delete | |||||
%td= link_to 'Delete', feed, :confirm => 'Are you sure?', :method => :delete | |||||
#new_feed | #new_feed | ||||
= render 'form' | = render 'form' |
@@ -0,0 +1,19 @@ | |||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html | |||||
one: | |||||
title: MyString | |||||
url: MyString | |||||
author: MyString | |||||
summary: MyText | |||||
content: MyText | |||||
published: 2012-06-21 12:03:03 | |||||
loc: | |||||
two: | |||||
title: MyString | |||||
url: MyString | |||||
author: MyString | |||||
summary: MyText | |||||
content: MyText | |||||
published: 2012-06-21 12:03:03 | |||||
loc: |
@@ -0,0 +1,7 @@ | |||||
require 'test_helper' | |||||
class PostTest < ActiveSupport::TestCase | |||||
# test "the truth" do | |||||
# assert true | |||||
# end | |||||
end |