Permalink
Browse files

Added initial get_street method

  • Loading branch information...
1 parent fc1615c commit bdf6c9b4db26f30a4965612dff27a2e70d1a0b73 @jbrowning committed Nov 27, 2011
Showing with 33 additions and 8 deletions.
  1. +1 −1 README.textile
  2. +9 −1 lib/snafu/locations.rb
  3. +23 −6 spec/snafu/locations_spec.rb
View
@@ -1,3 +1,3 @@
h1. Snafu
-Snafu is a Ruby implementation of the "Glitch API":http://api.glitch.com. "Glitch":http://glitch.com is a online multiplayer game created by Tiny Speck.
+Snafu is a Ruby gem that provides an interface to the "Glitch API":http://api.glitch.com. "Glitch":http://glitch.com is a online multiplayer game created by Tiny Speck.
@@ -20,6 +20,14 @@ def get_hub(hub_id)
return hub
end
+ def get_street(street_id)
+ response = self.call("locations.streetInfo", :street_tsid => street_id)
+ hub = Hub.new(:id => response["hub"]["id"], :name => response["hub"]["name"])
+ street = Location.new(:id => response["tsid"],
+ :name => response["name"],
+ :hub => hub)
+ end
+
# Models
class Hub
@@ -41,7 +49,7 @@ def initialize(options = {})
if options
@id = options[:id]
@name = options[:name]
- @hub = options[:name]
+ @hub = options[:hub]
end
end
end
@@ -5,6 +5,8 @@
@snafu = Snafu.new("test-key")
@test_hub_id = 27
@test_hub_name = "Ix"
+ @test_street_id = "LM416LNIKVLM1"
+ @test_street_name = "Baby Steppes"
end
context "get_hubs" do
it "should return an array of all hubs" do
@@ -21,7 +23,6 @@
end
context "get_hub" do
-
it "should return a hub if given a valid Hub ID" do
hub = @snafu.get_hub(@test_hub_id)
hub.name.should eql(@test_hub_name)
@@ -33,14 +34,30 @@
end
end
+ context "get_street" do
+ before(:each) do
+ @test_street = @snafu.get_street(@test_street_id)
+ end
+
+ it "should return a street if given a valid street ID" do
+ @test_street.id.should_not be_nil
+ @test_street.name.should_not be_nil
+ end
+
+ it "should contain a reference to its parent hub" do
+ @test_street.hub.id.should_not be_nil
+ @test_street.hub.name.should_not be_nil
+ end
+
+ it "should contain connections to adjacent locations"
+ end
+
describe Snafu::Locations::Hub do
Hub = Snafu::Locations::Hub
it "should retain the ID & Name of the hub if given a valid " do
- id = "27"
- name = "Ix"
- hub = Hub.new(:id => id, :name => name)
- hub.id.should eql(id)
- hub.name.should eql(name)
+ hub = Hub.new(:id => @test_hub_id, :name => @test_hub_name)
+ hub.id.should eql(@test_hub_id)
+ hub.name.should eql(@test_hub_name)
end
end

0 comments on commit bdf6c9b

Please sign in to comment.