fanyi_api 0.0.1 → 0.0.2
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/lib/fanyi_api.rb +1 -0
- data/lib/fanyi_api/requester.rb +1 -2
- data/lib/fanyi_api/strategies/default.rb +1 -0
- data/lib/fanyi_api/strategies/iciba.rb +30 -0
- data/lib/fanyi_api/strategies/youdao.rb +4 -2
- data/lib/fanyi_api/version.rb +1 -1
- data/spec/fanyi_api/strategies/iciba_spec.rb +26 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5acb20d9fb0e14a8cacd63ddee7ed7e869aec194
|
4
|
+
data.tar.gz: 590dd6f6532468c99e46ad38487ba9e55c72ee7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a18358323939d825777fdd444cb05dd4bd194861287532b4c779f34fac6f378c565ef0ca94a5e7e21ecc16af20a0bde9af17de711857f9704dadaf68848a678
|
7
|
+
data.tar.gz: e01e652c752e223a37c31925b32d3f4cbd87343d0a1e356a59a6db8425d291a3a47d6080b2b00f2404934d617ba6c8dbd3886ef3a97e0d9face62921e5e410d2
|
data/lib/fanyi_api.rb
CHANGED
data/lib/fanyi_api/requester.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module FanyiAPI
|
2
|
+
module Strategies
|
3
|
+
|
4
|
+
class Iciba < Default
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
@options = {
|
8
|
+
host: "http://dict-co.iciba.com/api/dictionary.php",
|
9
|
+
type: "json"
|
10
|
+
}.merge(params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def api_url
|
14
|
+
@api_url ||= "#{@options[:host]}?type=#{@options[:type]}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def request_url
|
18
|
+
raise InvalidKey, "Key is not provided!" if @options[:key].nil?
|
19
|
+
|
20
|
+
@request_url ||= api_url + "&key=" + @options[:key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def query_key
|
24
|
+
:w
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module FanyiAPI
|
2
2
|
module Strategies
|
3
3
|
|
4
|
-
InvalidKey = Class.new ArgumentError
|
5
|
-
|
6
4
|
class Youdao < Default
|
7
5
|
|
8
6
|
def initialize(params={})
|
@@ -25,6 +23,10 @@ module FanyiAPI
|
|
25
23
|
@request_url ||= api_url + "&keyfrom=" + @options[:keyfrom] + "&key=" + @options[:key]
|
26
24
|
end
|
27
25
|
|
26
|
+
def query_key
|
27
|
+
:q
|
28
|
+
end
|
29
|
+
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
data/lib/fanyi_api/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FanyiAPI::Strategies::Iciba do
|
4
|
+
|
5
|
+
let(:strategy) { FanyiAPI::Strategies::Iciba.new(key: "key") }
|
6
|
+
|
7
|
+
it "returns api url" do
|
8
|
+
expect(strategy.api_url).to eq \
|
9
|
+
"http://dict-co.iciba.com/api/dictionary.php?type=json"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns request url" do
|
13
|
+
expect(strategy.request_url).to eq \
|
14
|
+
"http://dict-co.iciba.com/api/dictionary.php?type=json&key=key"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#raise_error" do
|
18
|
+
|
19
|
+
it "raise key not found if type is not provided" do
|
20
|
+
expect { FanyiAPI::Strategies::Iciba.new.request_url }.to \
|
21
|
+
raise_error(FanyiAPI::Strategies::InvalidKey)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fanyi_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qi He
|
@@ -48,12 +48,14 @@ files:
|
|
48
48
|
- lib/fanyi_api/api.rb
|
49
49
|
- lib/fanyi_api/requester.rb
|
50
50
|
- lib/fanyi_api/strategies/default.rb
|
51
|
+
- lib/fanyi_api/strategies/iciba.rb
|
51
52
|
- lib/fanyi_api/strategies/youdao.rb
|
52
53
|
- lib/fanyi_api/version.rb
|
53
54
|
- lib/fanyi_api.rb
|
54
55
|
- spec/fanyi_api/api_spec.rb
|
55
56
|
- spec/fanyi_api/requester_spec.rb
|
56
57
|
- spec/fanyi_api/strategies/default_spec.rb
|
58
|
+
- spec/fanyi_api/strategies/iciba_spec.rb
|
57
59
|
- spec/fanyi_api/strategies/youdao_spec.rb
|
58
60
|
- spec/spec_helper.rb
|
59
61
|
homepage: http://github.com/he9qi/fanyi_api
|
@@ -84,5 +86,6 @@ test_files:
|
|
84
86
|
- spec/fanyi_api/api_spec.rb
|
85
87
|
- spec/fanyi_api/requester_spec.rb
|
86
88
|
- spec/fanyi_api/strategies/default_spec.rb
|
89
|
+
- spec/fanyi_api/strategies/iciba_spec.rb
|
87
90
|
- spec/fanyi_api/strategies/youdao_spec.rb
|
88
91
|
- spec/spec_helper.rb
|