citygrid_api 0.0.3 → 0.0.4
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/VERSION +1 -1
- data/citygrid_api.gemspec +4 -2
- data/lib/citygrid/abstraction/super_array.rb +1 -1
- data/lib/citygrid/details.rb +17 -1
- data/lib/citygrid/listing.rb +9 -4
- data/test/test_details.rb +33 -0
- data/test/test_super_array.rb +23 -0
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/citygrid_api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{citygrid_api}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Elpizo Choi"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-15}
|
13
13
|
s.description = %q{Ruby wrapper for CityGrid APIs}
|
14
14
|
s.email = %q{fu7iin@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -50,8 +50,10 @@ Gem::Specification.new do |s|
|
|
50
50
|
"test/helper.rb",
|
51
51
|
"test/publisher_helper.rb.sample",
|
52
52
|
"test/test_citygrid.rb",
|
53
|
+
"test/test_details.rb",
|
53
54
|
"test/test_listing.rb",
|
54
55
|
"test/test_search.rb",
|
56
|
+
"test/test_super_array.rb",
|
55
57
|
"test/test_super_hash.rb"
|
56
58
|
]
|
57
59
|
s.licenses = ["MIT"]
|
data/lib/citygrid/details.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class CityGrid
|
2
|
-
|
2
|
+
module DetailsMethods
|
3
3
|
def api
|
4
4
|
CityGrid::API::Content::Places::Detail
|
5
5
|
end
|
@@ -7,6 +7,10 @@ class CityGrid
|
|
7
7
|
def request opts = {}
|
8
8
|
api.request opts.merge(:client_ip => "192.168.0.1")
|
9
9
|
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Details < Abstraction::Item
|
13
|
+
include DetailsMethods
|
10
14
|
|
11
15
|
private
|
12
16
|
|
@@ -14,4 +18,16 @@ class CityGrid
|
|
14
18
|
response.locations.first
|
15
19
|
end
|
16
20
|
end
|
21
|
+
|
22
|
+
class MultiDetails < Abstraction::Collection
|
23
|
+
include DetailsMethods
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def preprocess response
|
28
|
+
response.locations.map do |detail|
|
29
|
+
Listing.new(detail).send(:load)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
17
33
|
end
|
data/lib/citygrid/listing.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
class CityGrid
|
2
2
|
class Listing < Abstraction::SuperHash
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
class << self
|
5
|
+
def first opts = {}
|
6
|
+
new({}).update Details.new(opts)
|
7
|
+
end
|
8
|
+
|
9
|
+
def all opts = {}
|
10
|
+
MultiDetails.new opts
|
11
|
+
end
|
6
12
|
end
|
7
13
|
|
8
14
|
def method_missing meth, *args, &block
|
9
|
-
load unless @loaded
|
15
|
+
load.update_details unless @loaded
|
10
16
|
send(meth, *args, &block) rescue super
|
11
17
|
end
|
12
18
|
|
@@ -14,7 +20,6 @@ class CityGrid
|
|
14
20
|
|
15
21
|
def load
|
16
22
|
extend LoadedMethods
|
17
|
-
update_details
|
18
23
|
@loaded = true
|
19
24
|
self
|
20
25
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
context "Initiating a Details" do
|
4
|
+
setup do
|
5
|
+
CityGrid::Details.new :public_id => "philip-marie-restaurant-new-york"
|
6
|
+
end
|
7
|
+
|
8
|
+
should "return a single Details object" do
|
9
|
+
topic.is_a? CityGrid::Details
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "Initiating new MultiDetails" do
|
14
|
+
setup do
|
15
|
+
CityGrid::MultiDetails.new :public_id => "philip-marie-restaurant-new-york"
|
16
|
+
end
|
17
|
+
|
18
|
+
should "return a MultiDetails object" do
|
19
|
+
topic.is_a? CityGrid::MultiDetails
|
20
|
+
end
|
21
|
+
|
22
|
+
should "contain multiple listings" do
|
23
|
+
topic.reject do |listing|
|
24
|
+
listing.is_a? CityGrid::Listing
|
25
|
+
end.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
asserts "all listings are loaded" do
|
29
|
+
topic.reject do |listing|
|
30
|
+
listing.instance_variable_get "@loaded"
|
31
|
+
end.empty?
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
super_array = CityGrid::Abstraction::SuperArray
|
4
|
+
super_hash = CityGrid::Abstraction::SuperHash
|
5
|
+
|
6
|
+
context "A SuperArray" do
|
7
|
+
context "created" do
|
8
|
+
context "with a single level" do
|
9
|
+
setup { super_array.new([1, 2, 3]) }
|
10
|
+
should("return the contents"){ topic == [1, 2, 3]}
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with a hash inside" do
|
14
|
+
setup { super_array.new([1, {:hello => "there"}])}
|
15
|
+
should("replace it with a SuperHash"){ topic[1].is_a? super_hash}
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with an array inside" do
|
19
|
+
setup { super_array.new([1, [2, 3, 4]])}
|
20
|
+
should("replace it with a SuperArray"){ topic[1].is_a? super_array}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: citygrid_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Elpizo Choi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-15 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :runtime
|
@@ -154,8 +154,10 @@ files:
|
|
154
154
|
- test/helper.rb
|
155
155
|
- test/publisher_helper.rb.sample
|
156
156
|
- test/test_citygrid.rb
|
157
|
+
- test/test_details.rb
|
157
158
|
- test/test_listing.rb
|
158
159
|
- test/test_search.rb
|
160
|
+
- test/test_super_array.rb
|
159
161
|
- test/test_super_hash.rb
|
160
162
|
homepage:
|
161
163
|
licenses:
|