mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-03-25 08:55:49 +00:00
rubocop cleanup
This commit is contained in:
parent
af19561e93
commit
5161c68b5a
21 changed files with 216 additions and 236 deletions
6
Rakefile
6
Rakefile
|
|
@ -6,8 +6,8 @@ Bundler::GemHelper.install_tasks
|
|||
require 'rspec/core/rake_task'
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :test => :spec
|
||||
task :default => :spec
|
||||
task test: :spec
|
||||
task default: :spec
|
||||
|
||||
require 'yard'
|
||||
YARD::Rake::YardocTask.new
|
||||
YARD::Rake::YardocTask.new
|
||||
|
|
|
|||
|
|
@ -10,56 +10,56 @@ module Faraday
|
|||
# general errors
|
||||
|
||||
when 1040
|
||||
raise Instapaper::Error.new(error_message(env, "Rate-limit exceeded."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Rate-limit exceeded.'))
|
||||
when 1041
|
||||
raise Instapaper::Error.new(error_message(env, "Subscription account required."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Subscription account required.'))
|
||||
when 1042
|
||||
raise Instapaper::Error.new(error_message(env, "Application is suspended."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Application is suspended.'))
|
||||
|
||||
# bookmark errors
|
||||
|
||||
when 1220
|
||||
raise Instapaper::Error.new(error_message(env, "Domain requires full content to be supplied."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Domain requires full content to be supplied.'))
|
||||
when 1221
|
||||
raise Instapaper::Error.new(error_message(env, "Domain has opted out of Instapaper compatibility."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Domain has opted out of Instapaper compatibility.'))
|
||||
when 1240
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid URL specified."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid URL specified.'))
|
||||
when 1241
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid or missing bookmark_id."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid or missing bookmark_id.'))
|
||||
when 1242
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid or missing folder_id."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid or missing folder_id.'))
|
||||
when 1243
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid or missing progress."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid or missing progress.'))
|
||||
when 1244
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid or missing progress_timestamp."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid or missing progress_timestamp.'))
|
||||
when 1245
|
||||
raise Instapaper::Error.new(error_message(env, "Private bookmarks require supplied content."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Private bookmarks require supplied content.'))
|
||||
when 1250
|
||||
raise Instapaper::Error.new(error_message(env, "Unexpected error when saving bookmark."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Unexpected error when saving bookmark.'))
|
||||
|
||||
# folder errors
|
||||
|
||||
when 1250
|
||||
raise Instapaper::Error.new(error_message(env, "Invalid or missing title."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Invalid or missing title.'))
|
||||
when 1251
|
||||
raise Instapaper::Error.new(error_message(env, "User already has a folder with this title."))
|
||||
fail Instapaper::Error.new(error_message(env, 'User already has a folder with this title.'))
|
||||
when 1252
|
||||
raise Instapaper::Error.new(error_message(env, "Cannot add bookmarks to this folder."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Cannot add bookmarks to this folder.'))
|
||||
|
||||
# operational errors
|
||||
|
||||
when 1500
|
||||
raise Instapaper::Error.new(error_message(env, "Unexpected service error."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Unexpected service error.'))
|
||||
when 1550
|
||||
raise Instapaper::Error.new(error_message(env, "Error generating text version of this URL."))
|
||||
fail Instapaper::Error.new(error_message(env, 'Error generating text version of this URL.'))
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def error_message(env, body=nil)
|
||||
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')}."
|
||||
def error_message(env, body = nil)
|
||||
"#{env[:method].to_s.upcase} #{env[:url]}: #{[env[:status].to_s + ':', body].compact.join(' ')}."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ module Instapaper
|
|||
# Alias for Instapaper::Client.new
|
||||
#
|
||||
# @return [Instapaper::Client]
|
||||
def self.client(options={})
|
||||
def self.client(options = {})
|
||||
Instapaper::Client.new(options)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,17 +8,17 @@ module Instapaper
|
|||
# @return [Hash]
|
||||
def authentication
|
||||
{
|
||||
:consumer_key => consumer_key,
|
||||
:consumer_secret => consumer_secret,
|
||||
:token => oauth_token,
|
||||
:token_secret => oauth_token_secret
|
||||
consumer_key: consumer_key,
|
||||
consumer_secret: consumer_secret,
|
||||
token: oauth_token,
|
||||
token_secret: oauth_token_secret
|
||||
}
|
||||
end
|
||||
|
||||
def consumer_tokens
|
||||
{
|
||||
:consumer_key => consumer_key,
|
||||
:consumer_secret => consumer_secret
|
||||
consumer_key: consumer_key,
|
||||
consumer_secret: consumer_secret
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ module Instapaper
|
|||
# @private
|
||||
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
||||
|
||||
alias :api_endpoint :endpoint
|
||||
alias :api_version :version
|
||||
alias_method :api_endpoint, :endpoint
|
||||
alias_method :api_version, :version
|
||||
|
||||
# Creates a new API
|
||||
def initialize(options={})
|
||||
def initialize(options = {})
|
||||
options = Instapaper.options.merge(options)
|
||||
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
||||
send("#{key}=", options[key])
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@ module Instapaper
|
|||
class Client
|
||||
# Defines methods related to accounts
|
||||
module Account
|
||||
|
||||
# Returns the currently logged in user.
|
||||
def verify_credentials
|
||||
post('account/verify_credentials')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ module Instapaper
|
|||
class Client
|
||||
# Defines methods related to bookmarks
|
||||
module Bookmark
|
||||
|
||||
# Lists the user’s unread bookmarks, and can also synchronize reading positions.
|
||||
# @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.
|
||||
def bookmarks(options={})
|
||||
def bookmarks(options = {})
|
||||
post('bookmarks/list', options)[2..-1]
|
||||
end
|
||||
|
||||
|
|
@ -15,67 +14,66 @@ module Instapaper
|
|||
# @param bookmark_id [String] The id of the bookmark to update.
|
||||
# @param progress [Float] The user’s progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the user’s current viewport, expressed as a percentage of the article’s total length.
|
||||
# @param progress_timestamp [Integer] The Unix timestamp value of the time that the progress was recorded.
|
||||
def update_read_progress(bookmark_id, progress, progress_timestamp=Time.now)
|
||||
post('bookmarks/update_read_progress', :bookmark_id => bookmark_id, :progress => progress, :progress_timestamp => progress_timestamp.to_i).first
|
||||
def update_read_progress(bookmark_id, progress, progress_timestamp = Time.now)
|
||||
post('bookmarks/update_read_progress', bookmark_id: bookmark_id, progress: progress, progress_timestamp: progress_timestamp.to_i).first
|
||||
end
|
||||
|
||||
# Adds a new unread bookmark to the user’s account.
|
||||
# @param url [String] The url of the bookmark.
|
||||
def add_bookmark(url, options={})
|
||||
post('bookmarks/add', options.merge(:url => url)).first
|
||||
def add_bookmark(url, options = {})
|
||||
post('bookmarks/add', options.merge(url: url)).first
|
||||
end
|
||||
|
||||
# Permanently deletes the specified bookmark.
|
||||
# This is NOT the same as Archive. Please be clear to users if you’re going to do this.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def delete_bookmark(bookmark_id)
|
||||
post('bookmarks/delete', :bookmark_id => bookmark_id)
|
||||
post('bookmarks/delete', bookmark_id: bookmark_id)
|
||||
end
|
||||
|
||||
# Stars the specified bookmark.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def star(bookmark_id)
|
||||
post('bookmarks/star', :bookmark_id => bookmark_id).first
|
||||
post('bookmarks/star', bookmark_id: bookmark_id).first
|
||||
end
|
||||
alias :star_bookmark :star
|
||||
alias_method :star_bookmark, :star
|
||||
|
||||
# Un-stars the specified bookmark.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def unstar(bookmark_id)
|
||||
post('bookmarks/unstar', :bookmark_id => bookmark_id).first
|
||||
post('bookmarks/unstar', bookmark_id: bookmark_id).first
|
||||
end
|
||||
alias :unstar_bookmark :unstar
|
||||
alias_method :unstar_bookmark, :unstar
|
||||
|
||||
# Moves the specified bookmark to the Archive.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def archive(bookmark_id)
|
||||
post('bookmarks/archive', :bookmark_id => bookmark_id).first
|
||||
post('bookmarks/archive', bookmark_id: bookmark_id).first
|
||||
end
|
||||
alias :archive_bookmark :archive
|
||||
alias_method :archive_bookmark, :archive
|
||||
|
||||
# Moves the specified bookmark to the top of the Unread folder.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def unarchive(bookmark_id)
|
||||
post('bookmarks/unarchive', :bookmark_id => bookmark_id).first
|
||||
post('bookmarks/unarchive', bookmark_id: bookmark_id).first
|
||||
end
|
||||
alias :unarchive_bookmark :unarchive
|
||||
alias_method :unarchive_bookmark, :unarchive
|
||||
|
||||
# Moves the specified bookmark to a user-created folder.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
# @param folder_id [String] The id of the folder to move the bookmark to.
|
||||
def move(bookmark_id, folder_id)
|
||||
post('bookmarks/move', :bookmark_id => bookmark_id, :folder_id => folder_id).first
|
||||
post('bookmarks/move', bookmark_id: bookmark_id, folder_id: folder_id).first
|
||||
end
|
||||
alias :move_bookmark :move
|
||||
alias_method :move_bookmark, :move
|
||||
|
||||
# Returns the specified bookmark’s processed text-view HTML, which is
|
||||
# always text/html encoded as UTF-8.
|
||||
# @param bookmark_id [String] The id of the bookmark.
|
||||
def text(bookmark_id)
|
||||
post('bookmarks/get_text', { :bookmark_id => bookmark_id }, true).body
|
||||
post('bookmarks/get_text', { bookmark_id: bookmark_id }, true).body
|
||||
end
|
||||
alias :get_text :text
|
||||
|
||||
alias_method :get_text, :text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ module Instapaper
|
|||
class Client
|
||||
# Defines methods related to folders
|
||||
module Folder
|
||||
|
||||
# List the account’s user-created folders.
|
||||
# @note This only includes organizational folders and does not include RSS-feed folders or starred-subscription folders
|
||||
def folders
|
||||
|
|
@ -12,23 +11,22 @@ module Instapaper
|
|||
# Creates an organizational folder.
|
||||
# @param title [String] The title of the folder to create
|
||||
def add_folder(title)
|
||||
post('folders/add', :title => title)
|
||||
post('folders/add', title: title)
|
||||
end
|
||||
|
||||
# Deletes the folder and moves any articles in it to the Archive.
|
||||
# @param folder_id [String] The id of the folder.
|
||||
def delete_folder(folder_id)
|
||||
post('folders/delete', :folder_id => folder_id)
|
||||
post('folders/delete', folder_id: folder_id)
|
||||
end
|
||||
|
||||
# Re-orders a user’s folders.
|
||||
# @param order [Array] An array of folder_id:position pairs joined by commas.
|
||||
# @example Ordering folder_ids 100, 200, and 300
|
||||
# Instapaper.set_order(['100:1','200:2','300:3'])
|
||||
def set_order(order=[])
|
||||
post('folders/set_order', :order => order.join(','))
|
||||
def set_order(order = [])
|
||||
post('folders/set_order', order: order.join(','))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,18 +2,16 @@ module Instapaper
|
|||
class Client
|
||||
# Defines methods related to users
|
||||
module User
|
||||
|
||||
# Gets an OAuth access token for a user.
|
||||
def access_token(username, password)
|
||||
response = post('oauth/access_token', { :x_auth_username => username, :x_auth_password => password, :x_auth_mode => "client_auth"}, true)
|
||||
params = response.body.split("&")
|
||||
values = params.map {|part| part.split("=") }.flatten
|
||||
response = post('oauth/access_token', { x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth' }, true)
|
||||
params = response.body.split('&')
|
||||
values = params.map { |part| part.split('=') }.flatten
|
||||
if values.length == 1
|
||||
values.unshift('error')
|
||||
end
|
||||
Hash[*values]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ module Instapaper
|
|||
# Create a hash of options and their values
|
||||
def options
|
||||
options = {}
|
||||
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
|
||||
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
||||
options
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,14 @@ module Instapaper
|
|||
module Connection
|
||||
private
|
||||
|
||||
def connection(raw=false)
|
||||
merged_options = connection_options.merge({
|
||||
:headers => {
|
||||
'Accept' => "application/json",
|
||||
'User-Agent' => user_agent
|
||||
},
|
||||
:proxy => proxy,
|
||||
:ssl => {:verify => false},
|
||||
:url => api_endpoint
|
||||
})
|
||||
def connection(raw = false)
|
||||
merged_options = connection_options.merge(headers: {
|
||||
'Accept' => 'application/json',
|
||||
'User-Agent' => user_agent
|
||||
},
|
||||
proxy: proxy,
|
||||
ssl: { verify: false },
|
||||
url: api_endpoint)
|
||||
|
||||
Faraday.new(merged_options) do |builder|
|
||||
if authenticated?
|
||||
|
|
|
|||
|
|
@ -1,22 +1,20 @@
|
|||
module Instapaper
|
||||
# Defines HTTP request methods
|
||||
module Request
|
||||
|
||||
# Perform an HTTP POST request
|
||||
def post(path, options={}, raw=false)
|
||||
def post(path, options = {}, raw = false)
|
||||
request(:post, path, options, raw)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Perform an HTTP request
|
||||
def request(method, path, options, raw=false)
|
||||
def request(method, path, options, raw = false)
|
||||
response = connection(raw).send(method) do |request|
|
||||
request.path = path_prefix + path
|
||||
request.body = options unless options.empty?
|
||||
end
|
||||
raw ? response : response.body
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module Instapaper
|
||||
VERSION = "0.3.0"
|
||||
VERSION = '0.3.0'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ describe Faraday::Response do
|
|||
end
|
||||
|
||||
[1040, 1041, 1042, 1220, 1221, 1240, 1241, 1242, 1243, 1244, 1245, 1250,
|
||||
1251, 1252, 1500, 1550].each do |status|
|
||||
1251, 1252, 1500, 1550].each do |status|
|
||||
context "when HTTP status is #{status}" do
|
||||
before do
|
||||
stub_post('folders/list').to_return(:status => status)
|
||||
stub_post('folders/list').to_return(status: status)
|
||||
end
|
||||
|
||||
it "should raise Instapaper::Error error" do
|
||||
it 'should raise Instapaper::Error error' do
|
||||
expect do
|
||||
@client.folders
|
||||
end.to raise_error(Instapaper::Error)
|
||||
|
|
|
|||
|
|
@ -7,21 +7,20 @@ describe Instapaper::Client::Account do
|
|||
|
||||
describe '.verify_credentials' do
|
||||
before do
|
||||
stub_post("account/verify_credentials").
|
||||
to_return(:body => fixture("verify_credentials.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('account/verify_credentials')
|
||||
.to_return(body: fixture('verify_credentials.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.verify_credentials
|
||||
expect(a_post("account/verify_credentials")).
|
||||
to have_been_made
|
||||
expect(a_post('account/verify_credentials'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the user" do
|
||||
it 'should return the user' do
|
||||
user = @client.verify_credentials.first
|
||||
expect(user).to be_a Hashie::Rash
|
||||
expect(user.username).to eq('TestUserOMGLOL')
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,28 +2,28 @@ require 'spec_helper'
|
|||
|
||||
describe Instapaper::Client::Bookmark do
|
||||
before(:each) do
|
||||
@client = Instapaper::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
||||
@client = Instapaper::Client.new(consumer_key: 'CK', consumer_secret: 'CS', oauth_token: 'OT', oauth_token_secret: 'OS')
|
||||
end
|
||||
|
||||
describe '.bookmarks' do
|
||||
before do
|
||||
stub_post("bookmarks/list").
|
||||
to_return(:body => fixture("bookmarks_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/list')
|
||||
.to_return(body: fixture('bookmarks_list.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.bookmarks
|
||||
expect(a_post("bookmarks/list")).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/list'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array containing bookmarks on success" do
|
||||
it 'should return an array containing bookmarks on success' do
|
||||
bookmarks = @client.bookmarks
|
||||
expect(bookmarks).to be_an Array
|
||||
expect(bookmarks.size).to eq(2)
|
||||
end
|
||||
|
||||
it "should remove the meta and current user objects from the array" do
|
||||
it 'should remove the meta and current user objects from the array' do
|
||||
bookmarks = @client.bookmarks
|
||||
bookmarks.each do |bookmark|
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
|
|
@ -35,38 +35,38 @@ describe Instapaper::Client::Bookmark do
|
|||
describe '.update_read_progress' do
|
||||
before do
|
||||
@time = Time.now
|
||||
stub_post("bookmarks/update_read_progress").
|
||||
to_return(:body => fixture("bookmarks_update_read_progress.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/update_read_progress')
|
||||
.to_return(body: fixture('bookmarks_update_read_progress.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.update_read_progress(123, 0.5, @time)
|
||||
expect(a_post("bookmarks/update_read_progress").with(:body => {:bookmark_id => "123", :progress => '0.5', :progress_timestamp => @time.to_i.to_s })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/update_read_progress').with(body: { bookmark_id: '123', progress: '0.5', progress_timestamp: @time.to_i.to_s }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array containing bookmarks on success" do
|
||||
it 'should return an array containing bookmarks on success' do
|
||||
bookmark = @client.update_read_progress(123, 0.5, @time)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
expect(bookmark.progress).to eq("0.5")
|
||||
expect(bookmark.progress).to eq('0.5')
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_bookmark' do
|
||||
before do
|
||||
stub_post("bookmarks/add").
|
||||
to_return(:body => fixture('bookmarks_add.json'), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/add')
|
||||
.to_return(body: fixture('bookmarks_add.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
@client.add_bookmark('http://someurl.com', :title => 'This is the title', :description => 'This is the description')
|
||||
expect(a_post("bookmarks/add").with(:body => {:url => "http://someurl.com", :title => 'This is the title', :description => 'This is the description' })).
|
||||
to have_been_made
|
||||
it 'should get the correct resource' do
|
||||
@client.add_bookmark('http://someurl.com', title: 'This is the title', description: 'This is the description')
|
||||
expect(a_post('bookmarks/add').with(body: { url: 'http://someurl.com', title: 'This is the title', description: 'This is the description' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the bookmark on success" do
|
||||
bookmark = @client.add_bookmark('http://someurl.com', :title => 'This is the title', :description => 'This is the description')
|
||||
it 'should return the bookmark on success' do
|
||||
bookmark = @client.add_bookmark('http://someurl.com', title: 'This is the title', description: 'This is the description')
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
end
|
||||
|
|
@ -74,17 +74,17 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.delete_bookmark' do
|
||||
before do
|
||||
stub_post("bookmarks/delete").
|
||||
to_return(:body => '[]', :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/delete')
|
||||
.to_return(body: '[]', headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.delete_bookmark(123)
|
||||
expect(a_post("bookmarks/delete").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/delete').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array containing bookmarks on success" do
|
||||
it 'should return an array containing bookmarks on success' do
|
||||
confirm = @client.delete_bookmark(123)
|
||||
expect(confirm).to be_an Array
|
||||
expect(confirm).to be_empty
|
||||
|
|
@ -93,17 +93,17 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.star' do
|
||||
before do
|
||||
stub_post("bookmarks/star").
|
||||
to_return(:body => fixture("bookmarks_star.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/star')
|
||||
.to_return(body: fixture('bookmarks_star.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.star(123)
|
||||
expect(a_post("bookmarks/star").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/star').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return a starred bookmark on success" do
|
||||
it 'should return a starred bookmark on success' do
|
||||
bookmark = @client.star(123)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
|
|
@ -117,17 +117,17 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.unstar' do
|
||||
before do
|
||||
stub_post("bookmarks/unstar").
|
||||
to_return(:body => fixture("bookmarks_unstar.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/unstar')
|
||||
.to_return(body: fixture('bookmarks_unstar.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.unstar(123)
|
||||
expect(a_post("bookmarks/unstar").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/unstar').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an unstarred bookmark on success" do
|
||||
it 'should return an unstarred bookmark on success' do
|
||||
bookmark = @client.unstar(123)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
|
|
@ -141,17 +141,17 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.archive' do
|
||||
before do
|
||||
stub_post("bookmarks/archive").
|
||||
to_return(:body => fixture("bookmarks_archive.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/archive')
|
||||
.to_return(body: fixture('bookmarks_archive.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.archive(123)
|
||||
expect(a_post("bookmarks/archive").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/archive').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the bookmark on success" do
|
||||
it 'should return the bookmark on success' do
|
||||
bookmark = @client.archive(123)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
|
|
@ -164,17 +164,17 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.unarchive' do
|
||||
before do
|
||||
stub_post("bookmarks/unarchive").
|
||||
to_return(:body => fixture("bookmarks_unarchive.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/unarchive')
|
||||
.to_return(body: fixture('bookmarks_unarchive.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.unarchive(123)
|
||||
expect(a_post("bookmarks/unarchive").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/unarchive').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the bookmark on success" do
|
||||
it 'should return the bookmark on success' do
|
||||
bookmark = @client.unarchive(123)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
|
|
@ -187,37 +187,37 @@ describe Instapaper::Client::Bookmark do
|
|||
|
||||
describe '.move' do
|
||||
before do
|
||||
stub_post("bookmarks/move").
|
||||
to_return(:body => fixture("bookmarks_move.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('bookmarks/move')
|
||||
.to_return(body: fixture('bookmarks_move.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
@client.move(123, 12345)
|
||||
expect(a_post("bookmarks/move").with(:body => {:bookmark_id => "123", :folder_id => "12345" })).
|
||||
to have_been_made
|
||||
it 'should get the correct resource' do
|
||||
@client.move(123, 12_345)
|
||||
expect(a_post('bookmarks/move').with(body: { bookmark_id: '123', folder_id: '12345' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the bookmark on success" do
|
||||
bookmark = @client.move(123, 12345)
|
||||
it 'should return the bookmark on success' do
|
||||
bookmark = @client.move(123, 12_345)
|
||||
expect(bookmark).to be_a Hashie::Rash
|
||||
expect(bookmark.type).to eq('bookmark')
|
||||
end
|
||||
|
||||
it 'should be aliased as .move_bookmark' do
|
||||
expect(@client.move(123, 12345)).to eq(@client.move_bookmark(123, 12345))
|
||||
expect(@client.move(123, 12_345)).to eq(@client.move_bookmark(123, 12_345))
|
||||
end
|
||||
end
|
||||
|
||||
describe '.text' do
|
||||
before do
|
||||
stub_post("bookmarks/get_text").
|
||||
to_return(:body => fixture("bookmarks_get_text.txt"), :headers => {:content_type => "text/html; charset=utf-8"})
|
||||
stub_post('bookmarks/get_text')
|
||||
.to_return(body: fixture('bookmarks_get_text.txt'), headers: { content_type: 'text/html; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.text(123)
|
||||
expect(a_post("bookmarks/get_text").with(:body => {:bookmark_id => "123" })).
|
||||
to have_been_made
|
||||
expect(a_post('bookmarks/get_text').with(body: { bookmark_id: '123' }))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the bookmark's html on success" do
|
||||
|
|
@ -230,5 +230,4 @@ describe Instapaper::Client::Bookmark do
|
|||
expect(@client.text(123)).to eq(@client.get_text(123))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ describe Instapaper::Client::Folder do
|
|||
|
||||
describe '.folders' do
|
||||
before do
|
||||
stub_post("folders/list").
|
||||
to_return(:body => fixture("folders_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('folders/list')
|
||||
.to_return(body: fixture('folders_list.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.folders
|
||||
expect(a_post("folders/list")).
|
||||
to have_been_made
|
||||
expect(a_post('folders/list'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array containing folders on success" do
|
||||
it 'should return an array containing folders on success' do
|
||||
folders = @client.folders
|
||||
expect(folders).to be_an Array
|
||||
expect(folders.size).to eq(2)
|
||||
|
|
@ -28,18 +28,18 @@ describe Instapaper::Client::Folder do
|
|||
|
||||
describe '.add_folder' do
|
||||
before do
|
||||
stub_post("folders/add").with(:body => {:title => "Ruby" }).
|
||||
to_return(:body => fixture("folders_add.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('folders/add').with(body: { title: 'Ruby' })
|
||||
.to_return(body: fixture('folders_add.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
@client.add_folder("Ruby")
|
||||
expect(a_post("folders/add")).
|
||||
to have_been_made
|
||||
it 'should get the correct resource' do
|
||||
@client.add_folder('Ruby')
|
||||
expect(a_post('folders/add'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array containing the new folder on success" do
|
||||
folders = @client.add_folder("Ruby")
|
||||
it 'should return an array containing the new folder on success' do
|
||||
folders = @client.add_folder('Ruby')
|
||||
expect(folders).to be_an Array
|
||||
expect(folders).not_to be_empty
|
||||
expect(folders.first).to be_a Hashie::Rash
|
||||
|
|
@ -49,18 +49,18 @@ describe Instapaper::Client::Folder do
|
|||
|
||||
describe '.delete_folder' do
|
||||
before do
|
||||
stub_post("folders/delete"). with(:body => {:folder_id => "1" }).
|
||||
to_return(:body => fixture("folders_delete.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('folders/delete'). with(body: { folder_id: '1' })
|
||||
.to_return(body: fixture('folders_delete.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
@client.delete_folder("1")
|
||||
expect(a_post("folders/delete")).
|
||||
to have_been_made
|
||||
it 'should get the correct resource' do
|
||||
@client.delete_folder('1')
|
||||
expect(a_post('folders/delete'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an empty array on success" do
|
||||
confirm = @client.delete_folder("1")
|
||||
it 'should return an empty array on success' do
|
||||
confirm = @client.delete_folder('1')
|
||||
expect(confirm).to be_an Array
|
||||
expect(confirm).to be_empty
|
||||
end
|
||||
|
|
@ -68,22 +68,21 @@ describe Instapaper::Client::Folder do
|
|||
|
||||
describe '.set_order' do
|
||||
before do
|
||||
stub_post("folders/set_order"). with(:body => {:order => "1121173:2,1121174:1" }).
|
||||
to_return(:body => fixture("folders_set_order.json"), :headers => {:content_type => "application/json; charset=utf-8"})
|
||||
stub_post('folders/set_order'). with(body: { order: '1121173:2,1121174:1' })
|
||||
.to_return(body: fixture('folders_set_order.json'), headers: { content_type: 'application/json; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
@client.set_order(['1121173:2','1121174:1'])
|
||||
expect(a_post("folders/set_order")).
|
||||
to have_been_made
|
||||
it 'should get the correct resource' do
|
||||
@client.set_order(['1121173:2', '1121174:1'])
|
||||
expect(a_post('folders/set_order'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return an array reflecting the new order on success" do
|
||||
folders = @client.set_order(['1121173:2','1121174:1'])
|
||||
it 'should return an array reflecting the new order on success' do
|
||||
folders = @client.set_order(['1121173:2', '1121174:1'])
|
||||
expect(folders).to be_an Array
|
||||
expect(folders.first).to be_a Hashie::Rash
|
||||
expect(folders.first['position']).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,30 +7,29 @@ describe Instapaper::Client::User do
|
|||
|
||||
describe '.access_token' do
|
||||
before do
|
||||
stub_post("oauth/access_token").with(:body => { :x_auth_username => 'ohai', :x_auth_password => 'p455w0rd', :x_auth_mode => 'client_auth'}).
|
||||
to_return(:body => fixture("access_token.qline"), :headers => {:content_type => "text/plain; charset=utf-8"})
|
||||
stub_post("oauth/access_token").with(:body => { :x_auth_username => 'inval1d', :x_auth_password => 'cr3dentials', :x_auth_mode => 'client_auth'}).
|
||||
to_return(:body => fixture("invalid_credentials.qline"), :headers => {:content_type => "text/plain; charset=utf-8"})
|
||||
stub_post('oauth/access_token').with(body: { x_auth_username: 'ohai', x_auth_password: 'p455w0rd', x_auth_mode: 'client_auth' })
|
||||
.to_return(body: fixture('access_token.qline'), headers: { content_type: 'text/plain; charset=utf-8' })
|
||||
stub_post('oauth/access_token').with(body: { x_auth_username: 'inval1d', x_auth_password: 'cr3dentials', x_auth_mode: 'client_auth' })
|
||||
.to_return(body: fixture('invalid_credentials.qline'), headers: { content_type: 'text/plain; charset=utf-8' })
|
||||
end
|
||||
|
||||
it "should get the correct resource" do
|
||||
it 'should get the correct resource' do
|
||||
@client.access_token('ohai', 'p455w0rd')
|
||||
expect(a_post("oauth/access_token")).
|
||||
to have_been_made
|
||||
expect(a_post('oauth/access_token'))
|
||||
.to have_been_made
|
||||
end
|
||||
|
||||
it "should return the a hash containing an oauth token and secret" do
|
||||
it 'should return the a hash containing an oauth token and secret' do
|
||||
tokens = @client.access_token('ohai', 'p455w0rd')
|
||||
expect(tokens).to be_a Hash
|
||||
expect(tokens.key?('oauth_token')).to be true
|
||||
expect(tokens.key?('oauth_token_secret')).to be true
|
||||
end
|
||||
|
||||
it "should return a hash containing the error on invalid credentials" do
|
||||
it 'should return a hash containing the error on invalid credentials' do
|
||||
tokens = @client.access_token('inval1d', 'cr3dentials')
|
||||
expect(tokens).to be_a Hash
|
||||
expect(tokens.key?('error')).to be true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Instapaper::Client do
|
||||
|
||||
before do
|
||||
@options = { :adapter => :em_synchrony, :user_agent => 'Instapaper::Client spec' }
|
||||
@options = { adapter: :em_synchrony, user_agent: 'Instapaper::Client spec' }
|
||||
@keys = Instapaper::Configuration::VALID_OPTIONS_KEYS
|
||||
end
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ describe Instapaper::Client do
|
|||
end
|
||||
|
||||
context 'with module configuration' do
|
||||
it "should inherit module configuration" do
|
||||
it 'should inherit module configuration' do
|
||||
api = Instapaper::Client.new
|
||||
@keys.each do |key|
|
||||
expect(api.send(key)).to eq(key)
|
||||
|
|
@ -28,24 +27,24 @@ describe Instapaper::Client do
|
|||
end
|
||||
|
||||
context 'with class configuration' do
|
||||
context "during initialization" do
|
||||
it "should override module configuration" do
|
||||
context 'during initialization' do
|
||||
it 'should override module configuration' do
|
||||
api = Instapaper::Client.new(@options)
|
||||
@keys.each do |key|
|
||||
h = @options.has_key?(key) ? @options : Instapaper.options
|
||||
h = @options.key?(key) ? @options : Instapaper.options
|
||||
expect(api.send(key)).to eq(h[key])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "after initialization" do
|
||||
it "should override module configuration after initialization" do
|
||||
context 'after initialization' do
|
||||
it 'should override module configuration after initialization' do
|
||||
api = Instapaper::Client.new
|
||||
@options.each do |key, value|
|
||||
api.send("#{key}=", value)
|
||||
end
|
||||
@keys.each do |key|
|
||||
h = @options.has_key?(key) ? @options : Instapaper.options
|
||||
h = @options.key?(key) ? @options : Instapaper.options
|
||||
expect(api.send(key)).to eq(h[key])
|
||||
end
|
||||
end
|
||||
|
|
@ -62,4 +61,4 @@ describe Instapaper::Client do
|
|||
expect(@client.endpoint_with_prefix).to eq(Instapaper.endpoint + Instapaper.path_prefix)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,68 +11,66 @@ describe Instapaper do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".client" do
|
||||
it "should be a Instapaper::Client" do
|
||||
describe '.client' do
|
||||
it 'should be a Instapaper::Client' do
|
||||
expect(Instapaper.client).to be_a Instapaper::Client
|
||||
end
|
||||
end
|
||||
|
||||
describe ".adapter" do
|
||||
it "should return the default adapter" do
|
||||
describe '.adapter' do
|
||||
it 'should return the default adapter' do
|
||||
expect(Instapaper.adapter).to eq(Instapaper::Configuration::DEFAULT_ADAPTER)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".adapter=" do
|
||||
it "should set the adapter" do
|
||||
describe '.adapter=' do
|
||||
it 'should set the adapter' do
|
||||
Instapaper.adapter = :typhoeus
|
||||
expect(Instapaper.adapter).to eq(:typhoeus)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".endpoint" do
|
||||
it "should return the default endpoint" do
|
||||
describe '.endpoint' do
|
||||
it 'should return the default endpoint' do
|
||||
expect(Instapaper.endpoint).to eq(Instapaper::Configuration::DEFAULT_ENDPOINT)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".endpoint=" do
|
||||
it "should set the endpoint" do
|
||||
describe '.endpoint=' do
|
||||
it 'should set the endpoint' do
|
||||
Instapaper.endpoint = 'http://tumblr.com/'
|
||||
expect(Instapaper.endpoint).to eq('http://tumblr.com/')
|
||||
end
|
||||
end
|
||||
|
||||
describe ".user_agent" do
|
||||
it "should return the default user agent" do
|
||||
describe '.user_agent' do
|
||||
it 'should return the default user agent' do
|
||||
expect(Instapaper.user_agent).to eq(Instapaper::Configuration::DEFAULT_USER_AGENT)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".user_agent=" do
|
||||
it "should set the user_agent" do
|
||||
describe '.user_agent=' do
|
||||
it 'should set the user_agent' do
|
||||
Instapaper.user_agent = 'Custom User Agent'
|
||||
expect(Instapaper.user_agent).to eq('Custom User Agent')
|
||||
end
|
||||
end
|
||||
|
||||
describe ".version" do
|
||||
it "should return the default version" do
|
||||
describe '.version' do
|
||||
it 'should return the default version' do
|
||||
expect(Instapaper.version).to eq(Instapaper::Configuration::DEFAULT_VERSION)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".version=" do
|
||||
it "should set the user_agent" do
|
||||
describe '.version=' do
|
||||
it 'should set the user_agent' do
|
||||
Instapaper.version = '2'
|
||||
expect(Instapaper.version).to eq('2')
|
||||
end
|
||||
end
|
||||
|
||||
describe ".configure" do
|
||||
|
||||
describe '.configure' do
|
||||
Instapaper::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
||||
|
||||
it "should set the #{key}" do
|
||||
Instapaper.configure do |config|
|
||||
config.send("#{key}=", key)
|
||||
|
|
@ -81,5 +79,4 @@ describe Instapaper do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def stub_put(path)
|
|||
end
|
||||
|
||||
def fixture_path
|
||||
File.expand_path("../fixtures", __FILE__)
|
||||
File.expand_path('../fixtures', __FILE__)
|
||||
end
|
||||
|
||||
def fixture(file)
|
||||
|
|
|
|||
Loading…
Reference in a new issue