Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 41dbbb5d819102b5eb7ebdf5029c1ccda8ad073d @zedtux committed Apr 21, 2012
1 .gemrc
@@ -0,0 +1 @@
+:ssl_verify_mode: 0
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1 @@
+alone for github
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format documentation
1 .rvmrc
@@ -0,0 +1 @@
+rvm --create use 1.9.3@urss > /dev/null
@@ -0,0 +1,7 @@
+rvm:
+ - ruby-head
+ - jruby
+ - 1.9.3
+ - 1.8.7
+ - 1.9.2
+ - ree
@@ -0,0 +1,9 @@
+source "https://rubygems.org"
+
+# Specify your gem's dependencies in urss.gemspec
+gemspec
+
+gem "rake"
+gem "rspec"
+gem "webmock"
+gem "simplecov"
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 zedtux
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
+# Urss [![Build Status](https://secure.travis-ci.org/zedtux/urss.png)](http://travis-ci.org/zedtux/urss) [![Dependency Status](https://gemnasium.com/zedtux/urss.png)](http://gemnasium.com/zedtux/urss)
+
+URSS or Ultra RSS is another ruby library to parse Feed RSS that has been created because there was no existing one that support multiple media:content or media:thumbnail.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'urss'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install urss
+
+## Usage
+
+````ruby
+rss = Urss.at("http://www.ruby-lang.org/en/feeds/news.rss")
+rss.title
+#=> "Ruby News"
+rss.url
+#=> "http://www.ruby-lang.org/en/feeds/news.rss/"
+rss.description
+#=> "The latest news from Ruby-Lang.org."
+rss.updated_at
+#=> ""
+rss.entries.size
+#=> 10
+rss.entries.first.title
+#=> "Ruby 1.9.3-p194 is released"
+rss.entries.first.created_at
+#=> "Fri, 20 Apr 2012 03:19:04 GMT"
+rss.entries.first.url
+#=> "http://www.ruby-lang.org/en/news/2012/04/20/ruby-1-9-3-p194-is-released/"
+````
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,8 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+
+require "rspec/core/rake_task"
+
+RSpec::Core::RakeTask.new("spec")
+
+task :default => :spec
@@ -0,0 +1,17 @@
+require "urss/version"
+require "open-uri"
+require "nokogiri"
+
+require "urss/rss"
+require "urss/entry"
+
+module Urss
+ class NotANokogiriInstance < StandardError; end
+
+ def self.at(url)
+ raise ArgumentError if url.nil? || !url.is_a?(String) || url.empty?
+
+ Rss.build(Nokogiri::XML(open(url)))
+ end
+
+end
@@ -0,0 +1,33 @@
+class Urss::Entry
+
+ # ~~~~ Attributes ~~~~
+ attr_accessor :title, :url, :comments_url, :created_at, :author, :categories, :content
+
+ # ~~~~ Class methods ~~~~
+ def self.build(nokogiri_instance)
+ raise Urss::NotANokogiriInstance unless nokogiri_instance.is_a?(Nokogiri::XML::Element)
+
+ entry = self.new
+ entry.title = nokogiri_instance.xpath(".//*[local-name()='title']").text
+ entry.url = nokogiri_instance.xpath(".//*[local-name()='link']").text
+ entry.comments_url = nokogiri_instance.xpath(".//*[local-name()='comments']").text
+ entry.created_at = nokogiri_instance.xpath(".//*[local-name()='pubDate']").text
+ entry.author = nokogiri_instance.xpath(".//*[local-name()='creator']").text
+ entry.categories = nokogiri_instance.search("category").collect(&:text).join(", ")
+ entry.content = nokogiri_instance.xpath(".//*[local-name()='description']").text
+
+ entry
+ end
+
+ # ~~~~ Instance methods ~~~~
+ def initialize
+ self.title = nil
+ self.url = nil
+ self.comments_url = nil
+ self.created_at = nil
+ self.author = nil
+ self.categories = []
+ self.content = nil
+ end
+
+end
@@ -0,0 +1,30 @@
+class Urss::Rss
+
+ # ~~~~ Attributes ~~~~
+ attr_accessor :title, :url, :description, :updated_at, :entries
+
+ # ~~~~ Class methods ~~~~
+ def self.build(nokogiri_instance)
+ raise Urss::NotANokogiriInstance unless nokogiri_instance.is_a?(Nokogiri::XML::Document)
+
+ rss = self.new
+ rss.title = nokogiri_instance.xpath("//channel/*[local-name()='title']").text
+ rss.url = nokogiri_instance.xpath("//channel/*[local-name()='link']").text
+ rss.description = nokogiri_instance.xpath("//channel/*[local-name()='description']").text
+ rss.updated_at = nokogiri_instance.xpath("//channel/*[local-name()='pubDate']").text
+
+ nokogiri_instance.xpath("//item").each {|item| rss.entries << Urss::Entry.build(item)}
+
+ rss
+ end
+
+ # ~~~~ Instance methods ~~~~
+ def initialize
+ self.title = nil
+ self.url = nil
+ self.description = nil
+ self.updated_at = nil
+ self.entries = []
+ end
+
+end
@@ -0,0 +1,3 @@
+module Urss
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,17 @@
+require "simplecov"
+SimpleCov.start
+
+require "rubygems"
+require "bundler/setup"
+
+# require "webmock/rspec" is not working. So:
+require "webmock"
+include WebMock::API
+
+require "support/webmocks"
+
+require "urss"
+
+RSpec.configure do |config|
+
+end
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <rss:title type="text">dive into mark</title>
+ <subtitle type="html">
+ A &lt;em&gt;lot&lt;/em&gt; of effort
+ went into making this effortless
+ </subtitle>
+ <updated>2005-07-31T12:29:29Z</updated>
+ <id>tag:example.org,2003:3</id>
+ <link rel="alternate" type="text/html"
+ hreflang="en" href="http://example.org/"/>
+ <link rel="self" type="application/atom+xml"
+ href="http://example.org/feed.atom"/>
+ <rights>Copyright (c) 2003, Mark Pilgrim</rights>
+ <generator uri="http://www.example.com/" version="1.0">
+ Example Toolkit
+ </generator>
+ <entry>
+ <title>Atom draft-07 snapshot</title>
+ <link rel="alternate" type="text/html"
+ href="http://example.org/2005/04/02/atom"/>
+ <link rel="enclosure" type="audio/mpeg" length="1337"
+ href="http://example.org/audio/ph34r_my_podcast.mp3"/>
+ <id>tag:example.org,2003:3.2397</id>
+ <updated>2005-07-31T12:29:29Z</updated>
+ <published>2003-12-13T08:29:29-04:00</published>
+ <author>
+ <name>Mark Pilgrim</name>
+ <uri>http://example.org/</uri>
+ <email>f8dy@example.com</email>
+ </author>
+ <contributor>
+ <name>Sam Ruby</name>
+ </contributor>
+ <contributor>
+ <name>Joe Gregorio</name>
+ </contributor>
+ <content type="xhtml" xml:lang="en"
+ xml:base="http://diveintomark.org/">
+ <div xmlns="http://www.w3.org/1999/xhtml">
+ <p><i>[Update: The Atom draft is finished.]</i></p>
+ </div>
+ </content>
+ </entry>
+</feed>
Oops, something went wrong.

0 comments on commit 41dbbb5

Please sign in to comment.