mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-04-27 14:57:44 +00:00
reimplement bookmarks/list now that it returns a different response
This commit is contained in:
parent
26f526fe07
commit
dab3c0d9de
7 changed files with 27 additions and 36 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
require 'instapaper/bookmark'
|
require 'instapaper/bookmark'
|
||||||
|
require 'instapaper/bookmark_list'
|
||||||
|
|
||||||
module Instapaper
|
module Instapaper
|
||||||
module API
|
module API
|
||||||
|
|
@ -8,8 +9,9 @@ module Instapaper
|
||||||
# @option limit: Optional. A number between 1 and 500, default 25.
|
# @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 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 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 = {})
|
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
|
end
|
||||||
|
|
||||||
# Updates the user's reading progress on a single article.
|
# Updates the user's reading progress on a single article.
|
||||||
|
|
|
||||||
16
lib/instapaper/bookmark_list.rb
Normal file
16
lib/instapaper/bookmark_list.rb
Normal 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
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
require 'instapaper/http/request'
|
require 'instapaper/http/request'
|
||||||
require 'instapaper/object'
|
|
||||||
|
|
||||||
module Instapaper
|
module Instapaper
|
||||||
module HTTP
|
module HTTP
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
require 'virtus'
|
|
||||||
|
|
||||||
module Instapaper
|
|
||||||
class Meta
|
|
||||||
include Virtus.value_object
|
|
||||||
|
|
||||||
values do
|
|
||||||
attribute :type, String
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -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
|
|
||||||
6
spec/fixtures/bookmarks_list.json
vendored
6
spec/fixtures/bookmarks_list.json
vendored
|
|
@ -1,5 +1 @@
|
||||||
[{"type":"meta"},
|
{"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]}
|
||||||
{"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}
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,15 @@ describe Instapaper::Client::Bookmarks do
|
||||||
.to have_been_made
|
.to have_been_made
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns an array containing bookmarks on success' do
|
it 'returns an Instappaer::BookmarkList on success' do
|
||||||
bookmarks = client.bookmarks
|
list = client.bookmarks
|
||||||
expect(bookmarks).to be_an Array
|
expect(list).to be_an Instapaper::BookmarkList
|
||||||
expect(bookmarks.size).to eq(2)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes the meta and current user objects from the array' do
|
it 'includes all objects in the response' do
|
||||||
bookmarks = client.bookmarks
|
list = client.bookmarks
|
||||||
bookmarks.each do |bookmark|
|
expect(list.user).to be_an Instapaper::User
|
||||||
|
list.bookmarks.each do |bookmark|
|
||||||
expect(bookmark).to be_an Instapaper::Bookmark
|
expect(bookmark).to be_an Instapaper::Bookmark
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue