yanapi 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/LICENSE +19 -0
- data/README +12 -0
- data/README.rdoc +23 -0
- data/Rakefile +14 -0
- data/lib/yanapi.rb +6 -0
- data/lib/yanapi/category_query.rb +10 -0
- data/lib/yanapi/error.rb +37 -0
- data/lib/yanapi/query.rb +188 -0
- data/lib/yanapi/question_query.rb +10 -0
- data/lib/yanapi/term_query.rb +30 -0
- data/lib/yanapi/user_query.rb +10 -0
- data/lib/yanapi/version.rb +3 -0
- data/test/data/bad_xml.txt +236 -0
- data/test/data/empty_result.txt +13 -0
- data/test/data/error_code.txt +237 -0
- data/test/data/response_with_error.txt +15 -0
- data/test/data/successfull_response.txt +237 -0
- data/test/test_query.rb +112 -0
- data/test/test_term_query.rb +64 -0
- data/yanapi.gemspec +23 -0
- metadata +118 -0
data/test/test_query.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yanapi/query'
|
3
|
+
require 'fakeweb'
|
4
|
+
|
5
|
+
class TestQuery < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@params = {:appid => 'MyID', :method => 'questionSearch'}
|
8
|
+
end
|
9
|
+
def teardown
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_public_methods
|
13
|
+
q = YANAPI::Query.new(@params)
|
14
|
+
assert_respond_to(q, :get)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_constants
|
18
|
+
assert_equal('http://answers.yahooapis.com', YANAPI::Query::HOST)
|
19
|
+
assert_equal('AnswersService', YANAPI::Query::SERVICE)
|
20
|
+
assert_equal('V1', YANAPI::Query::SERVICE_VERSION)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_missing_appid
|
24
|
+
@params.delete(:appid)
|
25
|
+
assert_raises(YANAPI::Error) do
|
26
|
+
q = YANAPI::Query.new(@params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# a Query can be only initialized with a valid value for :method
|
31
|
+
def test_missing_method
|
32
|
+
@params.delete(:method)
|
33
|
+
assert_raises(YANAPI::Error) do
|
34
|
+
q = YANAPI::Query.new(@params)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# :method may have only the following values:
|
39
|
+
# questionSearch|getByCategory|getQuestion|getByUser
|
40
|
+
def test_method_semantics
|
41
|
+
@params[:method] = 'someSampleMethod'
|
42
|
+
assert_raises(YANAPI::Error) do
|
43
|
+
q = YANAPI::Query.new(@params)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# :output may be missing
|
48
|
+
def test_missing_output
|
49
|
+
@params.delete(:output)
|
50
|
+
q = YANAPI::Query.new(@params)
|
51
|
+
assert_equal('xml', q.output)
|
52
|
+
end
|
53
|
+
|
54
|
+
# :output may be NIL or have values xml|json|php|rss
|
55
|
+
def test_output_semantics
|
56
|
+
@params[:output] = 'trash'
|
57
|
+
assert_raises(YANAPI::Error) do
|
58
|
+
q = YANAPI::Query.new(@params)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# :callback may be used only with :output => 'json'
|
63
|
+
def test_parameters_clash
|
64
|
+
# the default value 'xml' is set internally during the initialization
|
65
|
+
# we may delete the input value
|
66
|
+
@params.delete(:output)
|
67
|
+
@params[:callback] = 'wrapper'
|
68
|
+
assert_raises(YANAPI::Error) do
|
69
|
+
q = YANAPI::Query.new(@params)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# :callback may be used only with :output => 'json'
|
74
|
+
def test_parameters_pairing
|
75
|
+
@params[:output] = 'json'
|
76
|
+
@params[:callback] = 'wrapper'
|
77
|
+
assert_nothing_raised {q = YANAPI::Query.new(@params)}
|
78
|
+
end
|
79
|
+
|
80
|
+
# we can get an empty response set with valid xml structure
|
81
|
+
# and the status code 200 HTTP OK
|
82
|
+
# but we should declene this
|
83
|
+
def test_empty_response
|
84
|
+
q = YANAPI::Query.new(@params)
|
85
|
+
page = File.open('test/data/empty_result.txt') {|f| f.read}
|
86
|
+
FakeWeb.register_uri(:get, q.url, :response => page)
|
87
|
+
assert_raises(YANAPI::EmptyResponse) {q.get}
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_response_with_error
|
91
|
+
q = YANAPI::Query.new(@params)
|
92
|
+
|
93
|
+
page = File.open('test/data/response_with_error.txt') {|f| f.read}
|
94
|
+
FakeWeb.register_uri(:get, q.url, :response => page)
|
95
|
+
assert_raises(YANAPI::ContentError) {q.get}
|
96
|
+
|
97
|
+
page = File.open('test/data/error_code.txt') {|f| f.read}
|
98
|
+
FakeWeb.register_uri(:get, q.url, :response => page)
|
99
|
+
assert_raises(YANAPI::ContentError) {q.get}
|
100
|
+
|
101
|
+
page = File.open('test/data/bad_xml.txt') {|f| f.read}
|
102
|
+
FakeWeb.register_uri(:get, q.url, :response => page)
|
103
|
+
assert_raises(YANAPI::ContentError) {q.get}
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_successfull_response
|
107
|
+
q = YANAPI::Query.new(@params)
|
108
|
+
page = File.open('test/data/successfull_response.txt') {|f| f.read}
|
109
|
+
FakeWeb.register_uri(:get, q.url, :response => page)
|
110
|
+
assert_nothing_raised {q.get}
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yanapi/term_query'
|
3
|
+
require 'fakeweb'
|
4
|
+
|
5
|
+
class TestTermQuery < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@params = {
|
8
|
+
:query => 'Auto',
|
9
|
+
:appid => 'YahooDemo'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
def teardown
|
13
|
+
end
|
14
|
+
|
15
|
+
# questionSearch needs a unique :query
|
16
|
+
def test_missing_query
|
17
|
+
@params.delete(:query)
|
18
|
+
assert_raises(YANAPI::Error) do
|
19
|
+
q = YANAPI::TermQuery.new(@params)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# parameters can be only: query|search_in|category_query|category_name|
|
24
|
+
# region|date_range|sort|appid|type|start|results|output|callback
|
25
|
+
def test_parameters_semantics
|
26
|
+
assert_nothing_raised {q = YANAPI::TermQuery.new(@params)}
|
27
|
+
@params[:trash] = 'trash'
|
28
|
+
assert_raises(YANAPI::Error) do
|
29
|
+
q = YANAPI::TermQuery.new(@params)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# validates presense of query
|
34
|
+
# validates uniqueness of query
|
35
|
+
# validates the range of :start
|
36
|
+
# validates the range of :results
|
37
|
+
# validates the :region semantics
|
38
|
+
# validates the :type uniqueness and semantics
|
39
|
+
# validates uniqueness of the :date_range and its semantics
|
40
|
+
# validates semantics of all possible parameter names
|
41
|
+
|
42
|
+
def test_start_range
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_result_range
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_region_semantics
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# ?? not sure
|
53
|
+
def test_type_uniqueness
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_type_semantics
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_date_uniqueness
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_date_semantics
|
63
|
+
end
|
64
|
+
end #TestTermQuery
|
data/yanapi.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
lib_path = File.expand_path('../lib', __FILE__) # strange??
|
2
|
+
$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
|
3
|
+
require 'yanapi/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yanapi"
|
7
|
+
s.summary = 'YANAPI is an API for Yahoo! Answers web services.' # it is the description for 'gem list -d'
|
8
|
+
s.description = 'YANAPI is a programmatic API for Yahoo! Answers web services.It enables you to search for questions using key words, user IDs, category names and IDs and a pricise ID of a question. The output is provided in the xml format as well as json, php and rss.' # it appears on the RubyGems page
|
9
|
+
s.rubyforge_project = "yanapi"
|
10
|
+
s.version = YANAPI::VERSION
|
11
|
+
s.author = "Andrei Beliankou"
|
12
|
+
s.email = "a.belenkow@uni-trier.de"
|
13
|
+
s.homepage = "http://www.uni-trier.de/index.php?id=34451"
|
14
|
+
# s.require_paths = 'lib' # it is the default value, why to use?
|
15
|
+
s.add_dependency('nokogiri')
|
16
|
+
s.add_development_dependency('fakeweb')
|
17
|
+
s.rdoc_options = ["-m", "README.rdoc"]
|
18
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
|
19
|
+
s.platform = Gem::Platform::RUBY
|
20
|
+
s.required_ruby_version = '>=1.8.7'
|
21
|
+
s.files = Dir['**/*']
|
22
|
+
s.test_files = `ls test/test_*.rb`.split("\n")
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yanapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrei Beliankou
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-26 23:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: nokogiri
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: fakeweb
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: YANAPI is a programmatic API for Yahoo! Answers web services.It enables you to search for questions using key words, user IDs, category names and IDs and a pricise ID of a question. The output is provided in the xml format as well as json, php and rss.
|
50
|
+
email: a.belenkow@uni-trier.de
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
- LICENSE
|
58
|
+
files:
|
59
|
+
- README.rdoc
|
60
|
+
- yanapi.gemspec
|
61
|
+
- test/test_query.rb
|
62
|
+
- test/test_term_query.rb
|
63
|
+
- test/data/bad_xml.txt
|
64
|
+
- test/data/empty_result.txt
|
65
|
+
- test/data/error_code.txt
|
66
|
+
- test/data/response_with_error.txt
|
67
|
+
- test/data/successfull_response.txt
|
68
|
+
- LICENSE
|
69
|
+
- Rakefile
|
70
|
+
- README
|
71
|
+
- lib/yanapi/error.rb
|
72
|
+
- lib/yanapi/user_query.rb
|
73
|
+
- lib/yanapi/question_query.rb
|
74
|
+
- lib/yanapi/term_query.rb
|
75
|
+
- lib/yanapi/category_query.rb
|
76
|
+
- lib/yanapi/version.rb
|
77
|
+
- lib/yanapi/query.rb
|
78
|
+
- lib/yanapi.rb
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://www.uni-trier.de/index.php?id=34451
|
81
|
+
licenses: []
|
82
|
+
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options:
|
85
|
+
- -m
|
86
|
+
- README.rdoc
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 57
|
95
|
+
segments:
|
96
|
+
- 1
|
97
|
+
- 8
|
98
|
+
- 7
|
99
|
+
version: 1.8.7
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project: yanapi
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: YANAPI is an API for Yahoo! Answers web services.
|
116
|
+
test_files:
|
117
|
+
- test/test_query.rb
|
118
|
+
- test/test_term_query.rb
|