alchemy-api-rb 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/.travis.yml +7 -2
  4. data/CHANGELOG.md +23 -0
  5. data/CONTRIBUTING.md +117 -0
  6. data/README.md +32 -20
  7. data/Rakefile +6 -3
  8. data/alchemy-api-rb.gemspec +10 -9
  9. data/lib/alchemy-api/author_extraction.rb +1 -3
  10. data/lib/alchemy-api/base.rb +7 -11
  11. data/lib/alchemy-api/concept_tagging.rb +1 -2
  12. data/lib/alchemy-api/config.rb +3 -3
  13. data/lib/alchemy-api/entity_extraction.rb +1 -1
  14. data/lib/alchemy-api/image_tagging.rb +1 -1
  15. data/lib/alchemy-api/keyword_extraction.rb +1 -1
  16. data/lib/alchemy-api/language_detection.rb +0 -2
  17. data/lib/alchemy-api/relation_extraction.rb +1 -2
  18. data/lib/alchemy-api/sentiment_analysis.rb +1 -2
  19. data/lib/alchemy-api/targeted_sentiment_analysis.rb +1 -1
  20. data/lib/alchemy-api/taxonomy.rb +1 -2
  21. data/lib/alchemy-api/text_categorization.rb +0 -1
  22. data/lib/alchemy-api/text_extraction.rb +1 -1
  23. data/lib/alchemy-api/title_extraction.rb +1 -1
  24. data/lib/alchemy-api/version.rb +1 -1
  25. data/lib/alchemy_api.rb +19 -19
  26. data/spec/alchemy_api_spec.rb +22 -22
  27. data/spec/author_extraction_spec.rb +8 -19
  28. data/spec/base_spec.rb +13 -10
  29. data/spec/concept_tagging_spec.rb +11 -13
  30. data/spec/entity_extraction_spec.rb +13 -13
  31. data/spec/image_tagging_spec.rb +13 -11
  32. data/spec/keyword_extraction_spec.rb +13 -13
  33. data/spec/language_detection_spec.rb +10 -12
  34. data/spec/relation_extraction_spec.rb +12 -13
  35. data/spec/sentiment_analysis_spec.rb +11 -12
  36. data/spec/spec_helper.rb +3 -2
  37. data/spec/targeted_sentiment_analysis_spec.rb +16 -14
  38. data/spec/text_categorization_spec.rb +11 -12
  39. data/spec/text_extraction_spec.rb +7 -7
  40. metadata +37 -20
@@ -13,5 +13,3 @@ module AlchemyAPI
13
13
  end
14
14
  end
15
15
  end
16
-
17
-
@@ -9,8 +9,7 @@ module AlchemyAPI
9
9
  private
10
10
 
11
11
  def indexer
12
- "relations"
12
+ 'relations'
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -9,8 +9,7 @@ module AlchemyAPI
9
9
  private
10
10
 
11
11
  def indexer
12
- "docSentiment"
12
+ 'docSentiment'
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -9,7 +9,7 @@ module AlchemyAPI
9
9
  private
10
10
 
11
11
  def indexer
12
- "docSentiment"
12
+ 'docSentiment'
13
13
  end
14
14
  end
15
15
  end
@@ -9,8 +9,7 @@ module AlchemyAPI
9
9
  private
10
10
 
11
11
  def indexer
12
- "taxonomy"
12
+ 'taxonomy'
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -18,4 +18,3 @@ module AlchemyAPI
18
18
  end
19
19
  end
20
20
  end
21
-
@@ -13,7 +13,7 @@ module AlchemyAPI
13
13
  end
14
14
 
15
15
  def indexer
16
- "text"
16
+ 'text'
17
17
  end
18
18
  end
19
19
  end
@@ -13,7 +13,7 @@ module AlchemyAPI
13
13
  end
14
14
 
15
15
  def indexer
16
- "title"
16
+ 'title'
17
17
  end
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module AlchemyAPI
2
- VERSION = "0.4.0"
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/alchemy_api.rb CHANGED
@@ -1,22 +1,22 @@
1
- require "alchemy-api/version"
2
- require "alchemy-api/config"
3
- require "alchemy-api/base"
4
- require "alchemy-api/keyword_extraction"
5
- require "alchemy-api/text_extraction"
6
- require "alchemy-api/title_extraction"
7
- require "alchemy-api/entity_extraction"
8
- require "alchemy-api/sentiment_analysis"
9
- require "alchemy-api/targeted_sentiment_analysis"
10
- require "alchemy-api/relation_extraction"
11
- require "alchemy-api/concept_tagging"
12
- require "alchemy-api/text_categorization"
13
- require "alchemy-api/language_detection"
14
- require "alchemy-api/author_extraction"
15
- require "alchemy-api/taxonomy"
16
- require "alchemy-api/image_tagging"
1
+ require 'alchemy-api/version'
2
+ require 'alchemy-api/config'
3
+ require 'alchemy-api/base'
4
+ require 'alchemy-api/keyword_extraction'
5
+ require 'alchemy-api/text_extraction'
6
+ require 'alchemy-api/title_extraction'
7
+ require 'alchemy-api/entity_extraction'
8
+ require 'alchemy-api/sentiment_analysis'
9
+ require 'alchemy-api/targeted_sentiment_analysis'
10
+ require 'alchemy-api/relation_extraction'
11
+ require 'alchemy-api/concept_tagging'
12
+ require 'alchemy-api/text_categorization'
13
+ require 'alchemy-api/language_detection'
14
+ require 'alchemy-api/author_extraction'
15
+ require 'alchemy-api/taxonomy'
16
+ require 'alchemy-api/image_tagging'
17
17
 
18
18
  module AlchemyAPI
19
- BASE_URL = "http://access.alchemyapi.com/calls/"
19
+ BASE_URL = 'http://access.alchemyapi.com/calls/'
20
20
 
21
21
  def self.config
22
22
  Config
@@ -37,8 +37,8 @@ module AlchemyAPI
37
37
  def self.search(mode, opts)
38
38
  klass = Config.modes[mode]
39
39
 
40
- raise InvalidAPIKey.new unless Config.apikey
41
- raise InvalidSearchMode.new unless klass
40
+ fail InvalidAPIKey unless Config.apikey
41
+ fail InvalidSearchMode unless klass
42
42
 
43
43
  klass.new.search(opts)
44
44
  end
@@ -1,22 +1,22 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe AlchemyAPI do
4
- subject() { AlchemyAPI }
4
+ subject { AlchemyAPI }
5
5
 
6
- it "knows the alchemy api url" do
7
- AlchemyAPI::BASE_URL.must_be :==, "http://access.alchemyapi.com/calls/"
6
+ it 'knows the alchemy api url' do
7
+ AlchemyAPI::BASE_URL.must_be :==, 'http://access.alchemyapi.com/calls/'
8
8
  end
9
9
 
10
- it "allows you to set the key directly" do
11
- key = "xxxxxxxx"
10
+ it 'allows you to set the key directly' do
11
+ key = 'xxxxxxxx'
12
12
  AlchemyAPI.key = key
13
13
 
14
14
  AlchemyAPI.key.must_be :==, key
15
15
  end
16
16
 
17
17
  describe AlchemyAPI::Config do
18
- describe ".add_mode" do
19
- it "allows classes to register themselves" do
18
+ describe '.add_mode' do
19
+ it 'allows classes to register themselves' do
20
20
  class Foo
21
21
  AlchemyAPI::Config.add_mode :foo, self
22
22
  end
@@ -25,14 +25,14 @@ describe AlchemyAPI do
25
25
  end
26
26
  end
27
27
 
28
- describe ".output_mode" do
28
+ describe '.output_mode' do
29
29
  after do
30
30
  AlchemyAPI.configure do |config|
31
31
  config.output_mode = :json
32
32
  end
33
33
  end
34
34
 
35
- it "allows output mode to be set" do
35
+ it 'allows output mode to be set' do
36
36
  AlchemyAPI.configure do |config|
37
37
  config.output_mode = :xml
38
38
  end
@@ -40,31 +40,31 @@ describe AlchemyAPI do
40
40
  AlchemyAPI.config.output_mode.must_be :==, :xml
41
41
  end
42
42
 
43
- it "errors on invalid output mode" do
44
- -> {
43
+ it 'errors on invalid output mode' do
44
+ lambda do
45
45
  AlchemyAPI.configure do |config|
46
46
  config.output_mode = :xls
47
47
  end
48
- }.must_raise AlchemyAPI::InvalidOutputMode
48
+ end.must_raise AlchemyAPI::InvalidOutputMode
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
- describe ".search" do
54
- it "needs an api key" do
53
+ describe '.search' do
54
+ it 'needs an api key' do
55
55
  AlchemyAPI::Config.apikey = nil
56
56
 
57
- -> {
58
- AlchemyAPI.search(:keyword_extraction, :text => "foo")
59
- }.must_raise AlchemyAPI::InvalidAPIKey
57
+ lambda do
58
+ AlchemyAPI.search(:keyword_extraction, text: 'foo')
59
+ end.must_raise AlchemyAPI::InvalidAPIKey
60
60
  end
61
61
 
62
- it "needs a valid mode" do
63
- AlchemyAPI::Config.apikey = "xxxxxxxxxxx"
62
+ it 'needs a valid mode' do
63
+ AlchemyAPI::Config.apikey = 'xxxxxxxxxxx'
64
64
 
65
- -> {
66
- AlchemyAPI.search(:bar, :text => "hello")
67
- }.must_raise AlchemyAPI::InvalidSearchMode
65
+ lambda do
66
+ AlchemyAPI.search(:bar, text: 'hello')
67
+ end.must_raise AlchemyAPI::InvalidSearchMode
68
68
  end
69
69
  end
70
70
  end
@@ -1,36 +1,28 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
- describe AlchemyAPI, "author_extraction" do
3
+ describe AlchemyAPI, 'author_extraction' do
4
4
  before do
5
5
  AlchemyAPI::Config.apikey = API_KEY
6
6
  end
7
7
 
8
- subject() { AlchemyAPI::AuthorExtraction.new }
8
+ subject { AlchemyAPI::AuthorExtraction.new }
9
9
 
10
- describe "#search" do
10
+ describe '#search' do
11
11
  {
12
- :html => "<html><body>Google is a large, by Joe Smith</body></html>",
13
- :url => "http://blog.alchemyapi.com/"
14
- }.each do |type,value|
12
+ html: '<html><body>Google is a large, by Joe Smith</body></html>',
13
+ url: 'http://blog.alchemyapi.com/'
14
+ }.each do |type, value|
15
15
  [:json].each do |output_mode|
16
16
  before do
17
17
  AlchemyAPI::Config.output_mode = output_mode
18
18
  end
19
19
 
20
20
  describe "#{type} search with #{output_mode} results" do
21
- it "returns an array of results" do
21
+ it 'returns a string result' do
22
22
  VCR.use_cassette("author_basic_#{type}_#{output_mode}_search") do
23
23
  result = subject.search(type => value)
24
24
 
25
- result.must_be_instance_of Hash
26
- end
27
- end
28
-
29
- it "includes the keyword text and relavence" do
30
- VCR.use_cassette("author_basic_#{type}_#{output_mode}_search") do
31
- result = subject.search(type => value)
32
-
33
- result["author"].wont_be_nil
25
+ result.must_be_instance_of String
34
26
  end
35
27
  end
36
28
  end
@@ -38,6 +30,3 @@ describe AlchemyAPI, "author_extraction" do
38
30
  end
39
31
  end
40
32
  end
41
-
42
-
43
-
data/spec/base_spec.rb CHANGED
@@ -1,27 +1,30 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
3
  describe AlchemyAPI::Base do
4
- subject() { AlchemyAPI::Base.new }
4
+ subject { AlchemyAPI::Base.new }
5
5
 
6
- describe "#connection" do
7
- it "creates a connection" do
6
+ describe '#connection' do
7
+ it 'creates a connection' do
8
8
  subject.send(:connection).wont_be_nil
9
9
  end
10
10
 
11
- describe "#adapter" do
12
- it "uses the excon adapter" do
13
- subject.send(:connection).builder.handlers.must_include Faraday::Adapter::Excon
11
+ describe '#adapter' do
12
+ it 'uses the excon adapter' do
13
+ subject
14
+ .send(:connection)
15
+ .builder
16
+ .handlers
17
+ .must_include Faraday::Adapter::Excon
14
18
  end
15
19
  end
16
20
  end
17
21
 
18
- describe "#merge_options" do
19
- it "combines default options with user provided" do
20
- opts = { extra: "extra" }
22
+ describe '#merge_options' do
23
+ it 'combines default options with user provided' do
24
+ opts = { extra: 'extra' }
21
25
  expected = { outputMode: :json }.merge(opts)
22
26
 
23
27
  subject.merged_options(opts).must_be :==, expected
24
28
  end
25
29
  end
26
-
27
30
  end
@@ -1,25 +1,25 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
- describe AlchemyAPI, "concept_extraction" do
3
+ describe AlchemyAPI, 'concept_extraction' do
4
4
  before do
5
5
  AlchemyAPI::Config.apikey = API_KEY
6
6
  end
7
7
 
8
- subject() { AlchemyAPI::ConceptTagging.new }
8
+ subject { AlchemyAPI::ConceptTagging.new }
9
9
 
10
- describe "#search" do
10
+ describe '#search' do
11
11
  {
12
- :text => "Google is a large company",
13
- :html => "<html><body>Google is a large company</body></html>",
14
- :url => "http://www.alchemy.com"
15
- }.each do |type,value|
12
+ text: 'Google is a large company',
13
+ html: '<html><body>Google is a large company</body></html>',
14
+ url: 'http://www.alchemy.com'
15
+ }.each do |type, value|
16
16
  [:json].each do |output_mode|
17
17
  before do
18
18
  AlchemyAPI::Config.output_mode = output_mode
19
19
  end
20
20
 
21
21
  describe "#{type} search with #{output_mode} results" do
22
- it "returns an array of results" do
22
+ it 'returns an array of results' do
23
23
  VCR.use_cassette("concept_basic_#{type}_#{output_mode}_search") do
24
24
  result = subject.search(type => value)
25
25
 
@@ -27,12 +27,12 @@ describe AlchemyAPI, "concept_extraction" do
27
27
  end
28
28
  end
29
29
 
30
- it "includes the keyword text and relavence" do
30
+ it 'includes the keyword text and relavence' do
31
31
  VCR.use_cassette("concept_basic_#{type}_#{output_mode}_search") do
32
32
  result = subject.search(type => value)[0]
33
33
 
34
- result["text"].wont_be_nil
35
- result["relevance"].wont_be_nil
34
+ result['text'].wont_be_nil
35
+ result['relevance'].wont_be_nil
36
36
  end
37
37
  end
38
38
  end
@@ -40,5 +40,3 @@ describe AlchemyAPI, "concept_extraction" do
40
40
  end
41
41
  end
42
42
  end
43
-
44
-
@@ -1,25 +1,25 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
- describe AlchemyAPI, "entity_extraction" do
3
+ describe AlchemyAPI, 'entity_extraction' do
4
4
  before do
5
5
  AlchemyAPI::Config.apikey = API_KEY
6
6
  end
7
7
 
8
- subject() { AlchemyAPI::EntityExtraction.new }
8
+ subject { AlchemyAPI::EntityExtraction.new }
9
9
 
10
- describe "#search" do
10
+ describe '#search' do
11
11
  {
12
- :text => "Google is a large company",
13
- :html => "<html><body>Google is a large company</body></html>",
14
- :url => "http://www.google.com"
15
- }.each do |type,value|
12
+ text: 'Google is a large company',
13
+ html: '<html><body>Google is a large company</body></html>',
14
+ url: 'http://www.google.com'
15
+ }.each do |type, value|
16
16
  [:json].each do |output_mode|
17
17
  before do
18
18
  AlchemyAPI::Config.output_mode = output_mode
19
19
  end
20
20
 
21
21
  describe "#{type} search with #{output_mode} results" do
22
- it "returns an array of results" do
22
+ it 'returns an array of results' do
23
23
  VCR.use_cassette("entity_basic_#{type}_#{output_mode}_search") do
24
24
  result = subject.search(type => value)
25
25
 
@@ -27,14 +27,14 @@ describe AlchemyAPI, "entity_extraction" do
27
27
  end
28
28
  end
29
29
 
30
- it "includes the keyword text and relavence" do
30
+ it 'includes the keyword text and relavence' do
31
31
  VCR.use_cassette("entity_basic_#{type}_#{output_mode}_search") do
32
32
  result = subject.search(type => value)[0]
33
33
 
34
- result["text"].wont_be_nil
35
- result["type"].wont_be_nil
36
- result["count"].wont_be_nil
37
- result["relevance"].wont_be_nil
34
+ result['text'].wont_be_nil
35
+ result['type'].wont_be_nil
36
+ result['count'].wont_be_nil
37
+ result['relevance'].wont_be_nil
38
38
  end
39
39
  end
40
40
  end
@@ -1,36 +1,38 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
2
 
3
- describe AlchemyAPI, "image_tagging" do
3
+ describe AlchemyAPI, 'image_tagging' do
4
4
  before do
5
5
  AlchemyAPI::Config.apikey = API_KEY
6
6
  end
7
7
 
8
- subject() { AlchemyAPI::ImageTagging.new }
8
+ subject { AlchemyAPI::ImageTagging.new }
9
9
 
10
- describe "#search" do
10
+ describe '#search' do
11
11
  {
12
- :url => "http://demo1.alchemyapi.com/images/vision/emaxfpo.jpg"
13
- }.each do |type,value|
12
+ url: 'http://demo1.alchemyapi.com/images/vision/emaxfpo.jpg'
13
+ }.each do |type, value|
14
14
  [:json].each do |output_mode|
15
15
  before do
16
16
  AlchemyAPI::Config.output_mode = output_mode
17
17
  end
18
18
 
19
19
  describe "#{type} search with #{output_mode} results" do
20
- it "returns an array of results" do
21
- VCR.use_cassette("image_tagging_basic_#{type}_#{output_mode}_search") do
20
+ it 'returns an array of results' do
21
+ cassette_name = "image_tagging_basic_#{type}_#{output_mode}_search"
22
+ VCR.use_cassette(cassette_name) do
22
23
  result = subject.search(type => value)
23
24
 
24
25
  result.must_be_instance_of Array
25
26
  end
26
27
  end
27
28
 
28
- it "includes the keyword text and score" do
29
- VCR.use_cassette("image_tagging_basic_#{type}_#{output_mode}_search") do
29
+ it 'includes the keyword text and score' do
30
+ cassette_name = "image_tagging_basic_#{type}_#{output_mode}_search"
31
+ VCR.use_cassette(cassette_name) do
30
32
  result = subject.search(type => value)[0]
31
33
 
32
- result["text"].wont_be_nil
33
- result["score"].wont_be_nil
34
+ result['text'].wont_be_nil
35
+ result['score'].wont_be_nil
34
36
  end
35
37
  end
36
38
  end