openamplify 0.2.3 → 0.3.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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/History +4 -0
- data/README.rdoc +61 -46
- data/Rakefile +64 -54
- data/TODO +1 -0
- data/bin/openamplify +49 -0
- data/lib/openamplify.rb +13 -158
- data/lib/openamplify/analysis/context.rb +67 -0
- data/lib/openamplify/client.rb +82 -0
- data/lib/openamplify/configuration.rb +54 -0
- data/lib/openamplify/connection.rb +28 -0
- data/lib/openamplify/error.rb +20 -0
- data/lib/openamplify/request.rb +35 -0
- data/lib/openamplify/response/raise_client_error.rb +28 -0
- data/lib/openamplify/response/raise_server_error.rb +23 -0
- data/lib/openamplify/version.rb +3 -0
- data/openamplify.gemspec +19 -49
- data/test/fixtures/input.txt +2 -0
- data/test/helper.rb +14 -0
- data/test/openamplify/analysis_test.rb +102 -0
- data/test/openamplify/client_test.rb +67 -0
- data/test/openamplify/configuration_test.rb +38 -0
- data/test/openamplify/error_test.rb +10 -0
- metadata +98 -73
- data/VERSION.yml +0 -5
- data/lib/openamplify/validations.rb +0 -38
- data/test/test_openamplify.rb +0 -98
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OpenAmplify::Analysis do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@api = OpenAmplify::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'can return result as string' do
|
10
|
+
result = @api.amplify amplify_input
|
11
|
+
result.to_s.wont_be_empty
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'output format' do
|
15
|
+
it 'xml' do
|
16
|
+
result = @api.amplify(amplify_input, :output_format => :xml)
|
17
|
+
|
18
|
+
require 'nokogiri'
|
19
|
+
Nokogiri::XML(result).wont_be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'json' do
|
23
|
+
result = @api.amplify(amplify_input, :output_format => :json)
|
24
|
+
|
25
|
+
require 'json'
|
26
|
+
JSON.parse(result).wont_be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
%w(xml json json_js rdf rdfa csv signals pretty dart oas).each do |format|
|
30
|
+
it "should output #{format}" do
|
31
|
+
result = @api.amplify amplify_input
|
32
|
+
result.send("to_#{format}").wont_be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'input analysis' do
|
39
|
+
it 'knows a text' do
|
40
|
+
result = @api.amplify amplify_input
|
41
|
+
result.to_s.wont_be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'knows a url' do
|
45
|
+
result = @api.amplify 'http://theonion.com'
|
46
|
+
|
47
|
+
require 'json'
|
48
|
+
JSON.parse(result.to_json).wont_be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should have default values' do
|
53
|
+
result = @api.amplify amplify_input
|
54
|
+
|
55
|
+
OpenAmplify::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
56
|
+
result.send(key).must_equal OpenAmplify.options[key]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should accept option values' do
|
61
|
+
options = {
|
62
|
+
:analysis => :topics,
|
63
|
+
:output_format => :json,
|
64
|
+
:scoring => :standard,
|
65
|
+
}
|
66
|
+
|
67
|
+
result = @api.amplify amplify_input, options
|
68
|
+
|
69
|
+
options.each do |key, value|
|
70
|
+
result.send(key).must_equal options[key]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should point the client' do
|
75
|
+
result = @api.amplify amplify_input
|
76
|
+
result.client.must_equal @api
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should accept option from client' do
|
80
|
+
options = {
|
81
|
+
:analysis => :topics,
|
82
|
+
:output_format => :json,
|
83
|
+
:scoring => :fans,
|
84
|
+
}
|
85
|
+
|
86
|
+
api = OpenAmplify::Client.new(options)
|
87
|
+
result = api.amplify amplify_input
|
88
|
+
|
89
|
+
options.each do |key, value|
|
90
|
+
result.send(key).must_equal options[key]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'deprecated methods' do
|
95
|
+
|
96
|
+
it 'analyze_text' do
|
97
|
+
@api.analyze_text amplify_input
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OpenAmplify::Client do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@keys = OpenAmplify::Configuration::VALID_CONFIG_KEYS
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'with module configuration' do
|
10
|
+
before do
|
11
|
+
OpenAmplify.configure do |config|
|
12
|
+
@keys.each do |key|
|
13
|
+
config.send("#{key}=", key)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
OpenAmplify.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should inherit module configuration" do
|
23
|
+
api = OpenAmplify::Client.new
|
24
|
+
@keys.each do |key|
|
25
|
+
api.send(key).must_equal key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'with class configuration' do
|
30
|
+
before do
|
31
|
+
@config = {
|
32
|
+
:api_key => 'ak',
|
33
|
+
:analysis => 'an',
|
34
|
+
:output_format => 'of',
|
35
|
+
:scoring => 'sc',
|
36
|
+
:endpoint => 'ep',
|
37
|
+
:user_agent => 'ua',
|
38
|
+
:method => 'hm',
|
39
|
+
:adapter => 'ha',
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should override module configuration' do
|
44
|
+
api = OpenAmplify::Client.new(@config)
|
45
|
+
|
46
|
+
@keys.each do |key|
|
47
|
+
api.send(key).must_equal @config[key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should override module configuration after' do
|
52
|
+
api = OpenAmplify::Client.new
|
53
|
+
|
54
|
+
@config.each do |key, value|
|
55
|
+
api.send("#{key}=", value)
|
56
|
+
end
|
57
|
+
|
58
|
+
@keys.each do |key|
|
59
|
+
api.send("#{key}").must_equal @config[key]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OpenAmplify::Configuration do
|
4
|
+
|
5
|
+
after do
|
6
|
+
OpenAmplify.reset
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.configure' do
|
10
|
+
OpenAmplify::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
11
|
+
it "should set the #{key}" do
|
12
|
+
OpenAmplify.configure do |config|
|
13
|
+
config.send("#{key}=", key)
|
14
|
+
OpenAmplify.send(key).must_equal key
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.user_agent' do
|
21
|
+
it 'should return the default user agent' do
|
22
|
+
OpenAmplify.user_agent.must_equal OpenAmplify::Configuration::DEFAULT_USER_AGENT
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.endpoint' do
|
27
|
+
it 'should return the default endpoint' do
|
28
|
+
OpenAmplify.endpoint.must_equal OpenAmplify::Configuration::DEFAULT_ENDPOINT
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.http_method' do
|
33
|
+
it 'should return the default http method' do
|
34
|
+
OpenAmplify.method.must_equal OpenAmplify::Configuration::DEFAULT_HTTP_METHOD
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OpenAmplify::Error do
|
4
|
+
|
5
|
+
it 'should raise error when wrong or missing api key' do
|
6
|
+
client = OpenAmplify::Client.new(:api_key => 'some random key')
|
7
|
+
lambda { client.amplify 'sample' }.must_raise OpenAmplify::Error::Forbidden
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
metadata
CHANGED
@@ -1,97 +1,122 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: openamplify
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Greg Moreno
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 2
|
30
|
-
version: "1.2"
|
12
|
+
date: 2012-09-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: &70095171618300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
31
22
|
type: :runtime
|
32
|
-
version_requirements: *id001
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: shoulda
|
35
23
|
prerelease: false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
24
|
+
version_requirements: *70095171618300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70095171609520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
44
33
|
type: :development
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70095171609520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: nokogiri
|
38
|
+
requirement: &70095171602420 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70095171602420
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: json
|
49
|
+
requirement: &70095171597380 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70095171597380
|
58
|
+
description: The OpenAmplify API reads text you supply and returns linguistic data
|
59
|
+
explaining and classifying the content.
|
60
|
+
email:
|
61
|
+
- greg.moreno@gmail.com
|
62
|
+
executables:
|
63
|
+
- openamplify
|
50
64
|
extensions: []
|
51
|
-
|
52
|
-
|
53
|
-
- LICENSE
|
54
|
-
- README.rdoc
|
55
|
-
files:
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
56
67
|
- .gitignore
|
68
|
+
- Gemfile
|
57
69
|
- History
|
58
70
|
- LICENSE
|
59
71
|
- README.rdoc
|
60
72
|
- Rakefile
|
61
|
-
-
|
73
|
+
- TODO
|
74
|
+
- bin/openamplify
|
62
75
|
- lib/openamplify.rb
|
63
|
-
- lib/openamplify/
|
76
|
+
- lib/openamplify/analysis/context.rb
|
77
|
+
- lib/openamplify/client.rb
|
78
|
+
- lib/openamplify/configuration.rb
|
79
|
+
- lib/openamplify/connection.rb
|
80
|
+
- lib/openamplify/error.rb
|
81
|
+
- lib/openamplify/request.rb
|
82
|
+
- lib/openamplify/response/raise_client_error.rb
|
83
|
+
- lib/openamplify/response/raise_server_error.rb
|
84
|
+
- lib/openamplify/version.rb
|
64
85
|
- openamplify.gemspec
|
65
|
-
- test/
|
66
|
-
|
67
|
-
|
86
|
+
- test/fixtures/input.txt
|
87
|
+
- test/helper.rb
|
88
|
+
- test/openamplify/analysis_test.rb
|
89
|
+
- test/openamplify/client_test.rb
|
90
|
+
- test/openamplify/configuration_test.rb
|
91
|
+
- test/openamplify/error_test.rb
|
92
|
+
homepage: ''
|
68
93
|
licenses: []
|
69
|
-
|
70
94
|
post_install_message:
|
71
|
-
rdoc_options:
|
72
|
-
|
73
|
-
require_paths:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
74
97
|
- lib
|
75
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
- 0
|
88
|
-
version: "0"
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
89
110
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
rubygems_version: 1.3.6
|
111
|
+
rubyforge_project: openamplify
|
112
|
+
rubygems_version: 1.8.10
|
93
113
|
signing_key:
|
94
114
|
specification_version: 3
|
95
115
|
summary: Wrapper for the OpenAmplify API
|
96
|
-
test_files:
|
97
|
-
- test/
|
116
|
+
test_files:
|
117
|
+
- test/fixtures/input.txt
|
118
|
+
- test/helper.rb
|
119
|
+
- test/openamplify/analysis_test.rb
|
120
|
+
- test/openamplify/client_test.rb
|
121
|
+
- test/openamplify/configuration_test.rb
|
122
|
+
- test/openamplify/error_test.rb
|
data/VERSION.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module OpenAmplify
|
2
|
-
|
3
|
-
class NotAcceptable < StandardError; end
|
4
|
-
class NotSupported < StandardError; end
|
5
|
-
class Forbidden < StandardError; end
|
6
|
-
|
7
|
-
|
8
|
-
def self.validate_client!(client)
|
9
|
-
raise ArgumentError, "missing api key" if client.api_key.blank?
|
10
|
-
raise ArgumentError, "missing api url" if client.api_url.blank?
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.validate_response!(response)
|
14
|
-
case response.code.to_i
|
15
|
-
when 403
|
16
|
-
raise Forbidden, "(#{response.code}: #{response.message}) #{response.body}"
|
17
|
-
when 405
|
18
|
-
raise NotSupported, "(#{response.code}: #{response.message}) #{response.body}"
|
19
|
-
when 406
|
20
|
-
raise NotAcceptable, "(#{response.code}: #{response.message}) #{response.body}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
class String
|
28
|
-
def blank?
|
29
|
-
nil? || empty? || strip.empty?
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class NilClass
|
34
|
-
def blank?
|
35
|
-
nil?
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|