yanapi 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +11 -4
- data/LICENSE +1 -1
- data/README +6 -3
- data/lib/yanapi/query.rb +16 -7
- data/lib/yanapi/version.rb +1 -1
- data/test/test_query.rb +20 -6
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
== COMPLETED
|
2
|
+
=== 0.4.0
|
3
|
+
Implemented multivalued parameters as Arrays. You can now search in many regions
|
4
|
+
and categories simultaneously.
|
5
|
+
Enhanced and updated the documentation.
|
2
6
|
=== 0.3.3
|
3
7
|
Added a configuration file for Yard, the documentation should be compatible
|
4
8
|
with {RubyDoc.info}[http://www.rubydoc.info] now.
|
@@ -21,16 +25,19 @@ Initial release of the lib.
|
|
21
25
|
|
22
26
|
|
23
27
|
== PLANNED
|
24
|
-
=== 0.4.0
|
25
|
-
Enhance the documentation.
|
26
|
-
|
27
|
-
Implement multivalue parameters.
|
28
28
|
=== 0.5.0
|
29
29
|
Implement semantic checks for all query types.
|
30
30
|
|
31
31
|
Enhance the documentation.
|
32
32
|
=== 0.6.0
|
33
|
+
Implement the output formats <php>, <json>, <rss>.
|
34
|
+
|
35
|
+
Update the documentation.
|
33
36
|
=== 0.7.0
|
34
37
|
=== 0.8.0
|
35
38
|
=== 0.9.0
|
36
39
|
=== 1.0.0
|
40
|
+
Implement posting and tracking of questions.
|
41
|
+
|
42
|
+
Update the documentations.
|
43
|
+
|
data/LICENSE
CHANGED
data/README
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
= YANAPI
|
2
2
|
|
3
3
|
* {RubyGems}[http://rubygems.org/gems/yanapi]
|
4
|
-
*
|
4
|
+
* {Bug Tracker}[https://github.com/arbox/yanapi/issues]
|
5
5
|
* {YANAPI Project Page}[http://yanapi.rubyforge.org/]
|
6
|
+
* Developers {Homepage}[http://www.bu.chsta.be]
|
7
|
+
|
6
8
|
|
7
9
|
== DESCRIPTION
|
8
10
|
|
@@ -62,11 +64,12 @@ A small example shall demostrate the usage:
|
|
62
64
|
:search_in => 'question',
|
63
65
|
:type => 'resolved',
|
64
66
|
:results => 2,
|
65
|
-
:output => 'xml'
|
67
|
+
:output => 'xml',
|
68
|
+
:region => ['us', 'de']
|
66
69
|
}
|
67
70
|
}
|
68
71
|
api = YANAPI::API.new(params)
|
69
|
-
api.get # =>
|
72
|
+
api.get # => String
|
70
73
|
|
71
74
|
|
72
75
|
For details on particular keys and defaults see {the official description}[http://developer.yahoo.com/answers/] and the RDoc documentation in this library.
|
data/lib/yanapi/query.rb
CHANGED
@@ -12,6 +12,7 @@ module YANAPI
|
|
12
12
|
SERVICE = 'AnswersService'
|
13
13
|
SERVICE_VERSION = 'V1'
|
14
14
|
VALID_PARAMS = [:appid, :output, :callback]
|
15
|
+
MULTIVALUED_PARAMS = [:region, :category_id, :category_name]
|
15
16
|
REQUIRED_PARAMS = [:appid]
|
16
17
|
VALID_OUTPUT_FORMATS = [nil, 'xml', 'php', 'rss', 'json']
|
17
18
|
|
@@ -65,14 +66,22 @@ module YANAPI
|
|
65
66
|
"Output type #{params[:output]} is incompatible with <:callback>!"
|
66
67
|
end
|
67
68
|
|
68
|
-
# It accepts only unique values for every parameter
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
69
|
+
# It accepts only unique values for every parameter other than:
|
70
|
+
# * :category_id;
|
71
|
+
# * :category_name;
|
72
|
+
# * :region.
|
73
|
+
# They can be strings, arrays or numbers:
|
74
|
+
# :category_id => [123, 456, 789].
|
73
75
|
params.each_pair do |k, v|
|
74
|
-
unless (v.kind_of?(String) || v.kind_of?(Fixnum))
|
75
|
-
fail
|
76
|
+
unless (v.kind_of?(String) || v.kind_of?(Fixnum) || v.kind_of?(Array))
|
77
|
+
fail(UserError,
|
78
|
+
"The value type <#{v.class}> for the key <:#{k}> is wrong!")
|
79
|
+
end
|
80
|
+
|
81
|
+
if v.kind_of?(Array)
|
82
|
+
unless MULTIVALUED_PARAMS.include?(k)
|
83
|
+
fail UserError, "The value of <:#{k}> must, but is not unique!"
|
84
|
+
end
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
data/lib/yanapi/version.rb
CHANGED
data/test/test_query.rb
CHANGED
@@ -31,7 +31,8 @@ class TestQuery < Test::Unit::TestCase
|
|
31
31
|
:SERVICE_VERSION,
|
32
32
|
:VALID_PARAMS,
|
33
33
|
:REQUIRED_PARAMS,
|
34
|
-
:VALID_OUTPUT_FORMATS
|
34
|
+
:VALID_OUTPUT_FORMATS,
|
35
|
+
:MULTIVALUED_PARAMS
|
35
36
|
]
|
36
37
|
defined_constants.each do |const|
|
37
38
|
assert(YANAPI::Query.const_defined?(const))
|
@@ -47,6 +48,14 @@ class TestQuery < Test::Unit::TestCase
|
|
47
48
|
|
48
49
|
## Interface tests
|
49
50
|
|
51
|
+
# It should reject any key with values other than <Fixnum>, <String>, <Array>.
|
52
|
+
def test_type_of_value
|
53
|
+
@params[:query_params][:region] = {'a'=>1}
|
54
|
+
e = assert_raises(YANAPI::UserError) { YANAPI::Query.new(@params) }
|
55
|
+
assert_match(/The value type <Hash> for the key <:region> is wrong!/,
|
56
|
+
e.message)
|
57
|
+
end
|
58
|
+
|
50
59
|
# It should reject the input hash without <:appid> parameter.
|
51
60
|
def test_missing_appid
|
52
61
|
@params[:query_params].delete(:appid)
|
@@ -86,10 +95,11 @@ class TestQuery < Test::Unit::TestCase
|
|
86
95
|
assert_raises(YANAPI::UserError) { YANAPI::Query.new(@params) }
|
87
96
|
end
|
88
97
|
|
89
|
-
# It should reject not unique values.
|
98
|
+
# It should reject not unique values for not predefined parameters.
|
90
99
|
def test_uniqueness_of_values
|
91
|
-
@params[:query_params][:
|
92
|
-
assert_raises(YANAPI::UserError) { YANAPI::Query.new(@params) }
|
100
|
+
@params[:query_params][:appid] = ['123', 345]
|
101
|
+
e = assert_raises(YANAPI::UserError) { YANAPI::Query.new(@params) }
|
102
|
+
assert_match(/The value of <:appid> must, but is not unique!/, e.message)
|
93
103
|
end
|
94
104
|
|
95
105
|
|
@@ -98,12 +108,16 @@ class TestQuery < Test::Unit::TestCase
|
|
98
108
|
# It should create well formed urls.
|
99
109
|
def test_url_form
|
100
110
|
q = YANAPI::Query.new(@params)
|
101
|
-
print q.inspect
|
102
111
|
etalon_url = 'http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=YahooDemo&output=xml&query=Haus'
|
103
112
|
real_url = q.instance_variable_get(:@url).to_s
|
104
113
|
assert_equal(etalon_url, real_url)
|
105
114
|
|
106
|
-
|
115
|
+
@params[:query_params][:region] = ['us', 'de']
|
116
|
+
q = YANAPI::Query.new(@params)
|
117
|
+
etalon_url = 'http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=YahooDemo&output=xml&query=Haus®ion=de®ion=us'
|
118
|
+
real_url = q.instance_variable_get(:@url).to_s
|
119
|
+
assert_equal(etalon_url, real_url)
|
120
|
+
|
107
121
|
end
|
108
122
|
|
109
123
|
# It should return <nil> if the server response contains
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yanapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrei Beliankou
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-11 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|