reimplement bookmarks/list now that it returns a different response

This commit is contained in:
stve 2015-02-25 23:13:40 -05:00
parent 26f526fe07
commit dab3c0d9de
7 changed files with 27 additions and 36 deletions

View file

@ -1,4 +1,5 @@
require 'instapaper/bookmark'
require 'instapaper/bookmark_list'
module Instapaper
module API
@ -8,8 +9,9 @@ module Instapaper
# @option limit: Optional. A number between 1 and 500, default 25.
# @option folder_id: Optional. Possible values are unread (default), starred, archive, or a folder_id value from /api/1/folders/list.
# @option have: Optional. A concatenation of bookmark_id values that the client already has from the specified folder. See below.
# @option highlights: Optional. A '-' delimited list of highlight IDs that the client already has from the specified bookmarks.
def bookmarks(options = {})
perform_post_with_objects('/api/1/bookmarks/list', options, Instapaper::Object)[2..-1]
perform_post_with_object('/api/1/bookmarks/list', options, Instapaper::BookmarkList)
end
# Updates the user's reading progress on a single article.

View file

@ -0,0 +1,16 @@
require 'instapaper/bookmark'
require 'instapaper/highlight'
require 'instapaper/user'
module Instapaper
class BookmarkList
include Virtus.value_object
values do
attribute :user, Instapaper::User
attribute :bookmarks, Array[Instapaper::Bookmark]
attribute :highlights, Array[Instapaper::Highlight]
attribute :delete_ids, Array[Integer]
end
end
end

View file

@ -1,5 +1,4 @@
require 'instapaper/http/request'
require 'instapaper/object'
module Instapaper
module HTTP

View file

@ -1,11 +0,0 @@
require 'virtus'
module Instapaper
class Meta
include Virtus.value_object
values do
attribute :type, String
end
end
end

View file

@ -1,11 +0,0 @@
require 'instapaper/meta'
module Instapaper
class Object
def self.new(data)
type = data[:type]
type[0] = type[0].upcase
Instapaper.const_get(type).new(data)
end
end
end

View file

@ -1,5 +1 @@
[{"type":"meta"},
{"type":"user","user_id":1075837,"username":"steve.agalloco@gmail.com","subscription_is_active":"1"},
{"type":"bookmark","bookmark_id":170939225,"url":"http:\/\/www.igvita.com\/2010\/11\/17\/routing-with-ruby-zeromq-devices\/","title":"Routing with Ruby & ZeroMQ Devices","description":"ZeroMQ sockets provide message-oriented messaging, support for multiple transports, transparent setup and teardown, and an entire array of routing patterns via different socket types","time":1307319089,"starred":"0","private_source":"","hash":"PGU0MMPw","progress":0,"progress_timestamp":0},
{"type":"bookmark","bookmark_id":169529989,"url":"http:\/\/www.fastcodesign.com\/1662169\/ideos-axioms-for-starting-disruptive-new-businesses","title":"Ideo's Axioms for Starting Disruptive New Businesses | Co.Design","description":"www.fastcodesign.com","time":1306963988,"starred":"0","private_source":"","hash":"v27qHZc2","progress":"0","progress_timestamp":1307145892}
]
{"user":{"type":"user","user_id":1075837,"username":"steve.agalloco@gmail.com","subscription_is_active":"1"},"bookmarks":[{"type":"bookmark","bookmark_id":170939225,"url":"http:\/\/www.igvita.com\/2010\/11\/17\/routing-with-ruby-zeromq-devices\/","title":"Routing with Ruby & ZeroMQ Devices","description":"ZeroMQ sockets provide message-oriented messaging, support for multiple transports, transparent setup and teardown, and an entire array of routing patterns via different socket types","time":1307319089,"starred":"0","private_source":"","hash":"PGU0MMPw","progress":0,"progress_timestamp":0},{"type":"bookmark","bookmark_id":169529989,"url":"http:\/\/www.fastcodesign.com\/1662169\/ideos-axioms-for-starting-disruptive-new-businesses","title":"Ideo's Axioms for Starting Disruptive New Businesses | Co.Design","description":"www.fastcodesign.com","time":1306963988,"starred":"0","private_source":"","hash":"v27qHZc2","progress":"0","progress_timestamp":1307145892}],"highlights":[],"delete_ids":[12, 123, 123]}

View file

@ -15,15 +15,15 @@ describe Instapaper::Client::Bookmarks do
.to have_been_made
end
it 'returns an array containing bookmarks on success' do
bookmarks = client.bookmarks
expect(bookmarks).to be_an Array
expect(bookmarks.size).to eq(2)
it 'returns an Instappaer::BookmarkList on success' do
list = client.bookmarks
expect(list).to be_an Instapaper::BookmarkList
end
it 'removes the meta and current user objects from the array' do
bookmarks = client.bookmarks
bookmarks.each do |bookmark|
it 'includes all objects in the response' do
list = client.bookmarks
expect(list.user).to be_an Instapaper::User
list.bookmarks.each do |bookmark|
expect(bookmark).to be_an Instapaper::Bookmark
end
end