qype-qype 0.1.0

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.
@@ -0,0 +1,87 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class PlaceMappingTest < Test::Unit::TestCase
4
+
5
+ place_xml = File.read(File.dirname(__FILE__) + '/fixtures/place.xml')
6
+
7
+ context 'A single place' do
8
+ before do
9
+ @place = Qype::Place.parse(place_xml, :single => true)
10
+ end
11
+
12
+ test 'should have basic elements' do
13
+ assert_equal 'Mr. Kebab', @place.title
14
+ assert_equal '040 437798', @place.phone
15
+ assert_equal 4.95, @place.average_rating
16
+ assert_equal '53.5564,9.96239', @place.point
17
+ end
18
+
19
+ test 'should include a image element with three thumbnail sizes' do
20
+ image = @place.image
21
+ assert_not_nil image
22
+ assert_equal "http://assets1.qype.com/uploads/photos/0017/4291/IMG_2092_mini.JPG?1208428301", image.small
23
+ assert_equal "http://assets2.qype.com/uploads/photos/0017/4291/IMG_2092_thumb.JPG?1208428303", image.medium
24
+ assert_equal "http://assets3.qype.com/uploads/photos/0017/4291/IMG_2092_gallery.JPG?1208428300", image.large
25
+ end
26
+
27
+ test 'should include a address element' do
28
+ address = @place.address
29
+ assert_not_nil address
30
+ assert_equal 'Thadenstrasse', address.street
31
+ assert_equal '22767', address.postcode
32
+ assert_equal '1', address.housenumber
33
+ assert_equal 'Hamburg', address.city
34
+ end
35
+
36
+ test 'should include multiple category elements' do
37
+ categories = @place.categories
38
+ assert_equal 2, categories.size
39
+ assert_equal "Döner und Griechischer Imbiss", categories[0].title
40
+ assert_equal "Türkische Restaurants", categories[1].title
41
+ end
42
+
43
+ test 'should include links to reviews in multiple languages' do
44
+ review_links = @place.links.select { |link| link.rel == 'http://schemas.qype.com/reviews' }
45
+ assert_equal 5, review_links.size
46
+
47
+ german_link = review_links.find { |link| link.hreflang == 'de' }
48
+ assert_equal 'http://api.qype.com/v1/places/7019/reviews/de', german_link.href
49
+ assert_equal 40, german_link.count
50
+ end
51
+
52
+ test 'should include a link to the locator' do
53
+ locator_link = @place.links.find { |link| link.rel == 'http://schemas.qype.com/locator' }
54
+ assert_not_nil locator_link
55
+ assert_equal 'Hamburg', locator_link.title
56
+ end
57
+
58
+ test 'should include a link to assets for the place' do
59
+ assets_link = @place.links.find { |link| link.rel == 'http://schemas.qype.com/assets' }
60
+ assert_not_nil assets_link
61
+ end
62
+
63
+ test 'should fetch reviews in a specific language' do
64
+ client = mock_client(File.dirname(__FILE__) + '/fixtures/reviews.xml')
65
+
66
+ reviews = @place.reviews(client, 'de')
67
+ assert_equal 10, reviews.size
68
+ end
69
+ end
70
+
71
+ context 'Search places' do
72
+
73
+ test 'should search for places' do
74
+ client = mock_client(File.dirname(__FILE__) + '/fixtures/places.xml')
75
+ places = Qype::Place.search(client, 'Sushi', 'Hamburg')
76
+ assert_equal 10, places.size
77
+ end
78
+
79
+ test 'should find places nearby' do
80
+ client = mock_client(File.dirname(__FILE__) + '/fixtures/places.xml')
81
+ places = Qype::Place.nearby(client, 53.5511, 9.98199)
82
+ assert_equal 10, places.size
83
+ end
84
+
85
+ end
86
+
87
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class ReviewMappingTest < Test::Unit::TestCase
4
+
5
+ review_xml = File.read(File.dirname(__FILE__) + '/fixtures/review.xml')
6
+
7
+ context 'A single review' do
8
+ before do
9
+ @review = Qype::Review.parse(review_xml, :single => true)
10
+ end
11
+
12
+ test 'should have basic review elements' do
13
+ assert_equal 'de', @review.language
14
+ assert_equal 4, @review.rating
15
+
16
+ paragraph = /<p>/
17
+ assert_no_match paragraph, @review.content
18
+
19
+ assert_match paragraph, @review.formatted_content
20
+ end
21
+
22
+ test 'should include tag elements' do
23
+ tags = @review.tags
24
+ assert_equal 8, tags.size
25
+ assert_equal "günstig", tags.first.term
26
+ end
27
+
28
+ test 'should include a link to the locator' do
29
+ locator_link = @review.links.find { |link| link.rel == 'http://schemas.qype.com/locator' }
30
+ assert_not_nil locator_link
31
+ assert_equal 'Hamburg', locator_link.title
32
+ end
33
+
34
+ test 'should include a link to the place' do
35
+ place_link = @review.links.find { |link| link.rel == 'http://schemas.qype.com/place' }
36
+ assert_not_nil place_link
37
+ assert_equal 'Mr. Kebab', place_link.title
38
+ end
39
+
40
+ test 'should include a link to the user' do
41
+ user_link = @review.links.find { |link| link.rel == 'http://schemas.qype.com/user' }
42
+ assert_not_nil user_link
43
+ assert_equal 'Grobi', user_link.title
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,13 @@
1
+ $: << File.join(File.dirname(__FILE__), '..')
2
+
3
+ require 'rubygems'
4
+ require 'context'
5
+ require 'mocha'
6
+
7
+ require 'qype'
8
+
9
+
10
+ def mock_client(response_file)
11
+ response = File.read(response_file)
12
+ mock(:get => response)
13
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qype-qype
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Munz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: The official Ruby Library for interacting with the Qype API.
25
+ email: florian@qype.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - lib/httparty_patch.rb
32
+ - lib/qype/client.rb
33
+ - lib/qype/models.rb
34
+ - lib/qype.rb
35
+ - LICENSE
36
+ - README.markdown
37
+ files:
38
+ - lib/httparty_patch.rb
39
+ - lib/qype/client.rb
40
+ - lib/qype/models.rb
41
+ - lib/qype.rb
42
+ - LICENSE
43
+ - Manifest
44
+ - Rakefile
45
+ - README.markdown
46
+ - test/fixtures/place.xml
47
+ - test/fixtures/places.xml
48
+ - test/fixtures/review.xml
49
+ - test/fixtures/reviews.xml
50
+ - test/place_mapping_test.rb
51
+ - test/review_mapping_test.rb
52
+ - test/test_helper.rb
53
+ - qype.gemspec
54
+ has_rdoc: true
55
+ homepage: http://github.com/qype/qype
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --line-numbers
59
+ - --inline-source
60
+ - --title
61
+ - Qype
62
+ - --main
63
+ - README.markdown
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "1.2"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project: qype
81
+ rubygems_version: 1.2.0
82
+ signing_key:
83
+ specification_version: 2
84
+ summary: The official Ruby Library for interacting with the Qype API.
85
+ test_files:
86
+ - test/place_mapping_test.rb
87
+ - test/review_mapping_test.rb
88
+ - test/test_helper.rb