From 96af63d42d2ae69a03c5c7e6a6462565602a8ddd Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 28 Sep 2015 10:17:20 -0500 Subject: [PATCH 01/28] Adding error handling class --- lib/open_calais/calais_error.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 lib/open_calais/calais_error.rb diff --git a/lib/open_calais/calais_error.rb b/lib/open_calais/calais_error.rb new file mode 100644 index 0000000..377f029 --- /dev/null +++ b/lib/open_calais/calais_error.rb @@ -0,0 +1,8 @@ +class CalaisError < StandardError + attr_reader :object + + def initialize(object) + @object = object + end + +end \ No newline at end of file From 4661d1058e30cb5c5fc700174185f5835c0076e8 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 28 Sep 2015 10:23:09 -0500 Subject: [PATCH 02/28] Moving to module to hijack Faraday errors --- lib/open_calais/calais_error.rb | 15 ++++++++------- test/error_test.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 test/error_test.rb diff --git a/lib/open_calais/calais_error.rb b/lib/open_calais/calais_error.rb index 377f029..ea95783 100644 --- a/lib/open_calais/calais_error.rb +++ b/lib/open_calais/calais_error.rb @@ -1,8 +1,9 @@ -class CalaisError < StandardError - attr_reader :object - - def initialize(object) - @object = object +module Errors + class RaiseError < Faraday::Response::Middleware + + def on_complete(env) + raise Errors::NotFound if env[:status] == 404 + end + end - -end \ No newline at end of file +end diff --git a/test/error_test.rb b/test/error_test.rb new file mode 100644 index 0000000..547616b --- /dev/null +++ b/test/error_test.rb @@ -0,0 +1,10 @@ +require File.expand_path(File.dirname(__FILE__) + '/test_helper') + +describe OpenCalais::Client do + + it "is initialized with defaults" do + oc = OpenCalais::Client.new + oc.current_options.wont_be_nil + oc.current_options.must_equal OpenCalais.options + end +end From 85483e1f271912b7f4ac2e6a2341428a9d33c25c Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 28 Sep 2015 10:23:33 -0500 Subject: [PATCH 03/28] Fix name --- lib/open_calais/calais_error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_calais/calais_error.rb b/lib/open_calais/calais_error.rb index ea95783..2f7fe6d 100644 --- a/lib/open_calais/calais_error.rb +++ b/lib/open_calais/calais_error.rb @@ -1,5 +1,5 @@ module Errors - class RaiseError < Faraday::Response::Middleware + class CalaisError < Faraday::Response::Middleware def on_complete(env) raise Errors::NotFound if env[:status] == 404 From ab88aa6ee6869e3b1ba1f0c62784c0503c8118a8 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 28 Sep 2015 10:26:20 -0500 Subject: [PATCH 04/28] adding first 404 error --- lib/{open_calais => errors}/calais_error.rb | 0 lib/errors/not_found.rb | 4 ++++ 2 files changed, 4 insertions(+) rename lib/{open_calais => errors}/calais_error.rb (100%) create mode 100644 lib/errors/not_found.rb diff --git a/lib/open_calais/calais_error.rb b/lib/errors/calais_error.rb similarity index 100% rename from lib/open_calais/calais_error.rb rename to lib/errors/calais_error.rb diff --git a/lib/errors/not_found.rb b/lib/errors/not_found.rb new file mode 100644 index 0000000..d2f6640 --- /dev/null +++ b/lib/errors/not_found.rb @@ -0,0 +1,4 @@ +module Errors + class NotFound < StandardError + end +end \ No newline at end of file From 82b771de2387891221661de8d7e38209cd138221 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 28 Sep 2015 11:43:08 -0500 Subject: [PATCH 05/28] wip for relocation --- lib/errors/calais_error.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 lib/errors/calais_error.rb diff --git a/lib/errors/calais_error.rb b/lib/errors/calais_error.rb deleted file mode 100644 index 2f7fe6d..0000000 --- a/lib/errors/calais_error.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Errors - class CalaisError < Faraday::Response::Middleware - - def on_complete(env) - raise Errors::NotFound if env[:status] == 404 - end - - end -end From e067a115e96bf81191fd9571d5bc0a52fc5b333d Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Tue, 29 Sep 2015 09:15:27 -0500 Subject: [PATCH 06/28] adding raise error class --- lib/errors/raise_error.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/errors/raise_error.rb diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb new file mode 100644 index 0000000..ef6bfde --- /dev/null +++ b/lib/errors/raise_error.rb @@ -0,0 +1,10 @@ +module Errors + class RaiseError < Faraday::Response::Middleware + + def on_complete(env) + raise Errors::NotFound if env[:status] == 404 + raise Errors::AuthError if env[:status] == 401 + end + + end +end From 79e5247685ba6fc52e4abc1faf98fc3ea5c4792e Mon Sep 17 00:00:00 2001 From: cometman Date: Tue, 29 Sep 2015 09:29:06 -0500 Subject: [PATCH 07/28] adding 401 error --- lib/errors/denied_error.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lib/errors/denied_error.rb diff --git a/lib/errors/denied_error.rb b/lib/errors/denied_error.rb new file mode 100644 index 0000000..4f0363a --- /dev/null +++ b/lib/errors/denied_error.rb @@ -0,0 +1,5 @@ +module Errors + class DeniedError < StandardError + + end +end \ No newline at end of file From 5d100f7efb2e170fc15d9bb27d548e63e257d0df Mon Sep 17 00:00:00 2001 From: cometman Date: Tue, 29 Sep 2015 10:16:03 -0500 Subject: [PATCH 08/28] Adding test for 401's --- lib/errors/raise_error.rb | 5 ++++- lib/open_calais/client.rb | 1 + lib/open_calais/connection.rb | 2 +- test/error_test.rb | 7 +++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index ef6bfde..50a8cfe 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -1,9 +1,12 @@ +require "errors/denied_error" +require "errors/not_found" + module Errors class RaiseError < Faraday::Response::Middleware def on_complete(env) raise Errors::NotFound if env[:status] == 404 - raise Errors::AuthError if env[:status] == 401 + raise Errors::DeniedError if env[:status] == 401 end end diff --git a/lib/open_calais/client.rb b/lib/open_calais/client.rb index 2c75826..1e28cf8 100644 --- a/lib/open_calais/client.rb +++ b/lib/open_calais/client.rb @@ -3,6 +3,7 @@ require 'open_calais/configuration' require 'open_calais/connection' require 'open_calais/response' +require 'errors/raise_error' module OpenCalais class Client diff --git a/lib/open_calais/connection.rb b/lib/open_calais/connection.rb index 6eabdbd..6c72ac4 100644 --- a/lib/open_calais/connection.rb +++ b/lib/open_calais/connection.rb @@ -48,7 +48,7 @@ def connection(options={}) else connection.response :xml end - + connection.use Errors::RaiseError connection.adapter(adapter) end diff --git a/test/error_test.rb b/test/error_test.rb index 547616b..3e52b68 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -2,9 +2,8 @@ describe OpenCalais::Client do - it "is initialized with defaults" do - oc = OpenCalais::Client.new - oc.current_options.wont_be_nil - oc.current_options.must_equal OpenCalais.options + it "is throws 401 auth error for bad api key." do + oc = OpenCalais::Client.new(:api_key => 'bad_KEY') + -> { oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::DeniedError end end From 4bede03d64f9819e3841fda3466edd1094f5f5ef Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 12 Oct 2015 07:35:03 -0500 Subject: [PATCH 09/28] adding more error catching --- lib/errors/auth_error.rb | 4 ++++ lib/errors/bad_content.rb | 4 ++++ lib/errors/invalid_format.rb | 4 ++++ lib/errors/not_found.rb | 4 ---- lib/errors/raise_error.rb | 12 ++++++++++-- lib/errors/rate_limit_exceeded.rb | 4 ++++ lib/errors/resource_not_found.rb | 4 ++++ open_calais.gemspec | 1 + test/test_helper.rb | 1 + 9 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 lib/errors/auth_error.rb create mode 100644 lib/errors/bad_content.rb create mode 100644 lib/errors/invalid_format.rb delete mode 100644 lib/errors/not_found.rb create mode 100644 lib/errors/rate_limit_exceeded.rb create mode 100644 lib/errors/resource_not_found.rb diff --git a/lib/errors/auth_error.rb b/lib/errors/auth_error.rb new file mode 100644 index 0000000..531bfc7 --- /dev/null +++ b/lib/errors/auth_error.rb @@ -0,0 +1,4 @@ +module Errors + class AuthError < StandardError + end +end \ No newline at end of file diff --git a/lib/errors/bad_content.rb b/lib/errors/bad_content.rb new file mode 100644 index 0000000..ac4dc31 --- /dev/null +++ b/lib/errors/bad_content.rb @@ -0,0 +1,4 @@ +module Errors + class BadContent < StandardError + end +end \ No newline at end of file diff --git a/lib/errors/invalid_format.rb b/lib/errors/invalid_format.rb new file mode 100644 index 0000000..ca901a3 --- /dev/null +++ b/lib/errors/invalid_format.rb @@ -0,0 +1,4 @@ +module Errors + class InvalidFormat < StandardError + end +end diff --git a/lib/errors/not_found.rb b/lib/errors/not_found.rb deleted file mode 100644 index d2f6640..0000000 --- a/lib/errors/not_found.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class NotFound < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index ef6bfde..8069000 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -2,8 +2,16 @@ module Errors class RaiseError < Faraday::Response::Middleware def on_complete(env) - raise Errors::NotFound if env[:status] == 404 - raise Errors::AuthError if env[:status] == 401 + case env[:status] + when 429 + raise Errors::RateLimitExceeded + when 404 + raise Errors::ResourceNotFound + when 401 + raise Errors::AuthError + when 400 + raise Errors::BadContent + end end end diff --git a/lib/errors/rate_limit_exceeded.rb b/lib/errors/rate_limit_exceeded.rb new file mode 100644 index 0000000..d12750c --- /dev/null +++ b/lib/errors/rate_limit_exceeded.rb @@ -0,0 +1,4 @@ +module Errors + class RateLimitExceeded < StandardError + end +end \ No newline at end of file diff --git a/lib/errors/resource_not_found.rb b/lib/errors/resource_not_found.rb new file mode 100644 index 0000000..660f89d --- /dev/null +++ b/lib/errors/resource_not_found.rb @@ -0,0 +1,4 @@ +module Errors + class ResourceNotFound < StandardError + end +end \ No newline at end of file diff --git a/open_calais.gemspec b/open_calais.gemspec index c6a2828..95b1b68 100644 --- a/open_calais.gemspec +++ b/open_calais.gemspec @@ -30,4 +30,5 @@ Gem::Specification.new do |gem| gem.add_development_dependency('minitest') gem.add_development_dependency('simplecov') gem.add_development_dependency('coveralls') + gem.add_development_dependency('byebug') end diff --git a/test/test_helper.rb b/test/test_helper.rb index 23e7c6e..5a95a87 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,5 +10,6 @@ require 'minitest/spec' require 'minitest/autorun' +require 'byebug' require 'open_calais' From b7f4400858234e5c541f57e6beb258e5e5b67bf6 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 12 Oct 2015 11:02:02 -0500 Subject: [PATCH 10/28] Fixing unit test --- lib/errors/raise_error.rb | 6 ++++++ test/error_test.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index 8069000..465d3ba 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -1,3 +1,9 @@ +require "errors/rate_limit_exceeded" +require "errors/denied_error" +require "errors/auth_error" +require "errors/bad_content" +require "errors/resource_not_found" + module Errors class RaiseError < Faraday::Response::Middleware diff --git a/test/error_test.rb b/test/error_test.rb index 3e52b68..acb2790 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -4,6 +4,6 @@ it "is throws 401 auth error for bad api key." do oc = OpenCalais::Client.new(:api_key => 'bad_KEY') - -> { oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::DeniedError + -> { oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::AuthError end end From 1b1dd796962ff594d5f51e788d05c986b531d355 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Mon, 12 Oct 2015 11:06:04 -0500 Subject: [PATCH 11/28] Adding last 2 errors --- lib/errors/bad_media.rb | 4 ++++ lib/errors/denied_error.rb | 5 ----- lib/errors/large_entity.rb | 5 +++++ lib/errors/raise_error.rb | 6 ++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 lib/errors/bad_media.rb delete mode 100644 lib/errors/denied_error.rb create mode 100644 lib/errors/large_entity.rb diff --git a/lib/errors/bad_media.rb b/lib/errors/bad_media.rb new file mode 100644 index 0000000..9f3c968 --- /dev/null +++ b/lib/errors/bad_media.rb @@ -0,0 +1,4 @@ +module Errors + class BadMedia < StandardError + end +end \ No newline at end of file diff --git a/lib/errors/denied_error.rb b/lib/errors/denied_error.rb deleted file mode 100644 index 4f0363a..0000000 --- a/lib/errors/denied_error.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Errors - class DeniedError < StandardError - - end -end \ No newline at end of file diff --git a/lib/errors/large_entity.rb b/lib/errors/large_entity.rb new file mode 100644 index 0000000..e545b10 --- /dev/null +++ b/lib/errors/large_entity.rb @@ -0,0 +1,5 @@ +module Errors + class LargeEntity < StandardError + + end +end \ No newline at end of file diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index 465d3ba..056deba 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -11,6 +11,12 @@ def on_complete(env) case env[:status] when 429 raise Errors::RateLimitExceeded + when 415 + raise Errors::BadMedia + when 413 + raise Errors::LargeEntity + when 406 + raise Errors::InvalidFormat when 404 raise Errors::ResourceNotFound when 401 From c70cbc8bd1ac05a2401a0277d3c86b698d7c261f Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Tue, 13 Oct 2015 16:38:44 -0500 Subject: [PATCH 12/28] adding server errors --- lib/errors/raise_error.rb | 4 ++++ lib/errors/server_error.rb | 4 ++++ lib/errors/service_unavailable.rb | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 lib/errors/server_error.rb create mode 100644 lib/errors/service_unavailable.rb diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index 056deba..20dc4bd 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -9,6 +9,10 @@ class RaiseError < Faraday::Response::Middleware def on_complete(env) case env[:status] + when 503 + raise Errors::ServiceUnavailable + when 500 + raise Errors::ServerError when 429 raise Errors::RateLimitExceeded when 415 diff --git a/lib/errors/server_error.rb b/lib/errors/server_error.rb new file mode 100644 index 0000000..7357544 --- /dev/null +++ b/lib/errors/server_error.rb @@ -0,0 +1,4 @@ +module Errors + class Server < StandardError + end +end \ No newline at end of file diff --git a/lib/errors/service_unavailable.rb b/lib/errors/service_unavailable.rb new file mode 100644 index 0000000..2906590 --- /dev/null +++ b/lib/errors/service_unavailable.rb @@ -0,0 +1,4 @@ +module Errors + class ServiceUnavailable < StandardError + end +end \ No newline at end of file From aab1294aa749306bac161406a561cbcc72015cb2 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Wed, 14 Oct 2015 14:41:13 -0500 Subject: [PATCH 13/28] Adding more tests and refcatoring --- lib/errors/raise_error.rb | 7 ++--- lib/errors/server_error.rb | 2 +- open_calais.gemspec | 1 + test/client_test.rb | 4 +++ test/error_test.rb | 62 ++++++++++++++++++++++++++++++++++++-- test/test_helper.rb | 6 ++++ 6 files changed, 73 insertions(+), 9 deletions(-) diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb index 20dc4bd..8fdc825 100644 --- a/lib/errors/raise_error.rb +++ b/lib/errors/raise_error.rb @@ -1,8 +1,5 @@ -require "errors/rate_limit_exceeded" -require "errors/denied_error" -require "errors/auth_error" -require "errors/bad_content" -require "errors/resource_not_found" +#Dir["errors/*.rb"].each {|file| require file } +Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file } module Errors class RaiseError < Faraday::Response::Middleware diff --git a/lib/errors/server_error.rb b/lib/errors/server_error.rb index 7357544..5138b97 100644 --- a/lib/errors/server_error.rb +++ b/lib/errors/server_error.rb @@ -1,4 +1,4 @@ module Errors - class Server < StandardError + class ServerError < StandardError end end \ No newline at end of file diff --git a/open_calais.gemspec b/open_calais.gemspec index 95b1b68..8b9f21b 100644 --- a/open_calais.gemspec +++ b/open_calais.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.add_runtime_dependency('faraday') + gem.add_runtime_dependency('webmock') gem.add_runtime_dependency('faraday_middleware') gem.add_runtime_dependency('multi_json') gem.add_runtime_dependency('multi_xml') diff --git a/test/client_test.rb b/test/client_test.rb index 2f4c9ad..2c101ed 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -2,6 +2,10 @@ describe OpenCalais::Client do + before :each do + sleep(1) + end + it "is initialized with defaults" do oc = OpenCalais::Client.new oc.current_options.wont_be_nil diff --git a/test/error_test.rb b/test/error_test.rb index acb2790..788fbde 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -2,8 +2,64 @@ describe OpenCalais::Client do - it "is throws 401 auth error for bad api key." do - oc = OpenCalais::Client.new(:api_key => 'bad_KEY') - -> { oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::AuthError + before :each do + @oc = OpenCalais::Client.new(:api_key => '') end + + it "should throw a AuthError for bad api key." do + WebMock.disable! + -> { @oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::AuthError + end + + it "should throw a ServiceUnavailable error" do + WebMock.enable! + mock_call(:status => 503) + -> { @oc.enrich("Test") }.must_raise Errors::ServiceUnavailable + end + + it "should throw a ServerError error" do + WebMock.enable! + mock_call(:status => 500) + -> { @oc.enrich("Test") }.must_raise Errors::ServerError + end + + it "should throw a RateLimitExceeded error" do + WebMock.enable! + mock_call(:status => 429) + -> { @oc.enrich("Test") }.must_raise Errors::RateLimitExceeded + end + + it "should throw a BadMedia error" do + WebMock.enable! + mock_call(:status => 415) + -> { @oc.enrich("Test") }.must_raise Errors::BadMedia + end + + it "should throw a InvalidFormat error" do + WebMock.enable! + mock_call(:status => 406) + -> { @oc.enrich("Test") }.must_raise Errors::InvalidFormat + end + + it "should throw a ResourceNotFound error" do + WebMock.enable! + mock_call(:status => 404) + -> { @oc.enrich("Test") }.must_raise Errors::ResourceNotFound + end + + it "should throw a AuthError error" do + WebMock.enable! + mock_call(:status => 401) + -> { @oc.enrich("Test") }.must_raise Errors::AuthError + end + + it "should throw a BadContent error" do + WebMock.enable! + mock_call(:status => 400) + -> { @oc.enrich("Test") }.must_raise Errors::BadContent + end +end + +def mock_call(options) + stub_request(:any, /.*#{CALAIS_API}.*/).to_return(options, :headers => { 'Content-Length' => 3 }) end diff --git a/test/test_helper.rb b/test/test_helper.rb index 5a95a87..6e1030c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,3 +13,9 @@ require 'byebug' require 'open_calais' + +require 'webmock' +include WebMock::API +CALAIS_API = "api.thomsonreuters.com" + +WebMock.disable! From 955fb0483491aadc8d10f370475ad1270059315d Mon Sep 17 00:00:00 2001 From: Ted Han Date: Tue, 27 Oct 2015 09:46:22 -0700 Subject: [PATCH 14/28] Fix stray commit here too. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 560cd4d..df91189 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -CLA# OpenCalais +# OpenCalais [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.org/PRX/open_calais.svg?branch=master)](https://travis-ci.org/PRX/open_calais) From d94cd8ad3d4fa96e4848c236f395663738a2fc77 Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Fri, 30 Oct 2015 11:02:36 -0500 Subject: [PATCH 15/28] Adding code from refactoring --- lib/errors/auth_error.rb | 4 ---- lib/errors/bad_content.rb | 4 ---- lib/errors/bad_media.rb | 4 ---- lib/errors/invalid_format.rb | 4 ---- lib/errors/large_entity.rb | 5 ----- lib/errors/raise_error.rb | 31 ------------------------------- lib/errors/rate_limit_exceeded.rb | 4 ---- lib/errors/resource_not_found.rb | 4 ---- lib/errors/server_error.rb | 4 ---- lib/errors/service_unavailable.rb | 4 ---- test/error_test.rb | 16 ++++++++-------- 11 files changed, 8 insertions(+), 76 deletions(-) delete mode 100644 lib/errors/auth_error.rb delete mode 100644 lib/errors/bad_content.rb delete mode 100644 lib/errors/bad_media.rb delete mode 100644 lib/errors/invalid_format.rb delete mode 100644 lib/errors/large_entity.rb delete mode 100644 lib/errors/raise_error.rb delete mode 100644 lib/errors/rate_limit_exceeded.rb delete mode 100644 lib/errors/resource_not_found.rb delete mode 100644 lib/errors/server_error.rb delete mode 100644 lib/errors/service_unavailable.rb diff --git a/lib/errors/auth_error.rb b/lib/errors/auth_error.rb deleted file mode 100644 index 531bfc7..0000000 --- a/lib/errors/auth_error.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class AuthError < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/bad_content.rb b/lib/errors/bad_content.rb deleted file mode 100644 index ac4dc31..0000000 --- a/lib/errors/bad_content.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class BadContent < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/bad_media.rb b/lib/errors/bad_media.rb deleted file mode 100644 index 9f3c968..0000000 --- a/lib/errors/bad_media.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class BadMedia < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/invalid_format.rb b/lib/errors/invalid_format.rb deleted file mode 100644 index ca901a3..0000000 --- a/lib/errors/invalid_format.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class InvalidFormat < StandardError - end -end diff --git a/lib/errors/large_entity.rb b/lib/errors/large_entity.rb deleted file mode 100644 index e545b10..0000000 --- a/lib/errors/large_entity.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Errors - class LargeEntity < StandardError - - end -end \ No newline at end of file diff --git a/lib/errors/raise_error.rb b/lib/errors/raise_error.rb deleted file mode 100644 index 8fdc825..0000000 --- a/lib/errors/raise_error.rb +++ /dev/null @@ -1,31 +0,0 @@ -#Dir["errors/*.rb"].each {|file| require file } -Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file } - -module Errors - class RaiseError < Faraday::Response::Middleware - - def on_complete(env) - case env[:status] - when 503 - raise Errors::ServiceUnavailable - when 500 - raise Errors::ServerError - when 429 - raise Errors::RateLimitExceeded - when 415 - raise Errors::BadMedia - when 413 - raise Errors::LargeEntity - when 406 - raise Errors::InvalidFormat - when 404 - raise Errors::ResourceNotFound - when 401 - raise Errors::AuthError - when 400 - raise Errors::BadContent - end - end - - end -end diff --git a/lib/errors/rate_limit_exceeded.rb b/lib/errors/rate_limit_exceeded.rb deleted file mode 100644 index d12750c..0000000 --- a/lib/errors/rate_limit_exceeded.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class RateLimitExceeded < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/resource_not_found.rb b/lib/errors/resource_not_found.rb deleted file mode 100644 index 660f89d..0000000 --- a/lib/errors/resource_not_found.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class ResourceNotFound < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/server_error.rb b/lib/errors/server_error.rb deleted file mode 100644 index 5138b97..0000000 --- a/lib/errors/server_error.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class ServerError < StandardError - end -end \ No newline at end of file diff --git a/lib/errors/service_unavailable.rb b/lib/errors/service_unavailable.rb deleted file mode 100644 index 2906590..0000000 --- a/lib/errors/service_unavailable.rb +++ /dev/null @@ -1,4 +0,0 @@ -module Errors - class ServiceUnavailable < StandardError - end -end \ No newline at end of file diff --git a/test/error_test.rb b/test/error_test.rb index 788fbde..74761a5 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -14,49 +14,49 @@ it "should throw a ServiceUnavailable error" do WebMock.enable! mock_call(:status => 503) - -> { @oc.enrich("Test") }.must_raise Errors::ServiceUnavailable + -> { @oc.enrich("Test") }.must_raise CalaisError::ServiceUnavailable end it "should throw a ServerError error" do WebMock.enable! mock_call(:status => 500) - -> { @oc.enrich("Test") }.must_raise Errors::ServerError + -> { @oc.enrich("Test") }.must_raise CalaisError::ServerError end it "should throw a RateLimitExceeded error" do WebMock.enable! mock_call(:status => 429) - -> { @oc.enrich("Test") }.must_raise Errors::RateLimitExceeded + -> { @oc.enrich("Test") }.must_raise CalaisError::RateLimitExceeded end it "should throw a BadMedia error" do WebMock.enable! mock_call(:status => 415) - -> { @oc.enrich("Test") }.must_raise Errors::BadMedia + -> { @oc.enrich("Test") }.must_raise CalaisError::BadMedia end it "should throw a InvalidFormat error" do WebMock.enable! mock_call(:status => 406) - -> { @oc.enrich("Test") }.must_raise Errors::InvalidFormat + -> { @oc.enrich("Test") }.must_raise CalaisError::InvalidFormat end it "should throw a ResourceNotFound error" do WebMock.enable! mock_call(:status => 404) - -> { @oc.enrich("Test") }.must_raise Errors::ResourceNotFound + -> { @oc.enrich("Test") }.must_raise CalaisError::ResourceNotFound end it "should throw a AuthError error" do WebMock.enable! mock_call(:status => 401) - -> { @oc.enrich("Test") }.must_raise Errors::AuthError + -> { @oc.enrich("Test") }.must_raise CalaisError::AuthError end it "should throw a BadContent error" do WebMock.enable! mock_call(:status => 400) - -> { @oc.enrich("Test") }.must_raise Errors::BadContent + -> { @oc.enrich("Test") }.must_raise CalaisError::BadContent end end From ff41887d2206d28f64ea878461afede58bebdd3d Mon Sep 17 00:00:00 2001 From: Clayton Selby Date: Fri, 30 Oct 2015 11:03:02 -0500 Subject: [PATCH 16/28] Forgot to add lib folder with all refactored errors --- lib/calais_error/auth_error.rb | 4 ++++ lib/calais_error/bad_content.rb | 4 ++++ lib/calais_error/bad_media.rb | 4 ++++ lib/calais_error/invalid_format.rb | 4 ++++ lib/calais_error/large_entity.rb | 5 ++++ lib/calais_error/raise_error.rb | 31 +++++++++++++++++++++++++ lib/calais_error/rate_limit_exceeded.rb | 4 ++++ lib/calais_error/resource_not_found.rb | 4 ++++ lib/calais_error/server_error.rb | 4 ++++ lib/calais_error/service_unavailable.rb | 4 ++++ 10 files changed, 68 insertions(+) create mode 100644 lib/calais_error/auth_error.rb create mode 100644 lib/calais_error/bad_content.rb create mode 100644 lib/calais_error/bad_media.rb create mode 100644 lib/calais_error/invalid_format.rb create mode 100644 lib/calais_error/large_entity.rb create mode 100644 lib/calais_error/raise_error.rb create mode 100644 lib/calais_error/rate_limit_exceeded.rb create mode 100644 lib/calais_error/resource_not_found.rb create mode 100644 lib/calais_error/server_error.rb create mode 100644 lib/calais_error/service_unavailable.rb diff --git a/lib/calais_error/auth_error.rb b/lib/calais_error/auth_error.rb new file mode 100644 index 0000000..6031878 --- /dev/null +++ b/lib/calais_error/auth_error.rb @@ -0,0 +1,4 @@ +module CalaisError + class AuthError < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/bad_content.rb b/lib/calais_error/bad_content.rb new file mode 100644 index 0000000..b1c48b0 --- /dev/null +++ b/lib/calais_error/bad_content.rb @@ -0,0 +1,4 @@ +module CalaisError + class BadContent < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/bad_media.rb b/lib/calais_error/bad_media.rb new file mode 100644 index 0000000..13cec08 --- /dev/null +++ b/lib/calais_error/bad_media.rb @@ -0,0 +1,4 @@ +module CalaisError + class BadMedia < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/invalid_format.rb b/lib/calais_error/invalid_format.rb new file mode 100644 index 0000000..5521c89 --- /dev/null +++ b/lib/calais_error/invalid_format.rb @@ -0,0 +1,4 @@ +module CalaisError + class InvalidFormat < StandardError + end +end diff --git a/lib/calais_error/large_entity.rb b/lib/calais_error/large_entity.rb new file mode 100644 index 0000000..9651cf8 --- /dev/null +++ b/lib/calais_error/large_entity.rb @@ -0,0 +1,5 @@ +module CalaisError + class LargeEntity < StandardError + + end +end \ No newline at end of file diff --git a/lib/calais_error/raise_error.rb b/lib/calais_error/raise_error.rb new file mode 100644 index 0000000..7f27f58 --- /dev/null +++ b/lib/calais_error/raise_error.rb @@ -0,0 +1,31 @@ +#Dir["errors/*.rb"].each {|file| require file } +Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file } + +module CalaisError + class RaiseError < Faraday::Response::Middleware + + def on_complete(env) + case env[:status] + when 503 + raise CalaisError::ServiceUnavailable + when 500 + raise CalaisError::ServerError + when 429 + raise CalaisError::RateLimitExceeded + when 415 + raise CalaisError::BadMedia + when 413 + raise CalaisError::LargeEntity + when 406 + raise CalaisError::InvalidFormat + when 404 + raise CalaisError::ResourceNotFound + when 401 + raise CalaisError::AuthError + when 400 + raise CalaisError::BadContent + end + end + + end +end diff --git a/lib/calais_error/rate_limit_exceeded.rb b/lib/calais_error/rate_limit_exceeded.rb new file mode 100644 index 0000000..cb3b95d --- /dev/null +++ b/lib/calais_error/rate_limit_exceeded.rb @@ -0,0 +1,4 @@ +module CalaisError + class RateLimitExceeded < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/resource_not_found.rb b/lib/calais_error/resource_not_found.rb new file mode 100644 index 0000000..362601c --- /dev/null +++ b/lib/calais_error/resource_not_found.rb @@ -0,0 +1,4 @@ +module CalaisError + class ResourceNotFound < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/server_error.rb b/lib/calais_error/server_error.rb new file mode 100644 index 0000000..059b67c --- /dev/null +++ b/lib/calais_error/server_error.rb @@ -0,0 +1,4 @@ +module CalaisError + class ServerError < StandardError + end +end \ No newline at end of file diff --git a/lib/calais_error/service_unavailable.rb b/lib/calais_error/service_unavailable.rb new file mode 100644 index 0000000..489d13c --- /dev/null +++ b/lib/calais_error/service_unavailable.rb @@ -0,0 +1,4 @@ +module CalaisError + class ServiceUnavailable < StandardError + end +end \ No newline at end of file From 64bce2db4df4030429fc168f06d316e3255950d2 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Fri, 30 Oct 2015 13:48:20 -0700 Subject: [PATCH 17/28] Consolidate errors into a single file & namespace errors under OpenCalais --- lib/calais_error/auth_error.rb | 4 -- lib/calais_error/bad_content.rb | 4 -- lib/calais_error/bad_media.rb | 4 -- lib/calais_error/invalid_format.rb | 4 -- lib/calais_error/large_entity.rb | 5 --- lib/calais_error/raise_error.rb | 31 -------------- lib/calais_error/rate_limit_exceeded.rb | 4 -- lib/calais_error/resource_not_found.rb | 4 -- lib/calais_error/server_error.rb | 4 -- lib/calais_error/service_unavailable.rb | 4 -- lib/open_calais/client.rb | 2 +- lib/open_calais/connection.rb | 2 +- lib/open_calais/errors.rb | 57 +++++++++++++++++++++++++ test/error_test.rb | 16 +++---- 14 files changed, 67 insertions(+), 78 deletions(-) delete mode 100644 lib/calais_error/auth_error.rb delete mode 100644 lib/calais_error/bad_content.rb delete mode 100644 lib/calais_error/bad_media.rb delete mode 100644 lib/calais_error/invalid_format.rb delete mode 100644 lib/calais_error/large_entity.rb delete mode 100644 lib/calais_error/raise_error.rb delete mode 100644 lib/calais_error/rate_limit_exceeded.rb delete mode 100644 lib/calais_error/resource_not_found.rb delete mode 100644 lib/calais_error/server_error.rb delete mode 100644 lib/calais_error/service_unavailable.rb create mode 100644 lib/open_calais/errors.rb diff --git a/lib/calais_error/auth_error.rb b/lib/calais_error/auth_error.rb deleted file mode 100644 index 6031878..0000000 --- a/lib/calais_error/auth_error.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class AuthError < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/bad_content.rb b/lib/calais_error/bad_content.rb deleted file mode 100644 index b1c48b0..0000000 --- a/lib/calais_error/bad_content.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class BadContent < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/bad_media.rb b/lib/calais_error/bad_media.rb deleted file mode 100644 index 13cec08..0000000 --- a/lib/calais_error/bad_media.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class BadMedia < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/invalid_format.rb b/lib/calais_error/invalid_format.rb deleted file mode 100644 index 5521c89..0000000 --- a/lib/calais_error/invalid_format.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class InvalidFormat < StandardError - end -end diff --git a/lib/calais_error/large_entity.rb b/lib/calais_error/large_entity.rb deleted file mode 100644 index 9651cf8..0000000 --- a/lib/calais_error/large_entity.rb +++ /dev/null @@ -1,5 +0,0 @@ -module CalaisError - class LargeEntity < StandardError - - end -end \ No newline at end of file diff --git a/lib/calais_error/raise_error.rb b/lib/calais_error/raise_error.rb deleted file mode 100644 index 7f27f58..0000000 --- a/lib/calais_error/raise_error.rb +++ /dev/null @@ -1,31 +0,0 @@ -#Dir["errors/*.rb"].each {|file| require file } -Dir[File.dirname(__FILE__) + '/*.rb'].each {|file| require file } - -module CalaisError - class RaiseError < Faraday::Response::Middleware - - def on_complete(env) - case env[:status] - when 503 - raise CalaisError::ServiceUnavailable - when 500 - raise CalaisError::ServerError - when 429 - raise CalaisError::RateLimitExceeded - when 415 - raise CalaisError::BadMedia - when 413 - raise CalaisError::LargeEntity - when 406 - raise CalaisError::InvalidFormat - when 404 - raise CalaisError::ResourceNotFound - when 401 - raise CalaisError::AuthError - when 400 - raise CalaisError::BadContent - end - end - - end -end diff --git a/lib/calais_error/rate_limit_exceeded.rb b/lib/calais_error/rate_limit_exceeded.rb deleted file mode 100644 index cb3b95d..0000000 --- a/lib/calais_error/rate_limit_exceeded.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class RateLimitExceeded < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/resource_not_found.rb b/lib/calais_error/resource_not_found.rb deleted file mode 100644 index 362601c..0000000 --- a/lib/calais_error/resource_not_found.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class ResourceNotFound < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/server_error.rb b/lib/calais_error/server_error.rb deleted file mode 100644 index 059b67c..0000000 --- a/lib/calais_error/server_error.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class ServerError < StandardError - end -end \ No newline at end of file diff --git a/lib/calais_error/service_unavailable.rb b/lib/calais_error/service_unavailable.rb deleted file mode 100644 index 489d13c..0000000 --- a/lib/calais_error/service_unavailable.rb +++ /dev/null @@ -1,4 +0,0 @@ -module CalaisError - class ServiceUnavailable < StandardError - end -end \ No newline at end of file diff --git a/lib/open_calais/client.rb b/lib/open_calais/client.rb index 1e28cf8..bfe2a97 100644 --- a/lib/open_calais/client.rb +++ b/lib/open_calais/client.rb @@ -3,7 +3,7 @@ require 'open_calais/configuration' require 'open_calais/connection' require 'open_calais/response' -require 'errors/raise_error' +require 'open_calais/errors' module OpenCalais class Client diff --git a/lib/open_calais/connection.rb b/lib/open_calais/connection.rb index 6c72ac4..532b195 100644 --- a/lib/open_calais/connection.rb +++ b/lib/open_calais/connection.rb @@ -48,7 +48,7 @@ def connection(options={}) else connection.response :xml end - connection.use Errors::RaiseError + connection.use OpenCalais::Errors::Handler connection.adapter(adapter) end diff --git a/lib/open_calais/errors.rb b/lib/open_calais/errors.rb new file mode 100644 index 0000000..4486774 --- /dev/null +++ b/lib/open_calais/errors.rb @@ -0,0 +1,57 @@ +module OpenCalais + module Errors + + class AuthError < StandardError + end + + class BadContent < StandardError + end + + class BadMedia < StandardError + end + + class InvalidFormat < StandardError + end + + class LargeEntity < StandardError + end + + class RateLimitExceeded < StandardError + end + + class ResourceNotFound < StandardError + end + + class ServerError < StandardError + end + + class ServiceUnavailable < StandardError + end + + class Handler < Faraday::Response::Middleware + def on_complete(env) + case env[:status] + when 503 + raise Errors::ServiceUnavailable + when 500 + raise Errors::ServerError + when 429 + raise Errors::RateLimitExceeded + when 415 + raise Errors::BadMedia + when 413 + raise Errors::LargeEntity + when 406 + raise Errors::InvalidFormat + when 404 + raise Errors::ResourceNotFound + when 401 + raise Errors::AuthError + when 400 + raise Errors::BadContent + end + end + end + + end +end \ No newline at end of file diff --git a/test/error_test.rb b/test/error_test.rb index 74761a5..50dc56a 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -14,49 +14,49 @@ it "should throw a ServiceUnavailable error" do WebMock.enable! mock_call(:status => 503) - -> { @oc.enrich("Test") }.must_raise CalaisError::ServiceUnavailable + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::ServiceUnavailable end it "should throw a ServerError error" do WebMock.enable! mock_call(:status => 500) - -> { @oc.enrich("Test") }.must_raise CalaisError::ServerError + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::ServerError end it "should throw a RateLimitExceeded error" do WebMock.enable! mock_call(:status => 429) - -> { @oc.enrich("Test") }.must_raise CalaisError::RateLimitExceeded + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::RateLimitExceeded end it "should throw a BadMedia error" do WebMock.enable! mock_call(:status => 415) - -> { @oc.enrich("Test") }.must_raise CalaisError::BadMedia + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::BadMedia end it "should throw a InvalidFormat error" do WebMock.enable! mock_call(:status => 406) - -> { @oc.enrich("Test") }.must_raise CalaisError::InvalidFormat + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::InvalidFormat end it "should throw a ResourceNotFound error" do WebMock.enable! mock_call(:status => 404) - -> { @oc.enrich("Test") }.must_raise CalaisError::ResourceNotFound + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::ResourceNotFound end it "should throw a AuthError error" do WebMock.enable! mock_call(:status => 401) - -> { @oc.enrich("Test") }.must_raise CalaisError::AuthError + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::AuthError end it "should throw a BadContent error" do WebMock.enable! mock_call(:status => 400) - -> { @oc.enrich("Test") }.must_raise CalaisError::BadContent + -> { @oc.enrich("Test") }.must_raise OpenCalais::Errors::BadContent end end From 0e7040dba18095cf49d60d4f47bcf0ec6d51dfe3 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Fri, 30 Oct 2015 13:52:28 -0700 Subject: [PATCH 18/28] Fix reference to error class. --- test/error_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/error_test.rb b/test/error_test.rb index 50dc56a..45beead 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -8,7 +8,7 @@ it "should throw a AuthError for bad api key." do WebMock.disable! - -> { @oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise Errors::AuthError + -> { @oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz") }.must_raise OpenCalais::Errors::AuthError end it "should throw a ServiceUnavailable error" do From 646c1cee5e213f48383c1da11019782d024bc433 Mon Sep 17 00:00:00 2001 From: Chris Kalafarski Date: Mon, 2 Nov 2015 16:29:15 -0500 Subject: [PATCH 19/28] Update Travis config --- .travis.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 095ba4a..f02b2fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,12 @@ +sudo: false language: ruby +cache: bundler rvm: - - "2.1.6" - - "2.2.1" -env: - - TRAVIS=true + - 2.0.0-p647 + - 2.1.7 + - 2.2.0 + - 2.2.1 + - 2.2.2 + - 2.2.3 +script: + - bundle exec rake test From a39b4d17e05e6dd221e0fe2b98ad326224942004 Mon Sep 17 00:00:00 2001 From: Chris Kalafarski Date: Mon, 2 Nov 2015 16:34:19 -0500 Subject: [PATCH 20/28] Update .travis.yml --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f02b2fd..8882743 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ sudo: false language: ruby cache: bundler +env: + - TRAVIS=true rvm: - 2.0.0-p647 - 2.1.7 From 0a8ff020b29eb8f96ac4ee5bd8446b500eed7985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Here=C3=B1=C3=BA?= Date: Fri, 30 Sep 2016 20:56:54 -0300 Subject: [PATCH 21/28] Update links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index df91189..f59e715 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,11 @@ _Gem Version 0.1.* supports the original OpenCalais API_ -_Gem Version 0.2.* now uses the upgraded API http://new.opencalais.com/upgrade/_ +_Gem Version 0.2.* now uses the upgraded API http://www.opencalais.com/_ -If you are upgrading the the new version of the API, you will need a new API key. You should also review the [upgrade guide](http://new.opencalais.com/upgrade/). +If you are upgrading the the new version of the API, you will need a new API key. You should also review the [upgrade guide](http://www.opencalais.com/opencalais-api/). -This is a ruby gem to access the [OpenCalais API](http://www.opencalais.com/documentation/calais-web-service-api/api-invocation/rest), using the REST API, and JSON responses. +This is a ruby gem to access the [OpenCalais API](http://www.opencalais.com/opencalais-api/), using the REST API, and JSON responses. It uses [Faraday](https://github.com/lostisland/faraday) to abstract HTTP library (defaults to use excon because it is excellent), and multi_json to abstract JSON parsing. From 3e853140c6edae647bad6e2d00eb454c4f7a6189 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:50:49 -0800 Subject: [PATCH 22/28] kill circular dependency warning --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 23e7c6e..b6492c4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,6 @@ Coveralls.wear! end -require 'minitest/spec' require 'minitest/autorun' require 'open_calais' From 3e6be8881cd82b167bd4cbced6e3cb8e159d98f6 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:51:08 -0800 Subject: [PATCH 23/28] kill warning about ambiguous splats --- lib/open_calais/client.rb | 2 +- lib/open_calais/configuration.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open_calais/client.rb b/lib/open_calais/client.rb index ffd5b69..72ac82b 100644 --- a/lib/open_calais/client.rb +++ b/lib/open_calais/client.rb @@ -9,7 +9,7 @@ class Client include Connection - attr_reader *OpenCalais::Configuration.keys + attr_reader(*OpenCalais::Configuration.keys) attr_accessor :current_options diff --git a/lib/open_calais/configuration.rb b/lib/open_calais/configuration.rb index d84bf74..2fbeb78 100644 --- a/lib/open_calais/configuration.rb +++ b/lib/open_calais/configuration.rb @@ -22,7 +22,7 @@ module Configuration # The value sent in the http header for 'User-Agent' if none is set DEFAULT_USER_AGENT = "OpenCalais Ruby Gem #{OpenCalais::VERSION}".freeze - attr_accessor *VALID_OPTIONS_KEYS + attr_accessor(*VALID_OPTIONS_KEYS) # Convenience method to allow for global setting of configuration options def configure From 53212fbd62b86e08499de3acf76d769e547c360f Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:54:44 -0800 Subject: [PATCH 24/28] Kill warning about variable shadowing. --- lib/open_calais/response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_calais/response.rb b/lib/open_calais/response.rb index 300b485..42b9f89 100644 --- a/lib/open_calais/response.rb +++ b/lib/open_calais/response.rb @@ -64,7 +64,7 @@ def parse(response) self.entities << item end when 'relations' - item = v.reject{|k,v| k[0] == '_' || k == 'instances'} || {} + item = v.reject{|key,val| key[0] == '_' || key == 'instances'} || {} item[:type] = transliterate(v._type).titleize self.relations << item end From 63fd485b723b31fdae4da570b0109d286bce1363 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:57:57 -0800 Subject: [PATCH 25/28] Kill circular dependency warning. --- test/test_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 23e7c6e..b6492c4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,6 @@ Coveralls.wear! end -require 'minitest/spec' require 'minitest/autorun' require 'open_calais' From 9592f2134405aa46b90e3f08ea154b1fed389832 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:58:06 -0800 Subject: [PATCH 26/28] Kill ambiguous splat warning. --- lib/open_calais/client.rb | 2 +- lib/open_calais/configuration.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open_calais/client.rb b/lib/open_calais/client.rb index ffd5b69..72ac82b 100644 --- a/lib/open_calais/client.rb +++ b/lib/open_calais/client.rb @@ -9,7 +9,7 @@ class Client include Connection - attr_reader *OpenCalais::Configuration.keys + attr_reader(*OpenCalais::Configuration.keys) attr_accessor :current_options diff --git a/lib/open_calais/configuration.rb b/lib/open_calais/configuration.rb index d84bf74..2fbeb78 100644 --- a/lib/open_calais/configuration.rb +++ b/lib/open_calais/configuration.rb @@ -22,7 +22,7 @@ module Configuration # The value sent in the http header for 'User-Agent' if none is set DEFAULT_USER_AGENT = "OpenCalais Ruby Gem #{OpenCalais::VERSION}".freeze - attr_accessor *VALID_OPTIONS_KEYS + attr_accessor(*VALID_OPTIONS_KEYS) # Convenience method to allow for global setting of configuration options def configure From 7bcbcdce369a72bcc00a2240745c44dba0967704 Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 10:58:13 -0800 Subject: [PATCH 27/28] Kill variable shadowing warning. --- lib/open_calais/response.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_calais/response.rb b/lib/open_calais/response.rb index 300b485..42b9f89 100644 --- a/lib/open_calais/response.rb +++ b/lib/open_calais/response.rb @@ -64,7 +64,7 @@ def parse(response) self.entities << item end when 'relations' - item = v.reject{|k,v| k[0] == '_' || k == 'instances'} || {} + item = v.reject{|key,val| key[0] == '_' || key == 'instances'} || {} item[:type] = transliterate(v._type).titleize self.relations << item end From 1f968a19f6f3c66ad741c5256a00f023f29e70fb Mon Sep 17 00:00:00 2001 From: Ted Han Date: Thu, 1 Feb 2018 16:11:08 -0800 Subject: [PATCH 28/28] Fix typo --- test/client_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/client_test.rb b/test/client_test.rb index 2c101ed..0928d1d 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -34,7 +34,7 @@ response.raw.wont_be_nil end - it "passes in header optionsin enrich" do + it "passes in header options in enrich" do oc = OpenCalais::Client.new(:api_key => ENV['OPEN_CALAIS_KEY']) response = oc.enrich("Ruby on Rails is a fantastic web framework. It uses MVC, and the ruby programming language invented by Matz", :headers => {:content_type => OpenCalais::CONTENT_TYPES[:html]}) response.wont_be_nil