Skip to content

Commit

Permalink
Merge pull request #1 from twe4ked/master
Browse files Browse the repository at this point in the history
Add `entries_for_feed` method
  • Loading branch information
cp committed Nov 1, 2015
2 parents bd91b58 + 90523d8 commit 85667bb
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 50 deletions.
Empty file modified .gitignore
100755 → 100644
Empty file.
Empty file modified .travis.yml
100755 → 100644
Empty file.
4 changes: 0 additions & 4 deletions Gemfile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
source 'https://rubygems.org'

gemspec

group :test do
gem "webmock"
end
Empty file modified LICENSE.txt
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ Please add tests when contrinuting, and make sure that they all pass before subm
4. Run `rspec`. If there are any failures, please fix them before moving forward.
5. Commit your changes (`git commit -am 'Add some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
7. Create new Pull Request
7. Create new Pull Request
9 changes: 4 additions & 5 deletions Rakefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

task :default => [:spec]
desc 'run Rspec specs'
task :spec do
sh 'rspec'
end
RSpec::Core::RakeTask.new(:spec)

task :default => :spec
8 changes: 5 additions & 3 deletions feedbin.gemspec
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "httparty"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_runtime_dependency "httparty"
end
spec.add_development_dependency "rspec", ">= 2.14"
spec.add_development_dependency "webmock"
end
55 changes: 33 additions & 22 deletions lib/feedbin.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,88 @@

class FeedbinAPI
attr_accessor :email, :password

def initialize(email, password)
@email, @password = email, password
end

# Entries

def entries(options = {})
HTTParty.get("https://api.feedbin.me/v2/entries.json", query: options, basic_auth: { username: @email, password: @password })
HTTParty.get("https://api.feedbin.me/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)
end

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

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

def star(id)
HTTParty.post("https://api.feedbin.me/v2/starred_entries.json",
body: { 'starred_entries' => id }.to_json,
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 }).code
basic_auth: basic_auth).code
end

def unstar(id)
HTTParty.post("https://api.feedbin.me/v2/starred_entries/delete.json",
body: { 'starred_entries' => id }.to_json,
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 }).code
basic_auth: basic_auth).code
end

def mark_as_read(id)
HTTParty.post("https://api.feedbin.me/v2/unread_entries/delete.json",
body: { 'unread_entries' => id }.to_json,
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 }).code
basic_auth: basic_auth).code
end

def mark_as_unread(id)
HTTParty.post("https://api.feedbin.me/v2/unread_entries.json",
body: { 'unread_entries' => id }.to_json,
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 }).code
basic_auth: basic_auth).code
end

# Feeds

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

# Subscriptions

def subscribe(url)
HTTParty.post("https://api.feedbin.me/v2/subscriptions.json",
body: { 'feed_url' => url }.to_json,
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 }).code
basic_auth: basic_auth).code
end

def unsubscribe(id)
HTTParty.delete("https://api.feedbin.me/v2/subscriptions/#{id}.json", basic_auth: { username: @email, password: @password }).code
HTTParty.delete("https://api.feedbin.me/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: { username: @email, password: @password })
resp = HTTParty.get("https://api.feedbin.me/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: { username: @email, password: @password })
HTTParty.get("https://api.feedbin.me/v2/subscriptions.json", basic_auth: basic_auth)
end
end

private

def basic_auth
{ username: @email, password: @password }
end
end
2 changes: 1 addition & 1 deletion lib/feedbin/version.rb
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Feedbin
VERSION = "0.0.5"
VERSION = '0.0.5'
end
33 changes: 20 additions & 13 deletions spec/feedbin_spec.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,55 @@
@feedbin = FeedbinAPI.new('email', 'password')
end

describe '.entries' do
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)
@feedbin.entries.code.should == 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)
@feedbin.entries(read: false).code.should == 200
expect(@feedbin.entries(read: false).code).to eq(200)
end
end

describe '.subscriptions' do
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)
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:[email protected]/v2/subscriptions.json").to_return(status: 200)
@feedbin.subscriptions.code.should == 200
expect(@feedbin.subscriptions.code).to eq(200)
end
end

describe '.unsubscribe' do
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
expect(@feedbin.unsubscribe(260815)).to eq(204)
end
end

describe '.feed' do
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
expect(@feedbin.feed(1).code).to eq(200)
end
end

describe '.star' do
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).should == 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)
@feedbin.star([33,44,55,66,77]).should == 200
expect(@feedbin.star([33,44,55,66,77])).to eq(200)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

RSpec.configure do |c|
c.include(WebMock::API)
end
end

0 comments on commit 85667bb

Please sign in to comment.