From e4081d83183e206d121d01235c75c4c98e99f490 Mon Sep 17 00:00:00 2001 From: Manu Campos Date: Tue, 9 Jan 2018 17:12:28 +0100 Subject: [PATCH 1/5] Update webmock stubbed request After version 2.0.0 Webmock does not match credentials in the userinfo of an url See https://github.com/bblimke/webmock#important-since-version-200-webmock-does-not-match-credentials-provided-in-authorization-header-and-credentials-provided-in-the-userinfo-of-a-url-ie-stub_requestget-userpasswwwexamplecom-does-not-match-a-request-with-credentials-provided-in-the-authorization-header --- spec/feedbin_spec.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/spec/feedbin_spec.rb b/spec/feedbin_spec.rb index 5aaffce..48e8359 100644 --- a/spec/feedbin_spec.rb +++ b/spec/feedbin_spec.rb @@ -8,52 +8,60 @@ describe '#entries' do it 'should get entries and return a 200' do - stub_request(:get, "https://email:password@api.feedbin.me/v2/entries.json?").to_return(status: 200) + stub_request(:get, "https://api.feedbin.me/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:password@api.feedbin.me/v2/entries.json?read=false").to_return(status: 200) + stub_request(:get, "https://api.feedbin.me/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:password@api.feedbin.me/v2/feeds/42/entries.json").to_return(status: 200) + stub_request(:get, "https://api.feedbin.me/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 '#subscriptions' do it 'should get subscriptions and return a 200' do - stub_request(:get, "https://email:password@api.feedbin.me/v2/subscriptions.json").to_return(status: 200) + stub_request(:get, "https://api.feedbin.me/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:password@api.feedbin.me/v2/subscriptions/260815.json").to_return(status: 204) + stub_request(:delete, "https://api.feedbin.me/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:password@api.feedbin.me/v2/feeds/1.json").to_return(status: 200) + stub_request(:get, "https://api.feedbin.me/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:password@api.feedbin.me/v2/starred_entries.json").to_return(status: 200) + stub_request(:post, "https://api.feedbin.me/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:password@api.feedbin.me/v2/starred_entries.json").to_return(status: 200) + stub_request(:post, "https://api.feedbin.me/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 From 5c11fa3f9d3eb4e980776e2e2a7ac7c3df3330d9 Mon Sep 17 00:00:00 2001 From: Manu Campos Date: Tue, 9 Jan 2018 17:18:28 +0100 Subject: [PATCH 2/5] Update api hostname Until 2014-03-14 the API hostname was api.feedbin.me. api.feedbin.me will remain available indefinitely but api.feedbin.com is recommended because it is the new primary domain. https://github.com/feedbin/feedbin-api#domain --- README.md | 2 +- lib/feedbin.rb | 26 +++++++++++++------------- spec/feedbin_spec.rb | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 30c7c18..78ab04b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/feedbin.rb b/lib/feedbin.rb index 7bba6c6..9bbd943 100644 --- a/lib/feedbin.rb +++ b/lib/feedbin.rb @@ -12,44 +12,44 @@ 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) + HTTParty.get("https://api.feedbin.com/v2/feeds/#{id}/entries.json", 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 @@ -58,28 +58,28 @@ 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 # 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 diff --git a/spec/feedbin_spec.rb b/spec/feedbin_spec.rb index 48e8359..987aba7 100644 --- a/spec/feedbin_spec.rb +++ b/spec/feedbin_spec.rb @@ -8,13 +8,13 @@ describe '#entries' do it 'should get entries and return a 200' do - stub_request(:get, "https://api.feedbin.me/v2/entries.json?") + 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://api.feedbin.me/v2/entries.json?read=false") + 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 @@ -22,7 +22,7 @@ describe '#entries_for_feed' do it 'should get entries for a feed and return a 200' do - stub_request(:get, "https://api.feedbin.me/v2/feeds/42/entries.json") + 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 @@ -30,7 +30,7 @@ describe '#subscriptions' do it 'should get subscriptions and return a 200' do - stub_request(:get, "https://api.feedbin.me/v2/subscriptions.json") + 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 @@ -38,7 +38,7 @@ describe '#unsubscribe' do it 'should unsubscribe and return a 204' do - stub_request(:delete, "https://api.feedbin.me/v2/subscriptions/260815.json") + 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 @@ -46,7 +46,7 @@ describe '#feed' do it 'should get feed and return a 200' do - stub_request(:get, "https://api.feedbin.me/v2/feeds/1.json") + 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 @@ -54,13 +54,13 @@ describe '#star' do it 'should star a post and return a 200' do - stub_request(:post, "https://api.feedbin.me/v2/starred_entries.json") + 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://api.feedbin.me/v2/starred_entries.json") + 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 From 249d83b2ddec6cf1bbf1e2ea88e1881dc3ca4397 Mon Sep 17 00:00:00 2001 From: Manu Campos Date: Tue, 9 Jan 2018 17:23:35 +0100 Subject: [PATCH 3/5] Add options to entries_for_feed method Adds an options hash to the entries_for_feed method, so that it can support the same options as the entries method (pagination, items per page, etc) https://github.com/feedbin/feedbin-api/blob/master/content/entries.md#get-entries --- lib/feedbin.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/feedbin.rb b/lib/feedbin.rb index 9bbd943..c557bfe 100644 --- a/lib/feedbin.rb +++ b/lib/feedbin.rb @@ -15,8 +15,12 @@ def entries(options = {}) 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.com/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) From 0505aad77410bf6d970fddc5a189591b6e407acf Mon Sep 17 00:00:00 2001 From: Manu Campos Date: Tue, 9 Jan 2018 17:30:09 +0100 Subject: [PATCH 4/5] Add taggings support Adds taggings support, see: https://github.com/feedbin/feedbin-api/blob/master/content/taggings.md --- lib/feedbin.rb | 10 ++++++++++ spec/feedbin_spec.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/feedbin.rb b/lib/feedbin.rb index c557bfe..28f98ef 100644 --- a/lib/feedbin.rb +++ b/lib/feedbin.rb @@ -65,6 +65,16 @@ def feed(id) HTTParty.get("https://api.feedbin.com/v2/feeds/#{id}.json", basic_auth: basic_auth) end + # Tags + + def tag(id) + HTTParty.get("https://api.feedbin.com/v2/taggings/#{id}.json", basic_auth: basic_auth) + end + + def tags + HTTParty.get('https://api.feedbin.com/v2/taggings.json', basic_auth: basic_auth) + end + # Subscriptions def subscribe(url) diff --git a/spec/feedbin_spec.rb b/spec/feedbin_spec.rb index 987aba7..a2becaa 100644 --- a/spec/feedbin_spec.rb +++ b/spec/feedbin_spec.rb @@ -28,6 +28,22 @@ end end + describe '#tag' do + it 'should get subscriptions 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.tag(42).code).to eq(200) + end + end + + describe '#tags' do + it 'should get subscriptions 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.tags.code).to eq(200) + end + end + describe '#subscriptions' do it 'should get subscriptions and return a 200' do stub_request(:get, "https://api.feedbin.com/v2/subscriptions.json") From bdd633a8b7b61fe31f446e663680c53ab0967f3c Mon Sep 17 00:00:00 2001 From: Manu Campos Date: Thu, 11 Jan 2018 10:53:41 +0100 Subject: [PATCH 5/5] Fixing tags support The api exposes taggings and tags, taggings are the relationship between tags and feeds. --- lib/feedbin.rb | 8 ++++++-- spec/feedbin_spec.rb | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/feedbin.rb b/lib/feedbin.rb index 28f98ef..a774599 100644 --- a/lib/feedbin.rb +++ b/lib/feedbin.rb @@ -67,11 +67,15 @@ def feed(id) # Tags - def tag(id) + 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 tags + def taggings HTTParty.get('https://api.feedbin.com/v2/taggings.json', basic_auth: basic_auth) end diff --git a/spec/feedbin_spec.rb b/spec/feedbin_spec.rb index a2becaa..59fa79d 100644 --- a/spec/feedbin_spec.rb +++ b/spec/feedbin_spec.rb @@ -28,19 +28,27 @@ end end - describe '#tag' do - it 'should get subscriptions and return a 200' do + 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.tag(42).code).to eq(200) + expect(@feedbin.tagging(42).code).to eq(200) end end - describe '#tags' do - it 'should get subscriptions and return a 200' do + 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.tags.code).to eq(200) + expect(@feedbin.taggings.code).to eq(200) end end