Skip to content

Commit bd91b58

Browse files
committed
Retrieve a feed, and unsubscribe from a subscription
1 parent 7b7e9a9 commit bd91b58

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Or install it yourself as:
2727
@feedbin.entries
2828
# => (array of entry hashes)
2929

30+
#feedbin.entries(read: false)
31+
# => (an array of unread entries as hashes)
32+
3033
@feedbin.unread_entries
3134
# => (array of unread entry IDs)
3235

lib/feedbin.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,34 @@ def star(id)
2626
HTTParty.post("https://api.feedbin.me/v2/starred_entries.json",
2727
body: { 'starred_entries' => id }.to_json,
2828
headers: { 'Content-Type' => 'application/json' },
29-
basic_auth: { username: @email, password: @password })
29+
basic_auth: { username: @email, password: @password }).code
3030
end
3131

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

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

4646
def mark_as_unread(id)
4747
HTTParty.post("https://api.feedbin.me/v2/unread_entries.json",
4848
body: { 'unread_entries' => id }.to_json,
4949
headers: { 'Content-Type' => 'application/json' },
50-
basic_auth: { username: @email, password: @password })
50+
basic_auth: { username: @email, password: @password }).code
51+
end
52+
53+
# Feeds
54+
55+
def feed(id)
56+
HTTParty.get("https://api.feedbin.me/v2/feeds/#{id}.json", basic_auth: { username: @email, password: @password })
5157
end
5258

5359
# Subscriptions
@@ -56,7 +62,11 @@ def subscribe(url)
5662
HTTParty.post("https://api.feedbin.me/v2/subscriptions.json",
5763
body: { 'feed_url' => url }.to_json,
5864
headers: { 'Content-Type' => 'application/json' },
59-
basic_auth: { username: @email, password: @password })
65+
basic_auth: { username: @email, password: @password }).code
66+
end
67+
68+
def unsubscribe(id)
69+
HTTParty.delete("https://api.feedbin.me/v2/subscriptions/#{id}.json", basic_auth: { username: @email, password: @password }).code
6070
end
6171

6272
def subscriptions(options = {})

spec/feedbin_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,29 @@
2525
end
2626
end
2727

28+
describe '.unsubscribe' do
29+
it 'should unsubscribe and return a 204' do
30+
stub_request(:delete, "https://email:password@api.feedbin.me/v2/subscriptions/260815.json").to_return(status: 204)
31+
@feedbin.unsubscribe(260815).should == 204
32+
end
33+
end
34+
35+
describe '.feed' do
36+
it 'should get feed and return a 200' do
37+
stub_request(:get, "https://email:password@api.feedbin.me/v2/feeds/1.json").to_return(status: 200)
38+
@feedbin.feed(1).code.should == 200
39+
end
40+
end
41+
2842
describe '.star' do
2943
it 'should star a post and return a 200' do
3044
stub_request(:post, "https://email:password@api.feedbin.me/v2/starred_entries.json").to_return(status: 200)
31-
@feedbin.star(33).code.should == 200
45+
@feedbin.star(33).should == 200
3246
end
3347

3448
it 'should star an array of posts and return a 200' do
3549
stub_request(:post, "https://email:password@api.feedbin.me/v2/starred_entries.json").to_return(status: 200)
36-
@feedbin.star([33,44,55,66,77]).code.should == 200
50+
@feedbin.star([33,44,55,66,77]).should == 200
3751
end
3852
end
3953
end

0 commit comments

Comments
 (0)