Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feedbin [![Build Status](https://travis-ci.org/ColbyAley/feedbin.png?branch=master)](https://travis-ci.org/ColbyAley/feedbin)
===

A simple Ruby wrapper for v2 of the [Feedbin.me](http://feedbin.me) REST [API](https://github.com/feedbin/feedbin-api). Includes functionality for retrieving entries and subscribing to feeds.
A simple Ruby wrapper for v2 of the [Feedbin.com](http://feedbin.com) REST [API](https://github.com/feedbin/feedbin-api). Includes functionality for retrieving entries and subscribing to feeds.

This is an unoficial gem, and is not affiliated with Feedbin.

Expand Down
46 changes: 32 additions & 14 deletions lib/feedbin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,48 @@ def initialize(email, password)
# Entries

def entries(options = {})
HTTParty.get("https://api.feedbin.me/v2/entries.json", query: options, basic_auth: basic_auth)
HTTParty.get("https://api.feedbin.com/v2/entries.json", query: options, basic_auth: basic_auth)
end

def entries_for_feed(id)
HTTParty.get("https://api.feedbin.me/v2/feeds/#{id}/entries.json", basic_auth: basic_auth)
def entries_for_feed(id, options = {})
HTTParty.get(
"https://api.feedbin.com/v2/feeds/#{id}/entries.json",
query:options,
basic_auth: basic_auth
)
end

def entry(id)
HTTParty.get("https://api.feedbin.me/v2/entries/#{id}.json", basic_auth: basic_auth)
HTTParty.get("https://api.feedbin.com/v2/entries/#{id}.json", basic_auth: basic_auth)
end

def unread_entries
HTTParty.get("https://api.feedbin.me/v2/unread_entries.json", basic_auth: basic_auth)
HTTParty.get("https://api.feedbin.com/v2/unread_entries.json", basic_auth: basic_auth)
end

def star(id)
HTTParty.post("https://api.feedbin.me/v2/starred_entries.json",
HTTParty.post("https://api.feedbin.com/v2/starred_entries.json",
body: { 'starred_entries' => id }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: basic_auth).code
end

def unstar(id)
HTTParty.post("https://api.feedbin.me/v2/starred_entries/delete.json",
HTTParty.post("https://api.feedbin.com/v2/starred_entries/delete.json",
body: { 'starred_entries' => id }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: basic_auth).code
end

def mark_as_read(id)
HTTParty.post("https://api.feedbin.me/v2/unread_entries/delete.json",
HTTParty.post("https://api.feedbin.com/v2/unread_entries/delete.json",
body: { 'unread_entries' => id }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: basic_auth).code
end

def mark_as_unread(id)
HTTParty.post("https://api.feedbin.me/v2/unread_entries.json",
HTTParty.post("https://api.feedbin.com/v2/unread_entries.json",
body: { 'unread_entries' => id }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: basic_auth).code
Expand All @@ -58,28 +62,42 @@ def mark_as_unread(id)
# Feeds

def feed(id)
HTTParty.get("https://api.feedbin.me/v2/feeds/#{id}.json", basic_auth: basic_auth)
HTTParty.get("https://api.feedbin.com/v2/feeds/#{id}.json", basic_auth: basic_auth)
end

# Tags

def tags
HTTParty.get("https://api.feedbin.com/v2/tags.json", basic_auth: basic_auth)
end

def tagging(id)
HTTParty.get("https://api.feedbin.com/v2/taggings/#{id}.json", basic_auth: basic_auth)
end

def taggings
HTTParty.get('https://api.feedbin.com/v2/taggings.json', basic_auth: basic_auth)
end

# Subscriptions

def subscribe(url)
HTTParty.post("https://api.feedbin.me/v2/subscriptions.json",
HTTParty.post("https://api.feedbin.com/v2/subscriptions.json",
body: { 'feed_url' => url }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: basic_auth).code
end

def unsubscribe(id)
HTTParty.delete("https://api.feedbin.me/v2/subscriptions/#{id}.json", basic_auth: basic_auth).code
HTTParty.delete("https://api.feedbin.com/v2/subscriptions/#{id}.json", basic_auth: basic_auth).code
end

def subscriptions(options = {})
if options[:since]
resp = HTTParty.get("https://api.feedbin.me/v2/subscriptions.json", query: { since: options[:since] }, basic_auth: basic_auth)
resp = HTTParty.get("https://api.feedbin.com/v2/subscriptions.json", query: { since: options[:since] }, basic_auth: basic_auth)
return resp == [] ? resp : 'There have been no subscriptions since this date.'.to_json unless resp.code != 200
else
HTTParty.get("https://api.feedbin.me/v2/subscriptions.json", basic_auth: basic_auth)
HTTParty.get("https://api.feedbin.com/v2/subscriptions.json", basic_auth: basic_auth)
end
end

Expand Down
48 changes: 40 additions & 8 deletions spec/feedbin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,84 @@

describe '#entries' do
it 'should get entries and return a 200' do
stub_request(:get, "https://email:[email protected]/v2/entries.json?").to_return(status: 200)
stub_request(:get, "https://api.feedbin.com/v2/entries.json?")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.entries.code).to eq(200)
end

it 'should return a 200 when parameter is passed' do
stub_request(:get, "https://email:[email protected]/v2/entries.json?read=false").to_return(status: 200)
stub_request(:get, "https://api.feedbin.com/v2/entries.json?read=false")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.entries(read: false).code).to eq(200)
end
end

describe '#entries_for_feed' do
it 'should get entries for a feed and return a 200' do
stub_request(:get, "https://email:[email protected]/v2/feeds/42/entries.json").to_return(status: 200)
stub_request(:get, "https://api.feedbin.com/v2/feeds/42/entries.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.entries_for_feed(42).code).to eq(200)
end
end

describe '#tags' do
it 'should get tags and return a 200' do
stub_request(:get, "https://api.feedbin.com/v2/tags.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.tags.code).to eq(200)
end
end

describe '#tagging' do
it 'should get a tagging and return a 200' do
stub_request(:get, "https://api.feedbin.com/v2/taggings/42.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.tagging(42).code).to eq(200)
end
end

describe '#taggings' do
it 'should get taggings and return a 200' do
stub_request(:get, "https://api.feedbin.com/v2/taggings.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.taggings.code).to eq(200)
end
end

describe '#subscriptions' do
it 'should get subscriptions and return a 200' do
stub_request(:get, "https://email:[email protected]/v2/subscriptions.json").to_return(status: 200)
stub_request(:get, "https://api.feedbin.com/v2/subscriptions.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.subscriptions.code).to eq(200)
end
end

describe '#unsubscribe' do
it 'should unsubscribe and return a 204' do
stub_request(:delete, "https://email:[email protected]/v2/subscriptions/260815.json").to_return(status: 204)
stub_request(:delete, "https://api.feedbin.com/v2/subscriptions/260815.json")
.with(basic_auth: ['email', 'password']).to_return(status: 204)
expect(@feedbin.unsubscribe(260815)).to eq(204)
end
end

describe '#feed' do
it 'should get feed and return a 200' do
stub_request(:get, "https://email:[email protected]/v2/feeds/1.json").to_return(status: 200)
stub_request(:get, "https://api.feedbin.com/v2/feeds/1.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.feed(1).code).to eq(200)
end
end

describe '#star' do
it 'should star a post and return a 200' do
stub_request(:post, "https://email:[email protected]/v2/starred_entries.json").to_return(status: 200)
stub_request(:post, "https://api.feedbin.com/v2/starred_entries.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.star(33)).to eq(200)
end

it 'should star an array of posts and return a 200' do
stub_request(:post, "https://email:[email protected]/v2/starred_entries.json").to_return(status: 200)
stub_request(:post, "https://api.feedbin.com/v2/starred_entries.json")
.with(basic_auth: ['email', 'password']).to_return(status: 200)
expect(@feedbin.star([33,44,55,66,77])).to eq(200)
end
end
Expand Down