Skip to content

Commit

Permalink
Added parsing from an XML string to README.
Browse files Browse the repository at this point in the history
  • Loading branch information
arttu committed Jul 26, 2013
1 parent e112176 commit 9f0b7df
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,36 @@ Add to Gemfile

## Usage

# the most basic use case
#### Parse from URL

fp = FeedParser.new(:url => "http://example.com/feed/")
# with sanitizer
feed = fp.parse

Optionally pass HTTP options, see more from the OpenURI documentation: http://apidock.com/ruby/OpenURI

fp = FeedParser.new(:url => "http://example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})

#### Parse from an XML string

fp = FeedParser.new(:feed_xml => "<rss>...</rss>")
feed = fp.parse

#### Use sanitizer

fp = FeedParser.new(:url => "http://example.com/feed/", :sanitizer => MyBestestSanitizer.new)
# sanitizing custom field set
fp = FeedParser.new(:url => "http://example.com/feed/", :sanitizer => MyBestestSanitizer.new, :fields_to_sanitize => [:title, :content])

# retrieve the feed xml and parse it
feed = fp.parse

# using parsed feed in your code

#### Using parsed feed in your code

feed.as_json
# => {:title => "Feed title", :url => "http://example.com/feed/", :items => [{:guid => , :title => , :author => ...}]}

feed.items.each do |feed_item|
pp feed_item
end

# you can also pass http options to be used for the connection
# for available options, check out the OpenURI documentation: http://apidock.com/ruby/OpenURI
fp = FeedParser.new(:url => "http://example.com/feed/", :http => {:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})

If the fetched XML is not a valid RSS or an ATOM feed, a FeedParser::UnknownFeedType is raised in FeedParser#parse.
If the XML is not a valid RSS or an ATOM feed, a FeedParser::UnknownFeedType is raised in FeedParser#parse.

## Running tests

Expand Down

0 comments on commit 9f0b7df

Please sign in to comment.