yanapi 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,5 +10,5 @@ SRC = FileList['**/*.rb']
10
10
  CLOBBER.include('doc', '**/*.html', '**/*.gem')
11
11
 
12
12
  Rake::TestTask.new do |t|
13
- t.test_files = FileList.new('test/**/test_*.rb')
13
+ t.test_files = FileList.new('test/test_yanapi.rb')
14
14
  end
@@ -1,10 +1,34 @@
1
+
1
2
  module YANAPI
2
3
 
3
4
  class CategoryQuery < Query
5
+
6
+ include Common
4
7
 
5
- def initialize(*)
6
- raise NotImplementedError, 'CategoryQuery is still not implemented!'
8
+ def initialize(params)
9
+ params[:method] = 'getByCategory'
10
+ super
7
11
  end
8
-
12
+
13
+ private
14
+ # specific checks for CategoryQuery
15
+ #--
16
+ def check_params(params)
17
+ unless params[:category_id] || params[:category_name]
18
+ raise Error, "Category is missing!"
19
+ end
20
+
21
+ allowed = %w{category_id category_name region
22
+ date_range sort appid type start
23
+ results output callback method
24
+ }
25
+
26
+ # in the module Common
27
+ check_semantics(allowed, params)
28
+ basic_check(params)
29
+
30
+ super
31
+ end
32
+
9
33
  end # CategoryQuery
10
34
  end # module
@@ -0,0 +1,17 @@
1
+ module YANAPI
2
+ module Common
3
+ private
4
+ def basic_check(params)
5
+ # fake
6
+ end
7
+
8
+ def check_semantics(allowed, actual)
9
+ actual.each_key do |param|
10
+ unless allowed.include?(param.to_s)
11
+ raise Error, "The parameter #{param} is not allowed!"
12
+ end
13
+ end
14
+ end
15
+
16
+ end # Common
17
+ end # YANAPI
data/lib/yanapi/query.rb CHANGED
@@ -21,8 +21,8 @@ module YANAPI
21
21
 
22
22
  # it is a bad idea to alter the parameters hash
23
23
  # that's why we duplicate the parameters
24
- checked_params = check_params(params.dup)
25
- @url = build_url(checked_params)
24
+ check_params(params)
25
+ @url = build_url(params.dup)
26
26
 
27
27
  $stderr.puts 'Full url:', @url if $DEBUG
28
28
  end
@@ -130,9 +130,8 @@ module YANAPI
130
130
  end
131
131
 
132
132
  if params[:output] != 'json' && params[:callback]
133
- raise Error, "The output type #{@output} is not supported!"
133
+ raise Error, "You may not use callback with output type: #{@output}!"
134
134
  end
135
- return params
136
135
  end
137
136
 
138
137
  # proves the presense of an error
@@ -2,27 +2,31 @@ module YANAPI
2
2
 
3
3
  class TermQuery < Query
4
4
 
5
+ include Common
6
+
5
7
  def initialize(params)
6
-
7
8
  params[:method] = 'questionSearch'
8
9
  super
9
10
  end
10
11
 
11
12
  private
12
- # specific checks for
13
- #--
14
13
  # validates presense of query
15
14
  # validates uniqueness of query
16
- # validates the range of :start
17
- # validates the range of :results
18
- # validates the :region semantics
19
- # validates the :type uniqueness and semantics
20
- # validates uniqueness of the :date_range and its semantics
21
- # validates semantics of all possible parameter names
22
15
  def check_params(params)
23
16
  unless params[:query]
24
17
  raise Error, "Query is missing!"
25
18
  end
19
+
20
+ allowed = %w{query search_in category_id
21
+ category_name region date_range
22
+ sort appid type start results
23
+ output callback method
24
+ }
25
+
26
+ # in the module Common
27
+ check_semantics(allowed, params)
28
+ basic_check(params)
29
+
26
30
  super
27
31
  end
28
32
 
@@ -1,3 +1,3 @@
1
1
  module YANAPI
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/yanapi.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'yanapi/common'
1
2
  require 'yanapi/query'
2
3
  require 'yanapi/term_query'
3
4
  require 'yanapi/question_query'
4
5
  require 'yanapi/user_query'
5
6
  require 'yanapi/category_query'
6
7
  require 'yanapi/version'
8
+
@@ -0,0 +1,61 @@
1
+ require 'test/unit'
2
+ require 'yanapi'
3
+ require 'fakeweb'
4
+
5
+ class TestCategoryQuery < Test::Unit::TestCase
6
+ def setup
7
+ @params = {
8
+ :category_name => 'Ausgehen',
9
+ :appid => 'YahooDemo'
10
+ }
11
+ end
12
+ def teardown
13
+ end
14
+
15
+ # getByCategory (CategorySearch) needs either :category_id or :category_name
16
+ def test_missing_category
17
+ @params.delete(:category_name)
18
+ @params.delete(:category_id)
19
+ assert_raises(YANAPI::Error) {YANAPI::CategoryQuery.new(@params)}
20
+ end
21
+
22
+ # parameters can be only: category_name|category_name|
23
+ # region|date_range|sort|appid|type|start|results|output|callback
24
+ def test_parameters_semantics
25
+ assert_nothing_raised {YANAPI::CategoryQuery.new(@params)}
26
+ @params[:trash] = 'trash'
27
+ assert_raises(YANAPI::Error) {YANAPI::CategoryQuery.new(@params)}
28
+ end
29
+
30
+ # validates presense of query
31
+ # validates uniqueness of query
32
+ # validates the range of :start
33
+ # validates the range of :results
34
+ # validates the :region semantics
35
+ # validates the :type uniqueness and semantics
36
+ # validates uniqueness of the :date_range and its semantics
37
+ # validates semantics of all possible parameter names
38
+
39
+ def test_start_range
40
+ end
41
+
42
+ def test_result_range
43
+ end
44
+
45
+ def test_region_semantics
46
+
47
+ end
48
+
49
+ # ?? not sure
50
+ def test_type_uniqueness
51
+ end
52
+
53
+ def test_type_semantics
54
+ end
55
+
56
+ def test_date_uniqueness
57
+ end
58
+
59
+ def test_date_semantics
60
+ end
61
+ end #TestTermQuery
@@ -0,0 +1,40 @@
1
+ require 'test/unit'
2
+ require 'yanapi'
3
+
4
+ class TestCommon < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ # validates the range of :start
12
+ # validates the range of :results
13
+ # validates the :region semantics
14
+ # validates the :type uniqueness and semantics
15
+ # validates uniqueness of the :date_range and its semantics
16
+ # validates semantics of all possible parameter names
17
+
18
+ def test_start_range
19
+ end
20
+
21
+ def test_result_range
22
+ end
23
+
24
+ def test_region_semantics
25
+
26
+ end
27
+
28
+ # ?? not sure
29
+ def test_type_uniqueness
30
+ end
31
+
32
+ def test_type_semantics
33
+ end
34
+
35
+ def test_date_uniqueness
36
+ end
37
+
38
+ def test_date_semantics
39
+ end
40
+ end
data/test/test_query.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'yanapi/query'
2
+ require 'yanapi'
3
3
  require 'fakeweb'
4
4
 
5
5
  class TestQuery < Test::Unit::TestCase
@@ -18,6 +18,7 @@ class TestQuery < Test::Unit::TestCase
18
18
  assert_equal('http://answers.yahooapis.com', YANAPI::Query::HOST)
19
19
  assert_equal('AnswersService', YANAPI::Query::SERVICE)
20
20
  assert_equal('V1', YANAPI::Query::SERVICE_VERSION)
21
+ assert(YANAPI::VERSION.is_a?(String) && ! YANAPI::VERSION.empty?)
21
22
  end
22
23
 
23
24
  def test_missing_appid
@@ -59,22 +60,16 @@ class TestQuery < Test::Unit::TestCase
59
60
  end
60
61
  end
61
62
 
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
63
 
73
64
  # :callback may be used only with :output => 'json'
74
65
  def test_parameters_pairing
75
66
  @params[:output] = 'json'
76
67
  @params[:callback] = 'wrapper'
77
68
  assert_nothing_raised {q = YANAPI::Query.new(@params)}
69
+ @params[:output] = 'xml'
70
+ assert_raises(YANAPI::Error) {YANAPI::Query.new(@params)}
71
+ @params.delete(:output)
72
+ assert_raises(YANAPI::Error) {YANAPI::Query.new(@params)}
78
73
  end
79
74
 
80
75
  # we can get an empty response set with valid xml structure
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require 'yanapi'
3
+
4
+ class TestQuestionQuery < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+
10
+ end #TestQuestionQuery
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require 'yanapi/term_query'
2
+ require 'yanapi'
3
3
  require 'fakeweb'
4
4
 
5
5
  class TestTermQuery < Test::Unit::TestCase
@@ -16,14 +16,14 @@ class TestTermQuery < Test::Unit::TestCase
16
16
  def test_missing_query
17
17
  @params.delete(:query)
18
18
  assert_raises(YANAPI::Error) do
19
- q = YANAPI::TermQuery.new(@params)
19
+ YANAPI::TermQuery.new(@params)
20
20
  end
21
21
  end
22
22
 
23
- # parameters can be only: query|search_in|category_query|category_name|
24
- # region|date_range|sort|appid|type|start|results|output|callback
23
+ # parameters can be only: query|search_in|category_id|category_name|
24
+ # region|date_range|sort|appid|type|start|results|output|callback|method
25
25
  def test_parameters_semantics
26
- assert_nothing_raised {q = YANAPI::TermQuery.new(@params)}
26
+ assert_nothing_raised {YANAPI::TermQuery.new(@params)}
27
27
  @params[:trash] = 'trash'
28
28
  assert_raises(YANAPI::Error) do
29
29
  q = YANAPI::TermQuery.new(@params)
@@ -32,33 +32,5 @@ class TestTermQuery < Test::Unit::TestCase
32
32
 
33
33
  # validates presense of query
34
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
35
 
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
36
  end #TestTermQuery
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require 'yanapi'
3
+
4
+ class TestUserQuery < Test::Unit::TestCase
5
+ def setup
6
+ end
7
+ def teardown
8
+ end
9
+ end #TestUserQuery
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ require 'test_query'
4
+ require 'test_term_query'
5
+ require 'test_category_query'
6
+ require 'test_user_query'
7
+ require 'test_question_query'
8
+ require 'test_common'
data/yanapi.gemspec CHANGED
@@ -10,14 +10,13 @@ Gem::Specification.new do |s|
10
10
  s.version = YANAPI::VERSION
11
11
  s.author = "Andrei Beliankou"
12
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')
13
+ s.homepage = "http://www.uni-trier.de/index.php?id=34451" # move on qa.uni
14
+ s.add_runtime_dependency('nokogiri')
16
15
  s.add_development_dependency('fakeweb')
17
16
  s.rdoc_options = ["-m", "README.rdoc"]
18
17
  s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
19
- s.platform = Gem::Platform::RUBY
20
- s.required_ruby_version = '>=1.8.7'
18
+ s.platform = Gem::Platform::RUBY # how to run it on JRuby?
19
+ s.required_ruby_version = '>=1.8' # is it a correct notation?
21
20
  s.files = Dir['**/*']
22
21
  s.test_files = `ls test/test_*.rb`.split("\n")
23
22
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yanapi
3
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
4
+ prerelease:
5
+ version: 0.1.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Andrei Beliankou
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-03-26 23:00:00 +01:00
13
+ date: 2011-04-05 00:00:00 +02:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,9 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
35
  version: "0"
47
36
  type: :development
48
37
  version_requirements: *id002
@@ -58,8 +47,13 @@ extra_rdoc_files:
58
47
  files:
59
48
  - README.rdoc
60
49
  - yanapi.gemspec
50
+ - test/test_yanapi.rb
51
+ - test/test_user_query.rb
61
52
  - test/test_query.rb
53
+ - test/test_category_query.rb
62
54
  - test/test_term_query.rb
55
+ - test/test_common.rb
56
+ - test/test_question_query.rb
63
57
  - test/data/bad_xml.txt
64
58
  - test/data/empty_result.txt
65
59
  - test/data/error_code.txt
@@ -72,6 +66,7 @@ files:
72
66
  - lib/yanapi/user_query.rb
73
67
  - lib/yanapi/question_query.rb
74
68
  - lib/yanapi/term_query.rb
69
+ - lib/yanapi/common.rb
75
70
  - lib/yanapi/category_query.rb
76
71
  - lib/yanapi/version.rb
77
72
  - lib/yanapi/query.rb
@@ -91,28 +86,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
86
  requirements:
92
87
  - - ">="
93
88
  - !ruby/object:Gem::Version
94
- hash: 57
95
- segments:
96
- - 1
97
- - 8
98
- - 7
99
- version: 1.8.7
89
+ version: "1.8"
100
90
  required_rubygems_version: !ruby/object:Gem::Requirement
101
91
  none: false
102
92
  requirements:
103
93
  - - ">="
104
94
  - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
95
  version: "0"
109
96
  requirements: []
110
97
 
111
98
  rubyforge_project: yanapi
112
- rubygems_version: 1.3.7
99
+ rubygems_version: 1.5.2
113
100
  signing_key:
114
101
  specification_version: 3
115
102
  summary: YANAPI is an API for Yahoo! Answers web services.
116
103
  test_files:
104
+ - test/test_category_query.rb
105
+ - test/test_common.rb
117
106
  - test/test_query.rb
107
+ - test/test_question_query.rb
118
108
  - test/test_term_query.rb
109
+ - test/test_user_query.rb
110
+ - test/test_yanapi.rb