From dab3c0d9de8df8f5b4de7e4226e5bb867deff909 Mon Sep 17 00:00:00 2001 From: stve Date: Wed, 25 Feb 2015 23:13:40 -0500 Subject: [PATCH] reimplement bookmarks/list now that it returns a different response --- lib/instapaper/api/bookmarks.rb | 4 +++- lib/instapaper/bookmark_list.rb | 16 ++++++++++++++++ lib/instapaper/http/utils.rb | 1 - lib/instapaper/meta.rb | 11 ----------- lib/instapaper/object.rb | 11 ----------- spec/fixtures/bookmarks_list.json | 6 +----- spec/instapaper/api/bookmarks_spec.rb | 14 +++++++------- 7 files changed, 27 insertions(+), 36 deletions(-) create mode 100644 lib/instapaper/bookmark_list.rb delete mode 100644 lib/instapaper/meta.rb delete mode 100644 lib/instapaper/object.rb diff --git a/lib/instapaper/api/bookmarks.rb b/lib/instapaper/api/bookmarks.rb index c3de22a..5448f9a 100644 --- a/lib/instapaper/api/bookmarks.rb +++ b/lib/instapaper/api/bookmarks.rb @@ -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. diff --git a/lib/instapaper/bookmark_list.rb b/lib/instapaper/bookmark_list.rb new file mode 100644 index 0000000..deb95da --- /dev/null +++ b/lib/instapaper/bookmark_list.rb @@ -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 diff --git a/lib/instapaper/http/utils.rb b/lib/instapaper/http/utils.rb index a9b9af0..f57196e 100644 --- a/lib/instapaper/http/utils.rb +++ b/lib/instapaper/http/utils.rb @@ -1,5 +1,4 @@ require 'instapaper/http/request' -require 'instapaper/object' module Instapaper module HTTP diff --git a/lib/instapaper/meta.rb b/lib/instapaper/meta.rb deleted file mode 100644 index eee144e..0000000 --- a/lib/instapaper/meta.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'virtus' - -module Instapaper - class Meta - include Virtus.value_object - - values do - attribute :type, String - end - end -end diff --git a/lib/instapaper/object.rb b/lib/instapaper/object.rb deleted file mode 100644 index dbccfd1..0000000 --- a/lib/instapaper/object.rb +++ /dev/null @@ -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 diff --git a/spec/fixtures/bookmarks_list.json b/spec/fixtures/bookmarks_list.json index 99216a8..7bf6337 100644 --- a/spec/fixtures/bookmarks_list.json +++ b/spec/fixtures/bookmarks_list.json @@ -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} -] \ No newline at end of file +{"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]} diff --git a/spec/instapaper/api/bookmarks_spec.rb b/spec/instapaper/api/bookmarks_spec.rb index ff1527a..6dde425 100644 --- a/spec/instapaper/api/bookmarks_spec.rb +++ b/spec/instapaper/api/bookmarks_spec.rb @@ -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