close
The Wayback Machine - https://web.archive.org/web/20221026060345/https://github.com/DougEverly/jsonfeed.cr
Skip to content

DougEverly/jsonfeed.cr

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

jsonfeed

Crystal implementation of JSONFeed spec.

Installation

Add this to your application's shard.yml:

dependencies:
  jsonfeed:
    github: DougEverly/jsonfeed

Usage

See examples/ and spec/ for usage examples.

Loading JSONFeed

require "jsonfeed"

url = "https://jsonfeed.org/feed.json"
r = HTTP::Client.get url
r.body

feed = JSONFeed.from_json(r.body)

pp feed

Generating JSONFeed

Using the Builder

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

Using the Initializer

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

Development

TODO

  • Extensions not yet supported. Ideally would use crystal-lang/crystal#4411.
  • Enforce content_html and content_text: one or both must be present
  • Create a builder for JSONFeed::Feed.

Contributing

  1. Fork it ( https://github.com/DougEverly/jsonfeed/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

About

Crystal Implemntation of JSON Feed

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published