rubocop cleanup

This commit is contained in:
stve 2015-02-09 00:29:53 -05:00
parent af19561e93
commit 5161c68b5a
21 changed files with 216 additions and 236 deletions

View file

@ -6,8 +6,8 @@ Bundler::GemHelper.install_tasks
require 'rspec/core/rake_task' require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) RSpec::Core::RakeTask.new(:spec)
task :test => :spec task test: :spec
task :default => :spec task default: :spec
require 'yard' require 'yard'
YARD::Rake::YardocTask.new YARD::Rake::YardocTask.new

View file

@ -10,56 +10,56 @@ module Faraday
# general errors # general errors
when 1040 when 1040
raise Instapaper::Error.new(error_message(env, "Rate-limit exceeded.")) fail Instapaper::Error.new(error_message(env, 'Rate-limit exceeded.'))
when 1041 when 1041
raise Instapaper::Error.new(error_message(env, "Subscription account required.")) fail Instapaper::Error.new(error_message(env, 'Subscription account required.'))
when 1042 when 1042
raise Instapaper::Error.new(error_message(env, "Application is suspended.")) fail Instapaper::Error.new(error_message(env, 'Application is suspended.'))
# bookmark errors # bookmark errors
when 1220 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 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 when 1240
raise Instapaper::Error.new(error_message(env, "Invalid URL specified.")) fail Instapaper::Error.new(error_message(env, 'Invalid URL specified.'))
when 1241 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 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 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 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 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 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 # folder errors
when 1250 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 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 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 # operational errors
when 1500 when 1500
raise Instapaper::Error.new(error_message(env, "Unexpected service error.")) fail Instapaper::Error.new(error_message(env, 'Unexpected service error.'))
when 1550 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
end end
private private
def error_message(env, body=nil) def error_message(env, body = nil)
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')}." "#{env[:method].to_s.upcase} #{env[:url]}: #{[env[:status].to_s + ':', body].compact.join(' ')}."
end end
end end
end end

View file

@ -7,7 +7,7 @@ module Instapaper
# Alias for Instapaper::Client.new # Alias for Instapaper::Client.new
# #
# @return [Instapaper::Client] # @return [Instapaper::Client]
def self.client(options={}) def self.client(options = {})
Instapaper::Client.new(options) Instapaper::Client.new(options)
end end

View file

@ -8,17 +8,17 @@ module Instapaper
# @return [Hash] # @return [Hash]
def authentication def authentication
{ {
:consumer_key => consumer_key, consumer_key: consumer_key,
:consumer_secret => consumer_secret, consumer_secret: consumer_secret,
:token => oauth_token, token: oauth_token,
:token_secret => oauth_token_secret token_secret: oauth_token_secret
} }
end end
def consumer_tokens def consumer_tokens
{ {
:consumer_key => consumer_key, consumer_key: consumer_key,
:consumer_secret => consumer_secret consumer_secret: consumer_secret
} }
end end

View file

@ -8,11 +8,11 @@ module Instapaper
# @private # @private
attr_accessor *Configuration::VALID_OPTIONS_KEYS attr_accessor *Configuration::VALID_OPTIONS_KEYS
alias :api_endpoint :endpoint alias_method :api_endpoint, :endpoint
alias :api_version :version alias_method :api_version, :version
# Creates a new API # Creates a new API
def initialize(options={}) def initialize(options = {})
options = Instapaper.options.merge(options) options = Instapaper.options.merge(options)
Configuration::VALID_OPTIONS_KEYS.each do |key| Configuration::VALID_OPTIONS_KEYS.each do |key|
send("#{key}=", options[key]) send("#{key}=", options[key])

View file

@ -2,12 +2,10 @@ module Instapaper
class Client class Client
# Defines methods related to accounts # Defines methods related to accounts
module Account module Account
# Returns the currently logged in user. # Returns the currently logged in user.
def verify_credentials def verify_credentials
post('account/verify_credentials') post('account/verify_credentials')
end end
end end
end end
end end

View file

@ -2,12 +2,11 @@ module Instapaper
class Client class Client
# Defines methods related to bookmarks # Defines methods related to bookmarks
module Bookmark module Bookmark
# Lists the users unread bookmarks, and can also synchronize reading positions. # Lists the users unread bookmarks, and can also synchronize reading positions.
# @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.
def bookmarks(options={}) def bookmarks(options = {})
post('bookmarks/list', options)[2..-1] post('bookmarks/list', options)[2..-1]
end end
@ -15,67 +14,66 @@ module Instapaper
# @param bookmark_id [String] The id of the bookmark to update. # @param bookmark_id [String] The id of the bookmark to update.
# @param progress [Float] The users progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the users current viewport, expressed as a percentage of the articles total length. # @param progress [Float] The users progress, as a floating-point number between 0.0 and 1.0, defined as the top edge of the users current viewport, expressed as a percentage of the articles total length.
# @param progress_timestamp [Integer] The Unix timestamp value of the time that the progress was recorded. # @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) 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 post('bookmarks/update_read_progress', bookmark_id: bookmark_id, progress: progress, progress_timestamp: progress_timestamp.to_i).first
end end
# Adds a new unread bookmark to the users account. # Adds a new unread bookmark to the users account.
# @param url [String] The url of the bookmark. # @param url [String] The url of the bookmark.
def add_bookmark(url, options={}) def add_bookmark(url, options = {})
post('bookmarks/add', options.merge(:url => url)).first post('bookmarks/add', options.merge(url: url)).first
end end
# Permanently deletes the specified bookmark. # Permanently deletes the specified bookmark.
# This is NOT the same as Archive. Please be clear to users if youre going to do this. # This is NOT the same as Archive. Please be clear to users if youre going to do this.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def delete_bookmark(bookmark_id) def delete_bookmark(bookmark_id)
post('bookmarks/delete', :bookmark_id => bookmark_id) post('bookmarks/delete', bookmark_id: bookmark_id)
end end
# Stars the specified bookmark. # Stars the specified bookmark.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def star(bookmark_id) def star(bookmark_id)
post('bookmarks/star', :bookmark_id => bookmark_id).first post('bookmarks/star', bookmark_id: bookmark_id).first
end end
alias :star_bookmark :star alias_method :star_bookmark, :star
# Un-stars the specified bookmark. # Un-stars the specified bookmark.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def unstar(bookmark_id) def unstar(bookmark_id)
post('bookmarks/unstar', :bookmark_id => bookmark_id).first post('bookmarks/unstar', bookmark_id: bookmark_id).first
end end
alias :unstar_bookmark :unstar alias_method :unstar_bookmark, :unstar
# Moves the specified bookmark to the Archive. # Moves the specified bookmark to the Archive.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def archive(bookmark_id) def archive(bookmark_id)
post('bookmarks/archive', :bookmark_id => bookmark_id).first post('bookmarks/archive', bookmark_id: bookmark_id).first
end end
alias :archive_bookmark :archive alias_method :archive_bookmark, :archive
# Moves the specified bookmark to the top of the Unread folder. # Moves the specified bookmark to the top of the Unread folder.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def unarchive(bookmark_id) def unarchive(bookmark_id)
post('bookmarks/unarchive', :bookmark_id => bookmark_id).first post('bookmarks/unarchive', bookmark_id: bookmark_id).first
end end
alias :unarchive_bookmark :unarchive alias_method :unarchive_bookmark, :unarchive
# Moves the specified bookmark to a user-created folder. # Moves the specified bookmark to a user-created folder.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
# @param folder_id [String] The id of the folder to move the bookmark to. # @param folder_id [String] The id of the folder to move the bookmark to.
def move(bookmark_id, folder_id) 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 end
alias :move_bookmark :move alias_method :move_bookmark, :move
# Returns the specified bookmarks processed text-view HTML, which is # Returns the specified bookmarks processed text-view HTML, which is
# always text/html encoded as UTF-8. # always text/html encoded as UTF-8.
# @param bookmark_id [String] The id of the bookmark. # @param bookmark_id [String] The id of the bookmark.
def text(bookmark_id) 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 end
alias :get_text :text alias_method :get_text, :text
end end
end end
end end

View file

@ -2,7 +2,6 @@ module Instapaper
class Client class Client
# Defines methods related to folders # Defines methods related to folders
module Folder module Folder
# List the accounts user-created folders. # List the accounts user-created folders.
# @note This only includes organizational folders and does not include RSS-feed folders or starred-subscription folders # @note This only includes organizational folders and does not include RSS-feed folders or starred-subscription folders
def folders def folders
@ -12,23 +11,22 @@ module Instapaper
# Creates an organizational folder. # Creates an organizational folder.
# @param title [String] The title of the folder to create # @param title [String] The title of the folder to create
def add_folder(title) def add_folder(title)
post('folders/add', :title => title) post('folders/add', title: title)
end end
# Deletes the folder and moves any articles in it to the Archive. # Deletes the folder and moves any articles in it to the Archive.
# @param folder_id [String] The id of the folder. # @param folder_id [String] The id of the folder.
def delete_folder(folder_id) def delete_folder(folder_id)
post('folders/delete', :folder_id => folder_id) post('folders/delete', folder_id: folder_id)
end end
# Re-orders a users folders. # Re-orders a users folders.
# @param order [Array] An array of folder_id:position pairs joined by commas. # @param order [Array] An array of folder_id:position pairs joined by commas.
# @example Ordering folder_ids 100, 200, and 300 # @example Ordering folder_ids 100, 200, and 300
# Instapaper.set_order(['100:1','200:2','300:3']) # Instapaper.set_order(['100:1','200:2','300:3'])
def set_order(order=[]) def set_order(order = [])
post('folders/set_order', :order => order.join(',')) post('folders/set_order', order: order.join(','))
end end
end end
end end
end end

View file

@ -2,18 +2,16 @@ module Instapaper
class Client class Client
# Defines methods related to users # Defines methods related to users
module User module User
# Gets an OAuth access token for a user. # Gets an OAuth access token for a user.
def access_token(username, password) def access_token(username, password)
response = post('oauth/access_token', { :x_auth_username => username, :x_auth_password => password, :x_auth_mode => "client_auth"}, true) response = post('oauth/access_token', { x_auth_username: username, x_auth_password: password, x_auth_mode: 'client_auth' }, true)
params = response.body.split("&") params = response.body.split('&')
values = params.map {|part| part.split("=") }.flatten values = params.map { |part| part.split('=') }.flatten
if values.length == 1 if values.length == 1
values.unshift('error') values.unshift('error')
end end
Hash[*values] Hash[*values]
end end
end end
end end
end end

View file

@ -65,7 +65,7 @@ module Instapaper
# Create a hash of options and their values # Create a hash of options and their values
def options def options
options = {} options = {}
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) } VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
options options
end end

View file

@ -6,16 +6,14 @@ module Instapaper
module Connection module Connection
private private
def connection(raw=false) def connection(raw = false)
merged_options = connection_options.merge({ merged_options = connection_options.merge(headers: {
:headers => { 'Accept' => 'application/json',
'Accept' => "application/json", 'User-Agent' => user_agent
'User-Agent' => user_agent },
}, proxy: proxy,
:proxy => proxy, ssl: { verify: false },
:ssl => {:verify => false}, url: api_endpoint)
:url => api_endpoint
})
Faraday.new(merged_options) do |builder| Faraday.new(merged_options) do |builder|
if authenticated? if authenticated?

View file

@ -1,22 +1,20 @@
module Instapaper module Instapaper
# Defines HTTP request methods # Defines HTTP request methods
module Request module Request
# Perform an HTTP POST request # Perform an HTTP POST request
def post(path, options={}, raw=false) def post(path, options = {}, raw = false)
request(:post, path, options, raw) request(:post, path, options, raw)
end end
private private
# Perform an HTTP request # 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| response = connection(raw).send(method) do |request|
request.path = path_prefix + path request.path = path_prefix + path
request.body = options unless options.empty? request.body = options unless options.empty?
end end
raw ? response : response.body raw ? response : response.body
end end
end end
end end

View file

@ -1,3 +1,3 @@
module Instapaper module Instapaper
VERSION = "0.3.0" VERSION = '0.3.0'
end end

View file

@ -6,13 +6,13 @@ describe Faraday::Response do
end end
[1040, 1041, 1042, 1220, 1221, 1240, 1241, 1242, 1243, 1244, 1245, 1250, [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 context "when HTTP status is #{status}" do
before do before do
stub_post('folders/list').to_return(:status => status) stub_post('folders/list').to_return(status: status)
end end
it "should raise Instapaper::Error error" do it 'should raise Instapaper::Error error' do
expect do expect do
@client.folders @client.folders
end.to raise_error(Instapaper::Error) end.to raise_error(Instapaper::Error)

View file

@ -7,21 +7,20 @@ describe Instapaper::Client::Account do
describe '.verify_credentials' do describe '.verify_credentials' do
before do before do
stub_post("account/verify_credentials"). stub_post('account/verify_credentials')
to_return(:body => fixture("verify_credentials.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('verify_credentials.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.verify_credentials @client.verify_credentials
expect(a_post("account/verify_credentials")). expect(a_post('account/verify_credentials'))
to have_been_made .to have_been_made
end end
it "should return the user" do it 'should return the user' do
user = @client.verify_credentials.first user = @client.verify_credentials.first
expect(user).to be_a Hashie::Rash expect(user).to be_a Hashie::Rash
expect(user.username).to eq('TestUserOMGLOL') expect(user.username).to eq('TestUserOMGLOL')
end end
end end
end
end

View file

@ -2,28 +2,28 @@ require 'spec_helper'
describe Instapaper::Client::Bookmark do describe Instapaper::Client::Bookmark do
before(:each) 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 end
describe '.bookmarks' do describe '.bookmarks' do
before do before do
stub_post("bookmarks/list"). stub_post('bookmarks/list')
to_return(:body => fixture("bookmarks_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_list.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.bookmarks @client.bookmarks
expect(a_post("bookmarks/list")). expect(a_post('bookmarks/list'))
to have_been_made .to have_been_made
end end
it "should return an array containing bookmarks on success" do it 'should return an array containing bookmarks on success' do
bookmarks = @client.bookmarks bookmarks = @client.bookmarks
expect(bookmarks).to be_an Array expect(bookmarks).to be_an Array
expect(bookmarks.size).to eq(2) expect(bookmarks.size).to eq(2)
end 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 = @client.bookmarks
bookmarks.each do |bookmark| bookmarks.each do |bookmark|
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
@ -35,38 +35,38 @@ describe Instapaper::Client::Bookmark do
describe '.update_read_progress' do describe '.update_read_progress' do
before do before do
@time = Time.now @time = Time.now
stub_post("bookmarks/update_read_progress"). stub_post('bookmarks/update_read_progress')
to_return(:body => fixture("bookmarks_update_read_progress.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_update_read_progress.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.update_read_progress(123, 0.5, @time) @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 })). 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 .to have_been_made
end 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) bookmark = @client.update_read_progress(123, 0.5, @time)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
expect(bookmark.progress).to eq("0.5") expect(bookmark.progress).to eq('0.5')
end end
end end
describe '.add_bookmark' do describe '.add_bookmark' do
before do before do
stub_post("bookmarks/add"). stub_post('bookmarks/add')
to_return(:body => fixture('bookmarks_add.json'), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_add.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.add_bookmark('http://someurl.com', :title => 'This is the title', :description => 'This is the description') @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' })). 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 .to have_been_made
end end
it "should return the bookmark on success" do 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') 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).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
end end
@ -74,17 +74,17 @@ describe Instapaper::Client::Bookmark do
describe '.delete_bookmark' do describe '.delete_bookmark' do
before do before do
stub_post("bookmarks/delete"). stub_post('bookmarks/delete')
to_return(:body => '[]', :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: '[]', headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.delete_bookmark(123) @client.delete_bookmark(123)
expect(a_post("bookmarks/delete").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/delete').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end 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) confirm = @client.delete_bookmark(123)
expect(confirm).to be_an Array expect(confirm).to be_an Array
expect(confirm).to be_empty expect(confirm).to be_empty
@ -93,17 +93,17 @@ describe Instapaper::Client::Bookmark do
describe '.star' do describe '.star' do
before do before do
stub_post("bookmarks/star"). stub_post('bookmarks/star')
to_return(:body => fixture("bookmarks_star.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_star.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.star(123) @client.star(123)
expect(a_post("bookmarks/star").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/star').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end end
it "should return a starred bookmark on success" do it 'should return a starred bookmark on success' do
bookmark = @client.star(123) bookmark = @client.star(123)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
@ -117,17 +117,17 @@ describe Instapaper::Client::Bookmark do
describe '.unstar' do describe '.unstar' do
before do before do
stub_post("bookmarks/unstar"). stub_post('bookmarks/unstar')
to_return(:body => fixture("bookmarks_unstar.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_unstar.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.unstar(123) @client.unstar(123)
expect(a_post("bookmarks/unstar").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/unstar').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end end
it "should return an unstarred bookmark on success" do it 'should return an unstarred bookmark on success' do
bookmark = @client.unstar(123) bookmark = @client.unstar(123)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
@ -141,17 +141,17 @@ describe Instapaper::Client::Bookmark do
describe '.archive' do describe '.archive' do
before do before do
stub_post("bookmarks/archive"). stub_post('bookmarks/archive')
to_return(:body => fixture("bookmarks_archive.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_archive.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.archive(123) @client.archive(123)
expect(a_post("bookmarks/archive").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/archive').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end end
it "should return the bookmark on success" do it 'should return the bookmark on success' do
bookmark = @client.archive(123) bookmark = @client.archive(123)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
@ -164,17 +164,17 @@ describe Instapaper::Client::Bookmark do
describe '.unarchive' do describe '.unarchive' do
before do before do
stub_post("bookmarks/unarchive"). stub_post('bookmarks/unarchive')
to_return(:body => fixture("bookmarks_unarchive.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_unarchive.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.unarchive(123) @client.unarchive(123)
expect(a_post("bookmarks/unarchive").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/unarchive').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end end
it "should return the bookmark on success" do it 'should return the bookmark on success' do
bookmark = @client.unarchive(123) bookmark = @client.unarchive(123)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
@ -187,37 +187,37 @@ describe Instapaper::Client::Bookmark do
describe '.move' do describe '.move' do
before do before do
stub_post("bookmarks/move"). stub_post('bookmarks/move')
to_return(:body => fixture("bookmarks_move.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('bookmarks_move.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.move(123, 12345) @client.move(123, 12_345)
expect(a_post("bookmarks/move").with(:body => {:bookmark_id => "123", :folder_id => "12345" })). expect(a_post('bookmarks/move').with(body: { bookmark_id: '123', folder_id: '12345' }))
to have_been_made .to have_been_made
end end
it "should return the bookmark on success" do it 'should return the bookmark on success' do
bookmark = @client.move(123, 12345) bookmark = @client.move(123, 12_345)
expect(bookmark).to be_a Hashie::Rash expect(bookmark).to be_a Hashie::Rash
expect(bookmark.type).to eq('bookmark') expect(bookmark.type).to eq('bookmark')
end end
it 'should be aliased as .move_bookmark' do 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
end end
describe '.text' do describe '.text' do
before do before do
stub_post("bookmarks/get_text"). stub_post('bookmarks/get_text')
to_return(:body => fixture("bookmarks_get_text.txt"), :headers => {:content_type => "text/html; charset=utf-8"}) .to_return(body: fixture('bookmarks_get_text.txt'), headers: { content_type: 'text/html; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.text(123) @client.text(123)
expect(a_post("bookmarks/get_text").with(:body => {:bookmark_id => "123" })). expect(a_post('bookmarks/get_text').with(body: { bookmark_id: '123' }))
to have_been_made .to have_been_made
end end
it "should return the bookmark's html on success" do 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)) expect(@client.text(123)).to eq(@client.get_text(123))
end end
end end
end end

View file

@ -7,17 +7,17 @@ describe Instapaper::Client::Folder do
describe '.folders' do describe '.folders' do
before do before do
stub_post("folders/list"). stub_post('folders/list')
to_return(:body => fixture("folders_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('folders_list.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.folders @client.folders
expect(a_post("folders/list")). expect(a_post('folders/list'))
to have_been_made .to have_been_made
end end
it "should return an array containing folders on success" do it 'should return an array containing folders on success' do
folders = @client.folders folders = @client.folders
expect(folders).to be_an Array expect(folders).to be_an Array
expect(folders.size).to eq(2) expect(folders.size).to eq(2)
@ -28,18 +28,18 @@ describe Instapaper::Client::Folder do
describe '.add_folder' do describe '.add_folder' do
before do before do
stub_post("folders/add").with(:body => {:title => "Ruby" }). stub_post('folders/add').with(body: { title: 'Ruby' })
to_return(:body => fixture("folders_add.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('folders_add.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.add_folder("Ruby") @client.add_folder('Ruby')
expect(a_post("folders/add")). expect(a_post('folders/add'))
to have_been_made .to have_been_made
end end
it "should return an array containing the new folder on success" do it 'should return an array containing the new folder on success' do
folders = @client.add_folder("Ruby") folders = @client.add_folder('Ruby')
expect(folders).to be_an Array expect(folders).to be_an Array
expect(folders).not_to be_empty expect(folders).not_to be_empty
expect(folders.first).to be_a Hashie::Rash expect(folders.first).to be_a Hashie::Rash
@ -49,18 +49,18 @@ describe Instapaper::Client::Folder do
describe '.delete_folder' do describe '.delete_folder' do
before do before do
stub_post("folders/delete"). with(:body => {:folder_id => "1" }). stub_post('folders/delete'). with(body: { folder_id: '1' })
to_return(:body => fixture("folders_delete.json"), :headers => {:content_type => "application/json; charset=utf-8"}) .to_return(body: fixture('folders_delete.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.delete_folder("1") @client.delete_folder('1')
expect(a_post("folders/delete")). expect(a_post('folders/delete'))
to have_been_made .to have_been_made
end end
it "should return an empty array on success" do it 'should return an empty array on success' do
confirm = @client.delete_folder("1") confirm = @client.delete_folder('1')
expect(confirm).to be_an Array expect(confirm).to be_an Array
expect(confirm).to be_empty expect(confirm).to be_empty
end end
@ -68,22 +68,21 @@ describe Instapaper::Client::Folder do
describe '.set_order' do describe '.set_order' do
before do before do
stub_post("folders/set_order"). with(:body => {:order => "1121173:2,1121174:1" }). 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"}) .to_return(body: fixture('folders_set_order.json'), headers: { content_type: 'application/json; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.set_order(['1121173:2','1121174:1']) @client.set_order(['1121173:2', '1121174:1'])
expect(a_post("folders/set_order")). expect(a_post('folders/set_order'))
to have_been_made .to have_been_made
end end
it "should return an array reflecting the new order on success" do it 'should return an array reflecting the new order on success' do
folders = @client.set_order(['1121173:2','1121174:1']) folders = @client.set_order(['1121173:2', '1121174:1'])
expect(folders).to be_an Array expect(folders).to be_an Array
expect(folders.first).to be_a Hashie::Rash expect(folders.first).to be_a Hashie::Rash
expect(folders.first['position']).to eq(1) expect(folders.first['position']).to eq(1)
end end
end end
end
end

View file

@ -7,30 +7,29 @@ describe Instapaper::Client::User do
describe '.access_token' do describe '.access_token' do
before do before do
stub_post("oauth/access_token").with(:body => { :x_auth_username => 'ohai', :x_auth_password => 'p455w0rd', :x_auth_mode => 'client_auth'}). 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"}) .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'}). 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"}) .to_return(body: fixture('invalid_credentials.qline'), headers: { content_type: 'text/plain; charset=utf-8' })
end end
it "should get the correct resource" do it 'should get the correct resource' do
@client.access_token('ohai', 'p455w0rd') @client.access_token('ohai', 'p455w0rd')
expect(a_post("oauth/access_token")). expect(a_post('oauth/access_token'))
to have_been_made .to have_been_made
end 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') tokens = @client.access_token('ohai', 'p455w0rd')
expect(tokens).to be_a Hash expect(tokens).to be_a Hash
expect(tokens.key?('oauth_token')).to be true expect(tokens.key?('oauth_token')).to be true
expect(tokens.key?('oauth_token_secret')).to be true expect(tokens.key?('oauth_token_secret')).to be true
end 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') tokens = @client.access_token('inval1d', 'cr3dentials')
expect(tokens).to be_a Hash expect(tokens).to be_a Hash
expect(tokens.key?('error')).to be true expect(tokens.key?('error')).to be true
end end
end end
end end

View file

@ -1,9 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe Instapaper::Client do describe Instapaper::Client do
before 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 @keys = Instapaper::Configuration::VALID_OPTIONS_KEYS
end end
@ -19,7 +18,7 @@ describe Instapaper::Client do
end end
context 'with module configuration' do context 'with module configuration' do
it "should inherit module configuration" do it 'should inherit module configuration' do
api = Instapaper::Client.new api = Instapaper::Client.new
@keys.each do |key| @keys.each do |key|
expect(api.send(key)).to eq(key) expect(api.send(key)).to eq(key)
@ -28,24 +27,24 @@ describe Instapaper::Client do
end end
context 'with class configuration' do context 'with class configuration' do
context "during initialization" do context 'during initialization' do
it "should override module configuration" do it 'should override module configuration' do
api = Instapaper::Client.new(@options) api = Instapaper::Client.new(@options)
@keys.each do |key| @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]) expect(api.send(key)).to eq(h[key])
end end
end end
end end
context "after initialization" do context 'after initialization' do
it "should override module configuration after initialization" do it 'should override module configuration after initialization' do
api = Instapaper::Client.new api = Instapaper::Client.new
@options.each do |key, value| @options.each do |key, value|
api.send("#{key}=", value) api.send("#{key}=", value)
end end
@keys.each do |key| @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]) expect(api.send(key)).to eq(h[key])
end end
end end
@ -62,4 +61,4 @@ describe Instapaper::Client do
expect(@client.endpoint_with_prefix).to eq(Instapaper.endpoint + Instapaper.path_prefix) expect(@client.endpoint_with_prefix).to eq(Instapaper.endpoint + Instapaper.path_prefix)
end end
end end
end end

View file

@ -11,68 +11,66 @@ describe Instapaper do
end end
end end
describe ".client" do describe '.client' do
it "should be a Instapaper::Client" do it 'should be a Instapaper::Client' do
expect(Instapaper.client).to be_a Instapaper::Client expect(Instapaper.client).to be_a Instapaper::Client
end end
end end
describe ".adapter" do describe '.adapter' do
it "should return the default adapter" do it 'should return the default adapter' do
expect(Instapaper.adapter).to eq(Instapaper::Configuration::DEFAULT_ADAPTER) expect(Instapaper.adapter).to eq(Instapaper::Configuration::DEFAULT_ADAPTER)
end end
end end
describe ".adapter=" do describe '.adapter=' do
it "should set the adapter" do it 'should set the adapter' do
Instapaper.adapter = :typhoeus Instapaper.adapter = :typhoeus
expect(Instapaper.adapter).to eq(:typhoeus) expect(Instapaper.adapter).to eq(:typhoeus)
end end
end end
describe ".endpoint" do describe '.endpoint' do
it "should return the default endpoint" do it 'should return the default endpoint' do
expect(Instapaper.endpoint).to eq(Instapaper::Configuration::DEFAULT_ENDPOINT) expect(Instapaper.endpoint).to eq(Instapaper::Configuration::DEFAULT_ENDPOINT)
end end
end end
describe ".endpoint=" do describe '.endpoint=' do
it "should set the endpoint" do it 'should set the endpoint' do
Instapaper.endpoint = 'http://tumblr.com/' Instapaper.endpoint = 'http://tumblr.com/'
expect(Instapaper.endpoint).to eq('http://tumblr.com/') expect(Instapaper.endpoint).to eq('http://tumblr.com/')
end end
end end
describe ".user_agent" do describe '.user_agent' do
it "should return the default user agent" do it 'should return the default user agent' do
expect(Instapaper.user_agent).to eq(Instapaper::Configuration::DEFAULT_USER_AGENT) expect(Instapaper.user_agent).to eq(Instapaper::Configuration::DEFAULT_USER_AGENT)
end end
end end
describe ".user_agent=" do describe '.user_agent=' do
it "should set the user_agent" do it 'should set the user_agent' do
Instapaper.user_agent = 'Custom User Agent' Instapaper.user_agent = 'Custom User Agent'
expect(Instapaper.user_agent).to eq('Custom User Agent') expect(Instapaper.user_agent).to eq('Custom User Agent')
end end
end end
describe ".version" do describe '.version' do
it "should return the default version" do it 'should return the default version' do
expect(Instapaper.version).to eq(Instapaper::Configuration::DEFAULT_VERSION) expect(Instapaper.version).to eq(Instapaper::Configuration::DEFAULT_VERSION)
end end
end end
describe ".version=" do describe '.version=' do
it "should set the user_agent" do it 'should set the user_agent' do
Instapaper.version = '2' Instapaper.version = '2'
expect(Instapaper.version).to eq('2') expect(Instapaper.version).to eq('2')
end end
end end
describe ".configure" do describe '.configure' do
Instapaper::Configuration::VALID_OPTIONS_KEYS.each do |key| Instapaper::Configuration::VALID_OPTIONS_KEYS.each do |key|
it "should set the #{key}" do it "should set the #{key}" do
Instapaper.configure do |config| Instapaper.configure do |config|
config.send("#{key}=", key) config.send("#{key}=", key)
@ -81,5 +79,4 @@ describe Instapaper do
end end
end end
end end
end end

View file

@ -44,7 +44,7 @@ def stub_put(path)
end end
def fixture_path def fixture_path
File.expand_path("../fixtures", __FILE__) File.expand_path('../fixtures', __FILE__)
end end
def fixture(file) def fixture(file)