diff --git a/Rakefile b/Rakefile index d18b887..d00ec43 100755 --- a/Rakefile +++ b/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 \ No newline at end of file +YARD::Rake::YardocTask.new diff --git a/lib/faraday/response/raise_http_1xxx.rb b/lib/faraday/response/raise_http_1xxx.rb index 58101b3..e543934 100644 --- a/lib/faraday/response/raise_http_1xxx.rb +++ b/lib/faraday/response/raise_http_1xxx.rb @@ -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 \ No newline at end of file +end diff --git a/lib/instapaper.rb b/lib/instapaper.rb index 68b992c..7b8ed04 100644 --- a/lib/instapaper.rb +++ b/lib/instapaper.rb @@ -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 diff --git a/lib/instapaper/authentication.rb b/lib/instapaper/authentication.rb index b035f69..65f0399 100644 --- a/lib/instapaper/authentication.rb +++ b/lib/instapaper/authentication.rb @@ -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 diff --git a/lib/instapaper/client.rb b/lib/instapaper/client.rb index c3b4dcf..1369e2d 100644 --- a/lib/instapaper/client.rb +++ b/lib/instapaper/client.rb @@ -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]) diff --git a/lib/instapaper/client/account.rb b/lib/instapaper/client/account.rb index 27c4417..a92b71e 100644 --- a/lib/instapaper/client/account.rb +++ b/lib/instapaper/client/account.rb @@ -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 diff --git a/lib/instapaper/client/bookmark.rb b/lib/instapaper/client/bookmark.rb index 49458f8..0cdb497 100644 --- a/lib/instapaper/client/bookmark.rb +++ b/lib/instapaper/client/bookmark.rb @@ -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 diff --git a/lib/instapaper/client/folder.rb b/lib/instapaper/client/folder.rb index 60a862b..ef99036 100644 --- a/lib/instapaper/client/folder.rb +++ b/lib/instapaper/client/folder.rb @@ -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 diff --git a/lib/instapaper/client/user.rb b/lib/instapaper/client/user.rb index f03cdf4..879364e 100644 --- a/lib/instapaper/client/user.rb +++ b/lib/instapaper/client/user.rb @@ -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 diff --git a/lib/instapaper/configuration.rb b/lib/instapaper/configuration.rb index 1c3ad9f..4aa0532 100644 --- a/lib/instapaper/configuration.rb +++ b/lib/instapaper/configuration.rb @@ -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 diff --git a/lib/instapaper/connection.rb b/lib/instapaper/connection.rb index 0ad3486..0395415 100644 --- a/lib/instapaper/connection.rb +++ b/lib/instapaper/connection.rb @@ -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? diff --git a/lib/instapaper/request.rb b/lib/instapaper/request.rb index d344c56..c55675b 100644 --- a/lib/instapaper/request.rb +++ b/lib/instapaper/request.rb @@ -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 diff --git a/lib/instapaper/version.rb b/lib/instapaper/version.rb index 8646e68..de5189b 100644 --- a/lib/instapaper/version.rb +++ b/lib/instapaper/version.rb @@ -1,3 +1,3 @@ module Instapaper - VERSION = "0.3.0" + VERSION = '0.3.0' end diff --git a/spec/faraday/response_spec.rb b/spec/faraday/response_spec.rb index 443091d..79c2921 100644 --- a/spec/faraday/response_spec.rb +++ b/spec/faraday/response_spec.rb @@ -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) diff --git a/spec/instapaper/client/account_spec.rb b/spec/instapaper/client/account_spec.rb index b8e852f..4b1afdb 100644 --- a/spec/instapaper/client/account_spec.rb +++ b/spec/instapaper/client/account_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/instapaper/client/bookmark_spec.rb b/spec/instapaper/client/bookmark_spec.rb index 0a5281c..c62ba88 100644 --- a/spec/instapaper/client/bookmark_spec.rb +++ b/spec/instapaper/client/bookmark_spec.rb @@ -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 diff --git a/spec/instapaper/client/folder_spec.rb b/spec/instapaper/client/folder_spec.rb index 41338f8..5674310 100644 --- a/spec/instapaper/client/folder_spec.rb +++ b/spec/instapaper/client/folder_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/instapaper/client/user_spec.rb b/spec/instapaper/client/user_spec.rb index beb57f2..08cc049 100644 --- a/spec/instapaper/client/user_spec.rb +++ b/spec/instapaper/client/user_spec.rb @@ -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 diff --git a/spec/instapaper/client_spec.rb b/spec/instapaper/client_spec.rb index 808ec57..8ea8716 100644 --- a/spec/instapaper/client_spec.rb +++ b/spec/instapaper/client_spec.rb @@ -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 \ No newline at end of file +end diff --git a/spec/instapaper_spec.rb b/spec/instapaper_spec.rb index 434d380..dab6792 100644 --- a/spec/instapaper_spec.rb +++ b/spec/instapaper_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a48c7b0..178ee64 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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)