From 45c110f96d300eefddfb3cfffa13b62e617d6ce6 Mon Sep 17 00:00:00 2001 From: stve Date: Tue, 6 Oct 2015 10:15:31 -0400 Subject: [PATCH] highlights return successfully with a GET request NOTE: This is undocumented and unconfirmed by Instapaper, but was discovered through trial and error. --- lib/instapaper/api/highlights.rb | 2 +- lib/instapaper/http/utils.rb | 7 +++++++ spec/instapaper/api/highlights_spec.rb | 4 ++-- spec/spec_helper.rb | 8 ++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/instapaper/api/highlights.rb b/lib/instapaper/api/highlights.rb index 201969d..b39e94c 100644 --- a/lib/instapaper/api/highlights.rb +++ b/lib/instapaper/api/highlights.rb @@ -7,7 +7,7 @@ module Instapaper # List highlights for a bookmark # @param bookmark_id [String, Integer] def highlights(bookmark_id) - perform_post_with_objects("/api/1.1/bookmarks/#{bookmark_id}/highlights", {}, Instapaper::Highlight) + perform_get_with_objects("/api/1.1/bookmarks/#{bookmark_id}/highlights", {}, Instapaper::Highlight) end # Create a new highlight diff --git a/lib/instapaper/http/utils.rb b/lib/instapaper/http/utils.rb index f0b02a7..f25dec0 100644 --- a/lib/instapaper/http/utils.rb +++ b/lib/instapaper/http/utils.rb @@ -12,6 +12,13 @@ module Instapaper perform_request_with_objects(:post, path, options, klass) end + # @param path [String] + # @param options [Hash] + # @param klass [Class] + def perform_get_with_objects(path, options, klass) + perform_request_with_objects(:get, path, options, klass) + end + # @param request_method [Symbol] # @param path [String] # @param options [Hash] diff --git a/spec/instapaper/api/highlights_spec.rb b/spec/instapaper/api/highlights_spec.rb index ec3eb9d..2be070e 100644 --- a/spec/instapaper/api/highlights_spec.rb +++ b/spec/instapaper/api/highlights_spec.rb @@ -5,13 +5,13 @@ describe Instapaper::Client::Highlights do describe '#highlights' do before do - stub_post('/api/1.1/bookmarks/123/highlights') + stub_get('/api/1.1/bookmarks/123/highlights') .to_return(status: 200, body: fixture('highlights_list.json'), headers: {content_type: 'application/json; charset=utf-8'}) end it 'gets the correct resource' do client.highlights(123) - expect(a_post('/api/1.1/bookmarks/123/highlights')).to have_been_made + expect(a_get('/api/1.1/bookmarks/123/highlights')).to have_been_made end it 'returns an array containing folders on success' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f7db603..b1796fa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,10 +13,18 @@ def a_post(path) a_request(:post, Instapaper::HTTP::Request::BASE_URL + path) end +def a_get(path) + a_request(:get, Instapaper::HTTP::Request::BASE_URL + path) +end + def stub_post(path) stub_request(:post, Instapaper::HTTP::Request::BASE_URL + path) end +def stub_get(path) + stub_request(:get, Instapaper::HTTP::Request::BASE_URL + path) +end + def fixture_path File.expand_path('../fixtures', __FILE__) end