cambridge_dict 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/config.ru +2 -1
- data/lib/cambridge_dict/server.rb +29 -0
- data/lib/cambridge_dict/version.rb +1 -1
- data/lib/cambridge_dict.rb +2 -27
- metadata +8 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f7f7932b9333e01c7af904c306f9e0a215cd797c824285b301292924b880ec
|
4
|
+
data.tar.gz: 244ebce0e0e906b85d111fbbdea76b3870e02fea54f16d6c232fc2711db68be6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4071c55b3707412ef8681946aa61c8d16bdd2b98e074bf6a2c1d4ecc52a58b9398b08920a22032469ad324b699a78aa5702e9cb7494c297d0c61fc3013db3e44
|
7
|
+
data.tar.gz: 7e4e7927bc956849ed64f97c0d829a40696f95932adfdc0bc3fc74258728bc7449031182993c3edf5790fc6adf911f7ad75903250b6b9ddc2c6592e58c4fb0e6
|
data/README.md
CHANGED
@@ -67,11 +67,14 @@ return if result.nil?
|
|
67
67
|
## Webserver Setup
|
68
68
|
|
69
69
|
```
|
70
|
+
# add sinatra and sinatra-cors to gemfile
|
71
|
+
|
70
72
|
# config.ru
|
71
|
-
require '
|
72
|
-
|
73
|
+
require 'cambridge_dict'
|
74
|
+
require 'cambridge_dict/server'
|
75
|
+
run CambridgeDict::Server
|
73
76
|
|
74
|
-
|
77
|
+
rackup config.ru
|
75
78
|
```
|
76
79
|
|
77
80
|
## Development
|
data/config.ru
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/cors'
|
3
|
+
|
4
|
+
module CambridgeDict
|
5
|
+
class Server < Sinatra::Base
|
6
|
+
register Sinatra::Cors
|
7
|
+
|
8
|
+
set :allow_origin, "*"
|
9
|
+
set :allow_methods, "GET,HEAD,POST"
|
10
|
+
set :allow_headers, "content-type,if-modified-since"
|
11
|
+
set :expose_headers, "location,link"
|
12
|
+
|
13
|
+
client = Client.new
|
14
|
+
|
15
|
+
get '/api/dictionary/:language/:entry' do
|
16
|
+
content_type :json
|
17
|
+
|
18
|
+
result = client.lookup(params[:entry], language: params[:language])
|
19
|
+
|
20
|
+
if result && !result[:word].empty?
|
21
|
+
status 200
|
22
|
+
result.to_json
|
23
|
+
else
|
24
|
+
status 404
|
25
|
+
{error: "word not found"}.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/cambridge_dict.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'httparty'
|
3
|
-
|
4
|
-
|
5
|
-
require 'cambridge_dict/version'
|
3
|
+
|
4
|
+
require_relative 'cambridge_dict/version'
|
6
5
|
|
7
6
|
module CambridgeDict
|
8
7
|
class Error < StandardError; end
|
@@ -171,28 +170,4 @@ module CambridgeDict
|
|
171
170
|
end
|
172
171
|
end
|
173
172
|
|
174
|
-
class API < Sinatra::Base
|
175
|
-
register Sinatra::Cors
|
176
|
-
|
177
|
-
set :allow_origin, "*"
|
178
|
-
set :allow_methods, "GET,HEAD,POST"
|
179
|
-
set :allow_headers, "content-type,if-modified-since"
|
180
|
-
set :expose_headers, "location,link"
|
181
|
-
|
182
|
-
client = Client.new
|
183
|
-
|
184
|
-
get '/api/dictionary/:language/:entry' do
|
185
|
-
content_type :json
|
186
|
-
|
187
|
-
result = client.lookup(params[:entry], language: params[:language])
|
188
|
-
|
189
|
-
if result && !result[:word].empty?
|
190
|
-
status 200
|
191
|
-
result.to_json
|
192
|
-
else
|
193
|
-
status 404
|
194
|
-
{error: "word not found"}.to_json
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cambridge_dict
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben D'Angelo
|
@@ -14,58 +14,30 @@ dependencies:
|
|
14
14
|
name: nokogiri
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.15'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.15'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httparty
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.21'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.21'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: sinatra
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: 0.1.0
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '3.1'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: sinatra-cors
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.2'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
38
|
+
- - ">="
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
40
|
+
version: 0.1.0
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: rspec
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +91,7 @@ files:
|
|
119
91
|
- Rakefile
|
120
92
|
- config.ru
|
121
93
|
- lib/cambridge_dict.rb
|
94
|
+
- lib/cambridge_dict/server.rb
|
122
95
|
- lib/cambridge_dict/version.rb
|
123
96
|
homepage: https://codeberg.org/bendangelo/cambridge_dict
|
124
97
|
licenses:
|