openamplify 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/test/test_openamplify.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'shoulda'
|
3
|
-
require 'openamplify'
|
4
|
-
|
5
|
-
class OpenAmplifyTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
context "Client instance" do
|
8
|
-
|
9
|
-
should "raise an error if api key is missing" do
|
10
|
-
assert_raises ArgumentError do
|
11
|
-
client = OpenAmplify::Client.new
|
12
|
-
client.analyze_text("sample")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
should "not raise an error if api key is present" do
|
17
|
-
assert_nothing_raised do
|
18
|
-
client.analyze_text("sample")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
should "raise an error if api key is not authorized" do
|
23
|
-
assert_raises OpenAmplify::Forbidden do
|
24
|
-
client = OpenAmplify::Client.new(:api_key => 'SOME_KEY')
|
25
|
-
client.analyze_text("sample").reload
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
should "raise an error if api_url is missing" do
|
30
|
-
assert_raises ArgumentError do
|
31
|
-
client.api_url = ''
|
32
|
-
client.analyze_text('sample')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
should "not raise an error if api_url is present" do
|
37
|
-
assert_nothing_raised do
|
38
|
-
client.analyze_text('sample')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end # context "Client instance"
|
43
|
-
|
44
|
-
context "Response" do
|
45
|
-
|
46
|
-
should "raise an error if empty text" do
|
47
|
-
assert_raises OpenAmplify::NotAcceptable do
|
48
|
-
client.analyze_text('').reload
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
should "not raise an error if there is input text" do
|
53
|
-
assert_nothing_raised do
|
54
|
-
client.analyze_text('sample').reload
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
should "raise error if analyis is not supported" do
|
59
|
-
assert_raises OpenAmplify::NotSupported do
|
60
|
-
client.analysis = 'not supported'
|
61
|
-
client.analyze_text('sample').reload
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
#pending "show the request url"
|
66
|
-
|
67
|
-
end # Response
|
68
|
-
|
69
|
-
context "Request methods" do
|
70
|
-
|
71
|
-
|
72
|
-
should "raise an error if not supported" do
|
73
|
-
assert_raises OpenAmplify::NotSupported do
|
74
|
-
client.method = :delete
|
75
|
-
client.analyze_text('sample').reload
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
[:get, :post].each do |method|
|
80
|
-
should "not raise error for #{method}" do
|
81
|
-
assert_nothing_raised do
|
82
|
-
client.method = method
|
83
|
-
client.analyze_text('sample').reload
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end # Request methods
|
89
|
-
|
90
|
-
def client
|
91
|
-
@client ||= OpenAmplify::Client.new(:api_key => api_key)
|
92
|
-
end
|
93
|
-
|
94
|
-
def api_key
|
95
|
-
ENV['OPEN_AMPLIFY_KEY']
|
96
|
-
end
|
97
|
-
|
98
|
-
end # OpenAmplifyTest
|