source2swagger 0.0.1
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 +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -0
- data/LICENCE +22 -0
- data/README.md +189 -0
- data/Rakefile +10 -0
- data/bin/source2swagger +84 -0
- data/lib/swagger_hash.rb +70 -0
- data/lib/swagger_reader.rb +113 -0
- data/source2swagger.gemspec +20 -0
- data/test/data/sample1.json +27 -0
- data/test/data/sample1.rb +18 -0
- data/test/data/sample2.json +86 -0
- data/test/data/sample2.rb +42 -0
- data/test/data/sample3.json +221 -0
- data/test/data/sample3.rb +156 -0
- data/test/data/sample4.rb +44 -0
- data/test/data/sample5.rb +46 -0
- data/test/data/sample_bad1.rb +20 -0
- data/test/data/sample_bad2.rb +16 -0
- data/test/data/sample_bad3.rb +44 -0
- data/test/test_helper.rb +10 -0
- data/test/test_helpers/compare_hashes.rb +57 -0
- data/test/unit/swagger_hash_test.rb +177 -0
- data/test/unit/swagger_reader_test.rb +181 -0
- metadata +98 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = "source2swagger"
|
4
|
+
|
5
|
+
gem.authors = ["Josep M. Pujol"]
|
6
|
+
gem.email = 'josep@3scale.net'
|
7
|
+
|
8
|
+
gem.description = %q{Tool for converting comments to Swagger JSON specification}
|
9
|
+
gem.summary = %q{Builds a swagger compliant JSON specification from annotations on the comments of your source code.}
|
10
|
+
|
11
|
+
gem.homepage = ""
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($\)
|
14
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = '0.0.1'
|
18
|
+
|
19
|
+
gem.add_dependency 'json'
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"apis": [
|
3
|
+
{
|
4
|
+
"path": "/ping",
|
5
|
+
"format":"text",
|
6
|
+
"description": "Check the status to see if it's up and running",
|
7
|
+
"operations": [
|
8
|
+
{
|
9
|
+
"httpMethod":"GET",
|
10
|
+
"tags":["test"],
|
11
|
+
"nickname":"ping",
|
12
|
+
"deprecated":true,
|
13
|
+
"summary":"This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"errorResponses":[
|
17
|
+
{
|
18
|
+
"reason":"API down",
|
19
|
+
"code":500
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"basePath":"http://helloworld.3scale.net",
|
25
|
+
"swagrVersion":"0.1a",
|
26
|
+
"apiVersion":"1.0"
|
27
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
2
|
+
##~ sapi.basePath = "http://helloworld.3scale.net"
|
3
|
+
##~ sapi.swagrVersion = "0.1a"
|
4
|
+
##~ sapi.apiVersion = "1.0"
|
5
|
+
##
|
6
|
+
##~ a = sapi.apis.add
|
7
|
+
##
|
8
|
+
##~ a.set :path => "/ping", :format => "text"
|
9
|
+
##~ a.description = "Check the status to see if it's up and running"
|
10
|
+
##
|
11
|
+
## declaring errors
|
12
|
+
##
|
13
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
14
|
+
##
|
15
|
+
##~ op = a.operations.add
|
16
|
+
##~ op.set :httpMethod => "GET", :tags => ["test"], :nickname => "ping", :deprecated => true
|
17
|
+
##~ op.summary = "This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
18
|
+
##
|
@@ -0,0 +1,86 @@
|
|
1
|
+
{
|
2
|
+
"apis": [
|
3
|
+
{
|
4
|
+
"path": "/ping",
|
5
|
+
"format":"text",
|
6
|
+
"description": "Check the status to see if it's up and running",
|
7
|
+
"operations": [
|
8
|
+
{
|
9
|
+
"httpMethod":"GET",
|
10
|
+
"tags":["test"],
|
11
|
+
"nickname":"ping",
|
12
|
+
"deprecated":true,
|
13
|
+
"summary":"This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"errorResponses":[
|
17
|
+
{
|
18
|
+
"reason":"API down",
|
19
|
+
"code":500
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"path":"/word/{word}",
|
25
|
+
"format":"json",
|
26
|
+
"description":"Access to the sentiment of a given word",
|
27
|
+
"operations": [
|
28
|
+
{
|
29
|
+
"parameters":[
|
30
|
+
{
|
31
|
+
"name":"word",
|
32
|
+
"description":"The word whose sentiment is returned",
|
33
|
+
"dataType":"string",
|
34
|
+
"allowMultiple":false,
|
35
|
+
"required":true,
|
36
|
+
"paramType":"path"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"name":"app_id",
|
40
|
+
"description":"Your access application id",
|
41
|
+
"dataType":"string",
|
42
|
+
"allowMultiple":false,
|
43
|
+
"required":true,
|
44
|
+
"paramType":"query"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"name":"app_key",
|
48
|
+
"description":"Your access application key",
|
49
|
+
"dataType":"string",
|
50
|
+
"allowMultiple":false,
|
51
|
+
"required":false,
|
52
|
+
"paramType":"query"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"httpMethod":"GET",
|
56
|
+
"tags":["production"],
|
57
|
+
"nickname":"get_word",
|
58
|
+
"deprecated":false,
|
59
|
+
"summary":"Returns the sentiment values of a given word"
|
60
|
+
}
|
61
|
+
],
|
62
|
+
|
63
|
+
"errorResponses":[
|
64
|
+
{
|
65
|
+
"reason":"failure to sanitize: \"input\"",
|
66
|
+
"code":422
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"reason":"failure to sanitize: \"input\", returns empty set",
|
70
|
+
"code":422
|
71
|
+
},
|
72
|
+
{
|
73
|
+
"reason":"access denied, either your access credentials are incorrect or you are about the limits of your quota",
|
74
|
+
"code":403
|
75
|
+
},
|
76
|
+
{
|
77
|
+
"reason":"API down",
|
78
|
+
"code":500
|
79
|
+
}
|
80
|
+
]
|
81
|
+
}
|
82
|
+
],
|
83
|
+
"basePath":"http://helloworld.3scale.net",
|
84
|
+
"swagrVersion":"0.1a",
|
85
|
+
"apiVersion":"1.0"
|
86
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
2
|
+
##~ sapi.basePath = "http://helloworld.3scale.net"
|
3
|
+
##~ sapi.swagrVersion = "0.1a"
|
4
|
+
##~ sapi.apiVersion = "1.0"
|
5
|
+
|
6
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
7
|
+
##~ a = sapi.apis.add
|
8
|
+
##
|
9
|
+
##~ a.set :path => "/word/{word}", :format => "json"
|
10
|
+
##~ a.description = "Access to the sentiment of a given word"
|
11
|
+
##
|
12
|
+
## declaring errors
|
13
|
+
##
|
14
|
+
##~ err = a.errorResponses.add
|
15
|
+
##~ err.set :reason => "failure to sanitize: \"input\"", :code => 422
|
16
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
17
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\", returns empty set", :code => 422
|
18
|
+
##~ a.errorResponses.add :reason => "access denied, either your access credentials are incorrect or you are about the limits of your quota", :code => 403
|
19
|
+
##~
|
20
|
+
##~ op = a.operations.add
|
21
|
+
##~ op.set :httpMethod => "GET", :tags => ["production"], :nickname => "get_word", :deprecated => false
|
22
|
+
##~ op.summary = "Returns the sentiment values of a given word"
|
23
|
+
##~ op.parameters.add :name => "word", :description => "The word whose sentiment is returned", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "path"
|
24
|
+
##~ op.parameters.add :name => "app_id", :description => "Your access application id", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "query"
|
25
|
+
##~ op.parameters.add :name => "app_key", :description => "Your access application key", :dataType => "string", :allowMultiple => false, :required => false, :paramType => "query"
|
26
|
+
##
|
27
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
28
|
+
##
|
29
|
+
##~ a = sapi.apis.add
|
30
|
+
##
|
31
|
+
##~ a.set :path => "/ping", :format => "text"
|
32
|
+
##~ a.description = "Check the status to see if it's up and running"
|
33
|
+
##
|
34
|
+
## declaring errors
|
35
|
+
##
|
36
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
37
|
+
##
|
38
|
+
##~ op = a.operations.add
|
39
|
+
##~ op.set :httpMethod => "GET", :tags => ["test"], :nickname => "ping", :deprecated => true
|
40
|
+
##~ op.summary = "This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
41
|
+
##
|
42
|
+
|
@@ -0,0 +1,221 @@
|
|
1
|
+
{
|
2
|
+
"apis": [
|
3
|
+
{
|
4
|
+
"path": "/ping",
|
5
|
+
"format":"text",
|
6
|
+
"description": "Check the status to see if it's up and running",
|
7
|
+
"operations": [
|
8
|
+
{
|
9
|
+
"httpMethod":"GET",
|
10
|
+
"tags":["test"],
|
11
|
+
"nickname":"ping",
|
12
|
+
"deprecated":true,
|
13
|
+
"summary":"This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
14
|
+
}
|
15
|
+
],
|
16
|
+
"errorResponses":[
|
17
|
+
{
|
18
|
+
"reason":"API down",
|
19
|
+
"code":500
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"path":"/word/{word}",
|
25
|
+
"format":"json",
|
26
|
+
"description":"Access to the sentiment of a given word",
|
27
|
+
"operations": [
|
28
|
+
{
|
29
|
+
"parameters":[
|
30
|
+
{
|
31
|
+
"name":"word",
|
32
|
+
"description":"The word whose sentiment is returned",
|
33
|
+
"dataType":"string",
|
34
|
+
"allowMultiple":false,
|
35
|
+
"required":true,
|
36
|
+
"paramType":"path"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"name":"app_id",
|
40
|
+
"description":"Your access application id",
|
41
|
+
"dataType":"string",
|
42
|
+
"allowMultiple":false,
|
43
|
+
"required":true,
|
44
|
+
"paramType":"query"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"name":"app_key",
|
48
|
+
"description":"Your access application key",
|
49
|
+
"dataType":"string",
|
50
|
+
"allowMultiple":false,
|
51
|
+
"required":false,
|
52
|
+
"paramType":"query"
|
53
|
+
}
|
54
|
+
],
|
55
|
+
"httpMethod":"GET",
|
56
|
+
"tags":["production"],
|
57
|
+
"nickname":"get_word",
|
58
|
+
"deprecated":false,
|
59
|
+
"summary":"Returns the sentiment values of a given word"
|
60
|
+
}
|
61
|
+
],
|
62
|
+
"errorResponses":[
|
63
|
+
{
|
64
|
+
"reason":"failure to sanitize: \"input\"",
|
65
|
+
"code":422
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"reason":"failure to sanitize: \"input\", returns empty set",
|
69
|
+
"code":422
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"reason":"access denied, either your access credentials are incorrect or you are about the limits of your quota",
|
73
|
+
"code":403
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"reason":"API down",
|
77
|
+
"code":500
|
78
|
+
}
|
79
|
+
]
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"path":"/word/{word}/{value}",
|
83
|
+
"format":"json",
|
84
|
+
"description":"Set the sentiment of a given word",
|
85
|
+
"operations": [
|
86
|
+
{
|
87
|
+
"parameters":[
|
88
|
+
{
|
89
|
+
"name":"word",
|
90
|
+
"description":"The word whose sentiment is to be set",
|
91
|
+
"dataType":"string",
|
92
|
+
"allowMultiple":false,
|
93
|
+
"required":true,
|
94
|
+
"paramType":"path"
|
95
|
+
},
|
96
|
+
{
|
97
|
+
"name":"value",
|
98
|
+
"description":"The sentiment value, -5 to -1 for negative connotations, 0 neutral, +1 to +5 for positive connotations",
|
99
|
+
"dataType":"int",
|
100
|
+
"allowMultiple":false,
|
101
|
+
"required":true,
|
102
|
+
"paramType":"path"
|
103
|
+
},
|
104
|
+
{
|
105
|
+
"name":"app_id",
|
106
|
+
"description":"Your access application id",
|
107
|
+
"dataType":"string",
|
108
|
+
"allowMultiple":false,
|
109
|
+
"required":true,
|
110
|
+
"paramType":"query"
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"name":"app_key",
|
114
|
+
"description":"Your access application key",
|
115
|
+
"dataType":"string",
|
116
|
+
"allowMultiple":false,
|
117
|
+
"required":false,
|
118
|
+
"paramType":"query"
|
119
|
+
}
|
120
|
+
],
|
121
|
+
"httpMethod":"POST",
|
122
|
+
"tags":["production"],
|
123
|
+
"nickname":"set_word",
|
124
|
+
"deprecated":false,
|
125
|
+
"summary":"Returns the sentiment values of a given word"
|
126
|
+
}
|
127
|
+
],
|
128
|
+
"errorResponses":[
|
129
|
+
{
|
130
|
+
"reason":"\"word\" is not a single word",
|
131
|
+
"code":422
|
132
|
+
},
|
133
|
+
{
|
134
|
+
"reason":"incorrect \"value\", must be -5 to -1 for negative or to +1 to +5 for positive connotations",
|
135
|
+
"code":422
|
136
|
+
},
|
137
|
+
{
|
138
|
+
"reason":"failure to sanitize: \"input\"",
|
139
|
+
"code":422
|
140
|
+
},
|
141
|
+
{
|
142
|
+
"reason":"failure to sanitize: \"input\", returns empty set",
|
143
|
+
"code":422
|
144
|
+
},
|
145
|
+
{
|
146
|
+
"reason":"access denied, either your access credentials are incorrect or you are about the limits of your quota",
|
147
|
+
"code":403
|
148
|
+
},
|
149
|
+
{
|
150
|
+
"reason":"API down",
|
151
|
+
"code":500
|
152
|
+
}
|
153
|
+
]
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"path":"/sentence/{sentence}",
|
157
|
+
"format":"json",
|
158
|
+
"description":"Returns the aggregated sentiment of a sentence",
|
159
|
+
"operations": [
|
160
|
+
{
|
161
|
+
"parameters":[
|
162
|
+
{
|
163
|
+
"name":"sentence",
|
164
|
+
"description":"The sentence to be analyzed",
|
165
|
+
"dataType":"string",
|
166
|
+
"allowMultiple":false,
|
167
|
+
"required":true,
|
168
|
+
"paramType":"path"
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"name":"app_id",
|
172
|
+
"description":"Your access application id",
|
173
|
+
"dataType":"string",
|
174
|
+
"allowMultiple":false,
|
175
|
+
"required":true,
|
176
|
+
"paramType":"query"
|
177
|
+
},
|
178
|
+
{
|
179
|
+
"name":"app_key",
|
180
|
+
"description":"Your access application key",
|
181
|
+
"dataType":"string",
|
182
|
+
"allowMultiple":false,
|
183
|
+
"required":false,
|
184
|
+
"paramType":"query"
|
185
|
+
}
|
186
|
+
],
|
187
|
+
"httpMethod":"GET",
|
188
|
+
"tags":["production"],
|
189
|
+
"nickname":"get_sentence",
|
190
|
+
"deprecated":false,
|
191
|
+
"summary":"Returns the aggregated sentiment of a sentence"
|
192
|
+
}
|
193
|
+
],
|
194
|
+
"errorResponses":[
|
195
|
+
{
|
196
|
+
"reason":"sentence is too long",
|
197
|
+
"code":422
|
198
|
+
},
|
199
|
+
{
|
200
|
+
"reason":"failure to sanitize: \"input\"",
|
201
|
+
"code":422
|
202
|
+
},
|
203
|
+
{
|
204
|
+
"reason":"failure to sanitize: \"input\", returns empty set",
|
205
|
+
"code":422
|
206
|
+
},
|
207
|
+
{
|
208
|
+
"reason":"access denied, either your access credentials are incorrect or you are about the limits of your quota",
|
209
|
+
"code":403
|
210
|
+
},
|
211
|
+
{
|
212
|
+
"reason":"API down",
|
213
|
+
"code":500
|
214
|
+
}
|
215
|
+
]
|
216
|
+
}
|
217
|
+
],
|
218
|
+
"basePath":"http://helloworld.3scale.net",
|
219
|
+
"swagrVersion":"0.1a",
|
220
|
+
"apiVersion":"1.0"
|
221
|
+
}
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require './analyzer.rb'
|
6
|
+
require 'json'
|
7
|
+
require 'sinatra'
|
8
|
+
|
9
|
+
class SentimentApi < Sinatra::Base
|
10
|
+
disable :logging
|
11
|
+
disable :raise_errors
|
12
|
+
disable :show_exceptions
|
13
|
+
|
14
|
+
configure :production do
|
15
|
+
disable :dump_errors
|
16
|
+
end
|
17
|
+
|
18
|
+
set :server, 'thin'
|
19
|
+
|
20
|
+
@@the_logic = Analyzer.new
|
21
|
+
|
22
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
23
|
+
##~ sapi.basePath = "http://helloworld.3scale.net"
|
24
|
+
##~ sapi.swagrVersion = "0.1a"
|
25
|
+
##~ sapi.apiVersion = "1.0"
|
26
|
+
|
27
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
28
|
+
##~ a = sapi.apis.add
|
29
|
+
##
|
30
|
+
##~ a.set :path => "/word/{word}", :format => "json"
|
31
|
+
##~ a.description = "Access to the sentiment of a given word"
|
32
|
+
##
|
33
|
+
## declaring errors
|
34
|
+
##
|
35
|
+
##~ err = a.errorResponses.add
|
36
|
+
##~ err.set :reason => "failure to sanitize: \"input\"", :code => 422
|
37
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\", returns empty set", :code => 422
|
38
|
+
##~ a.errorResponses.add :reason => "access denied, either your access credentials are incorrect or you are about the limits of your quota", :code => 403
|
39
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
40
|
+
##~
|
41
|
+
##~ op = a.operations.add
|
42
|
+
##~ op.set :httpMethod => "GET", :tags => ["production"], :nickname => "get_word", :deprecated => false
|
43
|
+
##~ op.summary = "Returns the sentiment values of a given word"
|
44
|
+
##~ op.parameters.add :name => "word", :description => "The word whose sentiment is returned", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "path"
|
45
|
+
##~ op.parameters.add :name => "app_id", :description => "Your access application id", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "query"
|
46
|
+
##~ op.parameters.add :name => "app_key", :description => "Your access application key", :dataType => "string", :allowMultiple => false, :required => false, :paramType => "query"
|
47
|
+
##
|
48
|
+
|
49
|
+
|
50
|
+
get '/word/:word' do
|
51
|
+
res = @@the_logic.word(params[:word])
|
52
|
+
body res.to_json
|
53
|
+
##sleep(1)
|
54
|
+
status 200
|
55
|
+
end
|
56
|
+
|
57
|
+
##~ s = source2swagger.namespace("sentiment")
|
58
|
+
##~ a = s.apis.add
|
59
|
+
##~
|
60
|
+
##~ a.set :path => "/sentence/{sentence}", :format => "json"
|
61
|
+
##~ a.description = "Returns the aggregated sentiment of a sentence"
|
62
|
+
##
|
63
|
+
## declaring errors
|
64
|
+
##
|
65
|
+
##~ err = a.errorResponses.add
|
66
|
+
##~ err.set :reason => "sentence is too long", :code => 422
|
67
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\"", :code => 422
|
68
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\", returns empty set", :code => 422
|
69
|
+
##~ a.errorResponses.add :reason => "access denied, either your access credentials are incorrect or you are about the limits of your quota", :code => 403
|
70
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
71
|
+
##
|
72
|
+
##~ op = a.operations.add
|
73
|
+
##~ op.set :httpMethod => "GET", :tags => ["production"], :nickname => "get_sentence", :deprecated => false
|
74
|
+
##~ op.summary = "Returns the aggregated sentiment of a sentence"
|
75
|
+
##~ op.parameters.add :name => "sentence", :description => "The sentence to be analyzed", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "path"
|
76
|
+
##~ op.parameters.add :name => "app_id", :description => "Your access application id", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "query"
|
77
|
+
##~ op.parameters.add :name => "app_key", :description => "Your access application key", :dataType => "string", :allowMultiple => false, :required => false, :paramType => "query"
|
78
|
+
##~
|
79
|
+
|
80
|
+
get '/sentence/:sentence' do
|
81
|
+
res = @@the_logic.sentence(params[:sentence])
|
82
|
+
body res.to_json
|
83
|
+
status 200
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
##~ s = source2swagger.namespace("sentiment")
|
88
|
+
##~ a = s.apis.add
|
89
|
+
##~
|
90
|
+
##~ a.path = "/word/{word}/{value}"
|
91
|
+
##~ a.format = "json"
|
92
|
+
##~ a.description = "Set the sentiment of a given word"
|
93
|
+
##
|
94
|
+
## declaring errors
|
95
|
+
##
|
96
|
+
##~ a.errorResponses.add :reason => "\"word\" is not a single word", :code => 422
|
97
|
+
##~ a.errorResponses.add :reason => "incorrect \"value\", must be -5 to -1 for negative or to +1 to +5 for positive connotations", :code => 422
|
98
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\"", :code => 422
|
99
|
+
##~ a.errorResponses.add :reason => "failure to sanitize: \"input\", returns empty set", :code => 422
|
100
|
+
##~ a.errorResponses.add :reason => "access denied, either your access credentials are incorrect or you are about the limits of your quota", :code => 403
|
101
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
102
|
+
##~
|
103
|
+
##~ op = a.operations.add
|
104
|
+
##~ op.set :httpMethod => "POST", :tags => ["production"], :nickname => "set_word", :deprecated => false
|
105
|
+
##~ op.summary = "Returns the sentiment values of a given word"
|
106
|
+
##~ op.parameters.add :name => "word", :description => "The word whose sentiment is to be set", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "path"
|
107
|
+
##~ op.parameters.add :name => "value", :description => "The sentiment value, -5 to -1 for negative connotations, 0 neutral, +1 to +5 for positive connotations", :dataType => "int", :allowMultiple => false, :required => true, :paramType => "path"
|
108
|
+
##~ op.parameters.add :name => "app_id", :description => "Your access application id", :dataType => "string", :allowMultiple => false, :required => true, :paramType => "query"
|
109
|
+
##~ op.parameters.add :name => "app_key", :description => "Your access application key", :dataType => "string", :allowMultiple => false, :required => false, :paramType => "query"
|
110
|
+
##~
|
111
|
+
|
112
|
+
post '/word/:word/:value' do
|
113
|
+
res = @@the_logic.add_word(params[:word],params[:value])
|
114
|
+
body res.to_json
|
115
|
+
status 200
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
##~ sapi = source2swagger.namespace("sentiment")
|
120
|
+
##~ a = sapi.apis.add
|
121
|
+
##
|
122
|
+
##~ a.set :path => "/ping", :format => "text"
|
123
|
+
##~ a.description = "Check the status to see if it's up and running"
|
124
|
+
##
|
125
|
+
## declaring errors
|
126
|
+
##
|
127
|
+
##~ a.errorResponses.add :reason => "API down", :code => 500
|
128
|
+
##
|
129
|
+
##~ op = a.operations.add
|
130
|
+
##~ op.set :httpMethod => "GET", :tags => ["test"], :nickname => "ping", :deprecated => true
|
131
|
+
##~ op.summary = "This operation is DEPRECATED. It returns the string \"that's getting old... pong \" if the API is up and running"
|
132
|
+
##
|
133
|
+
|
134
|
+
get '/ping' do
|
135
|
+
body "that's getting old... pong"
|
136
|
+
status 200
|
137
|
+
end
|
138
|
+
|
139
|
+
not_found do
|
140
|
+
""
|
141
|
+
end
|
142
|
+
|
143
|
+
error InvalidParameters do
|
144
|
+
error_code = 422
|
145
|
+
error error_code, env['sinatra.error'].to_s
|
146
|
+
end
|
147
|
+
|
148
|
+
error do
|
149
|
+
error_code = 500
|
150
|
+
error error_code, env['sinatra.error'].to_s
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
SentimentApi.run! :port => ARGV[0]
|