Crystal implementation of JSONFeed spec.
Add this to your application's shard.yml
:
dependencies:
jsonfeed:
github: DougEverly/jsonfeed
See examples/ and spec/ for usage examples.
require "jsonfeed"
url = "https://jsonfeed.org/feed.json"
r = HTTP::Client.get url
r.body
feed = JSONFeed.from_json(r.body)
pp feed
require "jsonfeed"
feed = JSONFeed::Feed.build(version: "https://jsonfeed.org/version/1", title: "Brent Simmons’s Microblog") do |feed|
feed.user_comment = "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json"
feed.home_page_url = "https://example.org/"
feed.feed_url = "https://example.org/feed.json"
feed.author = JSONFeed::Author.build do |author|
author.name = "Brent Simmons"
author.url = "http://example.org/"
author.avatar = "https://example.org/avatar.png"
end
feed.items << JSONFeed::Item.build(id: "2347259", url: "https://example.org/2347259") do |item|
item.content_text = "Cats are neat. \n\nhttps://example.org/cats"
item.date_published = "2016-02-09T14:22:00-07:00"
end
end
puts feed.to_json
require "jsonfeed"
author = JSONFeed::Author.new(name: "Brent Simmons", url: "http://example.org/", avatar: "https://example.org/avatar.png")
feed = JSONFeed::Feed.new(version: "https://jsonfeed.org/version/1", title: "Brent Simmons’s Microblog", user_comment: "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json", home_page_url: "https://example.org/", feed_url: "https://example.org/feed.json", author: author)
item = JSONFeed::Item.new(id: "2347259", url: "https://example.org/2347259", content_text: "Cats are neat. \n\nhttps://example.org/cats", date_published: "2016-02-09T14:22:00-07:00")
feed << item
puts feed.to_json
- Extensions not yet supported. Ideally would use crystal-lang/crystal#4411.
- Enforce
content_html
andcontent_text
: one or both must be present - Create a builder for JSONFeed::Feed.
- Fork it ( https://github.com/DougEverly/jsonfeed/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- DougEverly Doug Everly - creator, maintainer