Skip to content

Commit

Permalink
Retrieve a feed, and unsubscribe from a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
cp committed Aug 22, 2013
1 parent 7b7e9a9 commit bd91b58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Or install it yourself as:
@feedbin.entries
# => (array of entry hashes)

#feedbin.entries(read: false)
# => (an array of unread entries as hashes)

@feedbin.unread_entries
# => (array of unread entry IDs)

Expand Down
20 changes: 15 additions & 5 deletions lib/feedbin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,34 @@ def star(id)
HTTParty.post("https://api.feedbin.me/v2/starred_entries.json",
body: { 'starred_entries' => id }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: { username: @email, password: @password })
basic_auth: { username: @email, password: @password }).code
end

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

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

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

# Feeds

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

# Subscriptions
Expand All @@ -56,7 +62,11 @@ def subscribe(url)
HTTParty.post("https://api.feedbin.me/v2/subscriptions.json",
body: { 'feed_url' => url }.to_json,
headers: { 'Content-Type' => 'application/json' },
basic_auth: { username: @email, password: @password })
basic_auth: { username: @email, password: @password }).code
end

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

def subscriptions(options = {})
Expand Down
18 changes: 16 additions & 2 deletions spec/feedbin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,29 @@
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)
@feedbin.unsubscribe(260815).should == 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)
@feedbin.feed(1).code.should == 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)
@feedbin.star(33).code.should == 200
@feedbin.star(33).should == 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)
@feedbin.star([33,44,55,66,77]).code.should == 200
@feedbin.star([33,44,55,66,77]).should == 200
end
end
end

0 comments on commit bd91b58

Please sign in to comment.