Commit 2a999e7
Changed files (4)
app
spec
app/controllers/restaurant_controller.rb
@@ -19,15 +19,22 @@ class RestaurantController < UIViewController
@add.center = CGPointMake(self.view.frame.size.width / 2, @text_field.center.y + 40)
self.view.addSubview @add
@add.when(UIControlEventTouchUpInside) do
- @add.enabled = false
- @text_field.enabled = false
- p @text_field.text
- location = Restaurant.new(@text_field.text, 1, 1)
- location.save
+ begin
+ @add.enabled = false
+ @text_field.enabled = false
+ BW::Location.get do |result|
+ BW::Location.stop
+ location = Restaurant.new(@text_field.text, result[:to].latitude, result[:to].longitude)
+ location.save
+ end
+ rescue Exception => e
+ puts e.message
+ puts e.backtrace.inspect
+ end
end
- access_twitter
- end
+ #access_twitter
+ end
def access_twitter
@account_repository = ACAccountStore.alloc.init
app/models/restaurant.rb
@@ -8,20 +8,30 @@ class Restaurant
end
def save
-
-
-
-
- begin
- BW::HTTP.post("http://localhost:3000/api/v1/restaurants", payload: { restaurant: { name: @name, latitude: @latitude, longitude: @longitude } } ) do |response|
- begin
- p response
- rescue Exception => e
- p e
+ begin
+ BW::HTTP.post("http://localhost:3000/api/v1/restaurants", to_hash ) do |response|
+ begin
+ p response
+ rescue Exception => e
+ p e
+ end
end
+ rescue Exception => e
+ p e
end
- rescue Exception => e
- p e
end
-end
+
+ def to_hash
+ {
+ payload:
+ {
+ restaurant:
+ {
+ name: @name,
+ latitude: @latitude,
+ longitude: @longitude
+ }
+ }
+ }
+ end
end
app/app_delegate.rb
@@ -1,15 +1,5 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
- begin
- BW::Location.get do |result|
- p "LOCATION: #{result}"
- p result
- #p "From Lat #{result[:from].latitude}, Long #{result[:from].longitude}"
- #p "To Lat #{result[:to].latitude}, Long #{result[:to].longitude}"
- end
- rescue Exception => e
- p e
- end
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@location_controller = RestaurantController.alloc.initWithNibName(nil, bundle:nil)
spec/location_spec.rb
@@ -0,0 +1,12 @@
+describe "location" do
+ it "should be able to tell me my location" do
+ BW::Location.get do |result|
+ BW::Location.stop
+ p "LOCATION: #{result}"
+ p result
+ result.should_not be_nil
+ #p "From Lat #{result[:from].latitude}, Long #{result[:from].longitude}"
+ #p "To Lat #{result[:to].latitude}, Long #{result[:to].longitude}"
+ end
+ end
+end