B-Sides / peacekeeper

Peacekeeper handles delegation to a variety of ORMs and separation of business logic from persistance logic
BSD 2-Clause "Simplified" License
1 stars 1 forks source link

API returns everything wrapped in many layers of 'data' #9

Open vosechu opened 12 years ago

vosechu commented 12 years ago

This is the response I'm seeing:

{"data":{"data":{"id":56,"name":"Asian Spice","price_rating":2,"phone_number":"2025890900","time_zone":"Eastern Time (US & 

Ideally it wouldn't wrap this at all.

Here's how I'm calling this:

respond_to :json
def show
  @restaurant = RestaurantModel.find(params[:id])

  respond_with @restaurant
end

Here's my model codes:

class Restaurant < Nasreddin::Resource('restaurants')
  class << self
    def all
      find({})
    end

    def by_metro(metro_id)
      find(metro_id: metro_id)
    end

    def for_merchant(merchant_id)
      find(merchant_id: merchant_id)
    end
  end
end

class RestaurantModel < Peacekeeper::Model
  self.data_source = :api
end
jperrine commented 12 years ago

What version of nasreddin are you using and also what branch/commit of cityeats-next

vosechu commented 12 years ago

nasreddin 0.0.5, branch merchant_apis on cityeats-next

On Fri, Aug 10, 2012 at 11:38 AM, Jimmy Perrine notifications@github.comwrote:

What version of nasreddin are you using and also what branch/commit of cityeats-next

— Reply to this email directly or view it on GitHubhttps://github.com/elc/peacekeeper/issues/9#issuecomment-7653009.

ELC Technologies (TM) 1771 NW Pettygrove Street Portland, OR, 97209

P 866.863.7365 F 877.658.6313 http://www.elctech.com

jperrine commented 12 years ago

nasreddin is up to 0.1.2 I think and also make sure your cityeats-next is up to date

davidcelis commented 12 years ago

I'm seeing this with the latest versions of both nasreddin and peacekeeper. cityeats-next is up-to-date with master

jperrine commented 12 years ago

I'm unable to reproduce this, running on master of cityeats-merchant and merchant_apis of cityeats-next

require 'nasreddin'
require 'rack'
require 'lib/data/api/restaurant'
r = Restaurant.find(57)
 => #<Restaurant:0x42225e9c @data={"id"=>57, "name"=>"Graffiato", "price_rating"=>3, "phone_number"=>"2022893600", "time_zone"=>"Eastern Time (US & Canada)", "accepts_reservations"=>true, "open_for"=>"", "cashonly"=>false, "dresscode"=>"", "popularity"=>4, "reservation_days_in_advance"=>31, "auto_payment_enabled"=>nil, "auto_payment_token"=>nil, "auto_payment_account_number"=>nil, "auto_payment_account_type"=>nil, "created_at"=>"2011-07-20T16:14:26Z", "region_id"=>8, "images"=>[{"id"=>10, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/280/thumb_retina.?1314835438", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/280/thumb_mobile_app.?1314835438", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/280/stock_mobile_app.?1314835438", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/280/stock_mobile_app_retina.?1314835438", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/280/photo_mobile_app.?1314835438", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/280/photo_mobile_app_retina.?1314835438"}, {"id"=>11, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/134/thumb_retina.jpg?1312995962", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/134/thumb_mobile_app.jpg?1312995962", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/134/stock_mobile_app.jpg?1312995962", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/134/stock_mobile_app_retina.jpg?1312995962", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/134/photo_mobile_app.jpg?1312995962", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/134/photo_mobile_app_retina.jpg?1312995962"}, {"id"=>12, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/131/thumb_retina.jpg?1312995958", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/131/thumb_mobile_app.jpg?1312995958", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/131/stock_mobile_app.jpg?1312995958", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/131/stock_mobile_app_retina.jpg?1312995958", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/131/photo_mobile_app.jpg?1312995958", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/131/photo_mobile_app_retina.jpg?1312995958"}, {"id"=>13, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/133/thumb_retina.jpg?1312995960", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/133/thumb_mobile_app.jpg?1312995960", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/133/stock_mobile_app.jpg?1312995960", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/133/stock_mobile_app_retina.jpg?1312995960", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/133/photo_mobile_app.jpg?1312995960", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/133/photo_mobile_app_retina.jpg?1312995960"}, {"id"=>14, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/132/thumb_retina.jpg?1312995959", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/132/thumb_mobile_app.jpg?1312995959", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/132/stock_mobile_app.jpg?1312995959", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/132/stock_mobile_app_retina.jpg?1312995959", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/132/photo_mobile_app.jpg?1312995959", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/132/photo_mobile_app_retina.jpg?1312995959"}, {"id"=>15, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/199/thumb_retina.jpg?1313167219", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/199/thumb_mobile_app.jpg?1313167219", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/199/stock_mobile_app.jpg?1313167219", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/199/stock_mobile_app_retina.jpg?1313167219", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/199/photo_mobile_app.jpg?1313167219", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/199/photo_mobile_app_retina.jpg?1313167219"}, {"id"=>16, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/130/thumb_retina.jpg?1312995956", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/130/thumb_mobile_app.jpg?1312995956", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/130/stock_mobile_app.jpg?1312995956", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/130/stock_mobile_app_retina.jpg?1312995956", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/130/photo_mobile_app.jpg?1312995956", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/130/photo_mobile_app_retina.jpg?1312995956"}, {"id"=>17, "created_at"=>"2011-07-22T16:35:56Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/73/thumb_retina.jpg?1312908841", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/73/thumb_mobile_app.jpg?1312908841", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/73/stock_mobile_app.jpg?1312908841", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/73/stock_mobile_app_retina.jpg?1312908841", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/73/photo_mobile_app.jpg?1312908841", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/73/photo_mobile_app_retina.jpg?1312908841"}, {"id"=>114, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/128/thumb_retina.jpg?1312995956", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/128/thumb_mobile_app.jpg?1312995956", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/128/stock_mobile_app.jpg?1312995956", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/128/stock_mobile_app_retina.jpg?1312995956", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/128/photo_mobile_app.jpg?1312995956", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/128/photo_mobile_app_retina.jpg?1312995956"}, {"id"=>115, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/135/thumb_retina.jpg?1312995963", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/135/thumb_mobile_app.jpg?1312995963", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/135/stock_mobile_app.jpg?1312995963", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/135/stock_mobile_app_retina.jpg?1312995963", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/135/photo_mobile_app.jpg?1312995963", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/135/photo_mobile_app_retina.jpg?1312995963"}, {"id"=>116, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/197/thumb_retina.jpg?1313166674", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/197/thumb_mobile_app.jpg?1313166674", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/197/stock_mobile_app.jpg?1313166674", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/197/stock_mobile_app_retina.jpg?1313166674", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/197/photo_mobile_app.jpg?1313166674", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/197/photo_mobile_app_retina.jpg?1313166674"}, {"id"=>117, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/198/thumb_retina.jpg?1313166675", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/198/thumb_mobile_app.jpg?1313166675", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/198/stock_mobile_app.jpg?1313166675", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/198/stock_mobile_app_retina.jpg?1313166675", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/198/photo_mobile_app.jpg?1313166675", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/198/photo_mobile_app_retina.jpg?1313166675"}, {"id"=>118, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/194/thumb_retina.jpg?1313166671", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/194/thumb_mobile_app.jpg?1313166671", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/194/stock_mobile_app.jpg?1313166671", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/194/stock_mobile_app_retina.jpg?1313166671", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/194/photo_mobile_app.jpg?1313166671", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/194/photo_mobile_app_retina.jpg?1313166671"}, {"id"=>119, "created_at"=>"2011-08-09T17:37:46Z", "title"=>nil, "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/196/thumb_retina.jpg?1313166672", "thumb_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/196/thumb_mobile_app.jpg?1313166672", "stock_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/196/stock_mobile_app.jpg?1313166672", "stock_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/196/stock_mobile_app_retina.jpg?1313166672", "photo_mobile_app"=>"http://s3.amazonaws.com/cityeats-development/images/196/photo_mobile_app.jpg?1313166672", "photo_mobile_app_retina"=>"http://s3.amazonaws.com/cityeats-development/images/196/photo_mobile_app_retina.jpg?1313166672"}], "rating"=>"0.0", "payment_options"=>["Visa", "MasterCard", "Amex"], "restaurant_hours"=>["#<RestaurantHour:0x195537f>", "#<RestaurantHour:0x9cb8af>", "#<RestaurantHour:0x1210a4c>", "#<RestaurantHour:0x2b3d9a>", "#<RestaurantHour:0xd9622a>", "#<RestaurantHour:0x1bbe826>", "#<RestaurantHour:0x1863c9b>"], "address"=>{"id"=>57, "city"=>"Washington", "country_code"=>"US", "lat"=>38.899, "lng"=>-77.0199, "postal_code"=>"20001", "street1"=>"706 6th Street NW", "street2"=>"", "created_at"=>"2011-07-20T16:14:28Z", "restaurant_id"=>57}, "neighborhood"=>{"id"=>13, "name"=>"Penn Quarter / Chinatown", "created_at"=>"2011-07-20T22:15:03Z", "metro_id"=>1}, "cuisine_types"=>[{"id"=>63, "name"=>"Italian", "created_at"=>"2011-07-20T22:45:21Z"}, {"id"=>82, "name"=>"Pizza", "created_at"=>"2011-07-20T22:48:00Z"}, {"id"=>100, "name"=>"Tapas / Small Plates", "created_at"=>"2011-07-20T22:50:24Z"}], "metro"=>{"id"=>1, "short_name"=>"dc", "lat"=>38.8951, "lng"=>-77.0364, "display_name"=>"Washington D.C.", "time_zone"=>"Eastern Time (US & Canada)", "created_at"=>"2011-07-14T01:53:29Z"}, "chef"=>{"id"=>3, "name"=>"Mike Isabella", "restaurant_id"=>57, "created_at"=>"2011-08-09T17:37:46Z", "thumb_retina"=>"http://s3.amazonaws.com/cityeats-development/images/65/thumb_retina.jpg?1312483969", "thumb_large_retina"=>"http://s3.amazonaws.com/cityeats-development/images/65/thumb_large_retina.jpg?1312483969", "resto_retina"=>"http://s3.amazonaws.com/cityeats-development/images/65/resto_retina.jpg?1312483969", "thumb_retina_landscape"=>"http://s3.amazonaws.com/cityeats-development/images/65/thumb_retina_landscape.jpg?1312483969", "thumb_large_retina_landscape"=>"http://s3.amazonaws.com/cityeats-development/images/65/thumb_large_retina_landscape.jpg?1312483969", "resto_retina_landscape"=>"http://s3.amazonaws.com/cityeats-development/images/65/resto_retina_landscape.jpg?1312483969"}}>
r.id
 => 57

Is your respond_with adding the data nesting?

jperrine commented 12 years ago

actually I think your to_json method is wrong, I changed it to this

# in data/api/restaurant
def to_json
  @data.to_json
end

and now I get this when turning it into json

r.to_json
=> "{\"id\":57,\"name\":\"Graffiato\",\"price_rating\":3,\"phone_number\":\"2022893600\",\"time_zone\":\"Eastern Time (US & Canada)\",\"accepts_reservations\":true,\"open_for\":\"\",\"cashonly\":false,\"dresscode\":\"\",\"popularity\":4,\"reservation_days_in_advance\":31,\"auto_payment_enabled\":null,\"auto_payment_token\":null,\"auto_payment_account_number\":null,\"auto_payment_account_type\":null,\"created_at\":\"2011-07-20T16:14:26Z\",\"region_id\":8,\"images\":[{\"id\":10,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/280/thumb_retina.?1314835438\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/280/thumb_mobile_app.?1314835438\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/280/stock_mobile_app.?1314835438\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/280/stock_mobile_app_retina.?1314835438\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/280/photo_mobile_app.?1314835438\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/280/photo_mobile_app_retina.?1314835438\"},{\"id\":11,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/134/thumb_retina.jpg?1312995962\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/134/thumb_mobile_app.jpg?1312995962\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/134/stock_mobile_app.jpg?1312995962\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/134/stock_mobile_app_retina.jpg?1312995962\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/134/photo_mobile_app.jpg?1312995962\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/134/photo_mobile_app_retina.jpg?1312995962\"},{\"id\":12,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/131/thumb_retina.jpg?1312995958\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/131/thumb_mobile_app.jpg?1312995958\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/131/stock_mobile_app.jpg?1312995958\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/131/stock_mobile_app_retina.jpg?1312995958\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/131/photo_mobile_app.jpg?1312995958\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/131/photo_mobile_app_retina.jpg?1312995958\"},{\"id\":13,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/133/thumb_retina.jpg?1312995960\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/133/thumb_mobile_app.jpg?1312995960\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/133/stock_mobile_app.jpg?1312995960\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/133/stock_mobile_app_retina.jpg?1312995960\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/133/photo_mobile_app.jpg?1312995960\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/133/photo_mobile_app_retina.jpg?1312995960\"},{\"id\":14,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/132/thumb_retina.jpg?1312995959\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/132/thumb_mobile_app.jpg?1312995959\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/132/stock_mobile_app.jpg?1312995959\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/132/stock_mobile_app_retina.jpg?1312995959\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/132/photo_mobile_app.jpg?1312995959\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/132/photo_mobile_app_retina.jpg?1312995959\"},{\"id\":15,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/199/thumb_retina.jpg?1313167219\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/199/thumb_mobile_app.jpg?1313167219\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/199/stock_mobile_app.jpg?1313167219\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/199/stock_mobile_app_retina.jpg?1313167219\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/199/photo_mobile_app.jpg?1313167219\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/199/photo_mobile_app_retina.jpg?1313167219\"},{\"id\":16,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/130/thumb_retina.jpg?1312995956\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/130/thumb_mobile_app.jpg?1312995956\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/130/stock_mobile_app.jpg?1312995956\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/130/stock_mobile_app_retina.jpg?1312995956\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/130/photo_mobile_app.jpg?1312995956\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/130/photo_mobile_app_retina.jpg?1312995956\"},{\"id\":17,\"created_at\":\"2011-07-22T16:35:56Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/73/thumb_retina.jpg?1312908841\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/73/thumb_mobile_app.jpg?1312908841\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/73/stock_mobile_app.jpg?1312908841\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/73/stock_mobile_app_retina.jpg?1312908841\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/73/photo_mobile_app.jpg?1312908841\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/73/photo_mobile_app_retina.jpg?1312908841\"},{\"id\":114,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/128/thumb_retina.jpg?1312995956\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/128/thumb_mobile_app.jpg?1312995956\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/128/stock_mobile_app.jpg?1312995956\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/128/stock_mobile_app_retina.jpg?1312995956\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/128/photo_mobile_app.jpg?1312995956\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/128/photo_mobile_app_retina.jpg?1312995956\"},{\"id\":115,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/135/thumb_retina.jpg?1312995963\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/135/thumb_mobile_app.jpg?1312995963\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/135/stock_mobile_app.jpg?1312995963\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/135/stock_mobile_app_retina.jpg?1312995963\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/135/photo_mobile_app.jpg?1312995963\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/135/photo_mobile_app_retina.jpg?1312995963\"},{\"id\":116,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/197/thumb_retina.jpg?1313166674\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/197/thumb_mobile_app.jpg?1313166674\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/197/stock_mobile_app.jpg?1313166674\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/197/stock_mobile_app_retina.jpg?1313166674\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/197/photo_mobile_app.jpg?1313166674\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/197/photo_mobile_app_retina.jpg?1313166674\"},{\"id\":117,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/198/thumb_retina.jpg?1313166675\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/198/thumb_mobile_app.jpg?1313166675\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/198/stock_mobile_app.jpg?1313166675\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/198/stock_mobile_app_retina.jpg?1313166675\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/198/photo_mobile_app.jpg?1313166675\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/198/photo_mobile_app_retina.jpg?1313166675\"},{\"id\":118,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/194/thumb_retina.jpg?1313166671\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/194/thumb_mobile_app.jpg?1313166671\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/194/stock_mobile_app.jpg?1313166671\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/194/stock_mobile_app_retina.jpg?1313166671\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/194/photo_mobile_app.jpg?1313166671\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/194/photo_mobile_app_retina.jpg?1313166671\"},{\"id\":119,\"created_at\":\"2011-08-09T17:37:46Z\",\"title\":null,\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/196/thumb_retina.jpg?1313166672\",\"thumb_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/196/thumb_mobile_app.jpg?1313166672\",\"stock_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/196/stock_mobile_app.jpg?1313166672\",\"stock_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/196/stock_mobile_app_retina.jpg?1313166672\",\"photo_mobile_app\":\"http://s3.amazonaws.com/cityeats-development/images/196/photo_mobile_app.jpg?1313166672\",\"photo_mobile_app_retina\":\"http://s3.amazonaws.com/cityeats-development/images/196/photo_mobile_app_retina.jpg?1313166672\"}],\"rating\":\"0.0\",\"payment_options\":[\"Visa\",\"MasterCard\",\"Amex\"],\"restaurant_hours\":[\"#<RestaurantHour:0x59ea04>\",\"#<RestaurantHour:0x112b2f1>\",\"#<RestaurantHour:0xa21f07>\",\"#<RestaurantHour:0x1a33621>\",\"#<RestaurantHour:0x36cb03>\",\"#<RestaurantHour:0x14a427a>\",\"#<RestaurantHour:0x528fa4>\"],\"address\":{\"id\":57,\"city\":\"Washington\",\"country_code\":\"US\",\"lat\":38.899,\"lng\":-77.0199,\"postal_code\":\"20001\",\"street1\":\"706 6th Street NW\",\"street2\":\"\",\"created_at\":\"2011-07-20T16:14:28Z\",\"restaurant_id\":57},\"neighborhood\":{\"id\":13,\"name\":\"Penn Quarter / Chinatown\",\"created_at\":\"2011-07-20T22:15:03Z\",\"metro_id\":1},\"cuisine_types\":[{\"id\":63,\"name\":\"Italian\",\"created_at\":\"2011-07-20T22:45:21Z\"},{\"id\":82,\"name\":\"Pizza\",\"created_at\":\"2011-07-20T22:48:00Z\"},{\"id\":100,\"name\":\"Tapas / Small Plates\",\"created_at\":\"2011-07-20T22:50:24Z\"}],\"metro\":{\"id\":1,\"short_name\":\"dc\",\"lat\":38.8951,\"lng\":-77.0364,\"display_name\":\"Washington D.C.\",\"time_zone\":\"Eastern Time (US & Canada)\",\"created_at\":\"2011-07-14T01:53:29Z\"},\"chef\":{\"id\":3,\"name\":\"Mike Isabella\",\"restaurant_id\":57,\"created_at\":\"2011-08-09T17:37:46Z\",\"thumb_retina\":\"http://s3.amazonaws.com/cityeats-development/images/65/thumb_retina.jpg?1312483969\",\"thumb_large_retina\":\"http://s3.amazonaws.com/cityeats-development/images/65/thumb_large_retina.jpg?1312483969\",\"resto_retina\":\"http://s3.amazonaws.com/cityeats-development/images/65/resto_retina.jpg?1312483969\",\"thumb_retina_landscape\":\"http://s3.amazonaws.com/cityeats-development/images/65/thumb_retina_landscape.jpg?1312483969\",\"thumb_large_retina_landscape\":\"http://s3.amazonaws.com/cityeats-development/images/65/thumb_large_retina_landscape.jpg?1312483969\",\"resto_retina_landscape\":\"http://s3.amazonaws.com/cityeats-development/images/65/resto_retina_landscape.jpg?1312483969\"}}" 
jballanc commented 12 years ago

We probably need to look at how Peacekeeper is handling to_json delegation. Ideally, we would be using serializers and avoiding the need to call to_json at all. In the mean time, it's possible that to_json is not behaving correctly...

davidcelis commented 12 years ago

:+1: to that.

vosechu commented 12 years ago

I was told by Josh that I was supposed to only use RestaurantModel.find, not Restaurant.find. I've added in the to_json back onto the Restaurant nasreddin model but the effect is exactly the same. I've updated nasreddin to 0.1.2 but to no effect.

RestaurantModel.for_merchant(57)
 => [#<Restaurant:0x2ccef28d @data={"id"=>56, "name"=>"Asian Spice", "price_rating"=>2, "phone_number"=>"2025890900", "time_zone"=>"Eastern Ti...

RestaurantModel.for_merchant(57).to_json
 => "[{\"data\":{\"data\":{\"id\":56,\"name\":\"Asian Spice\",\"price_rating\":2,\"phone_number\":\"2025890900\",\"time_zone\":\"Eastern Time (US

RestaurantModel.find(77).to_json
 => "{\"data\":{\"data\":{\"id\":77,\"name\":\"Betabreakers\",\"price_rating\":2,\"phone_number\":\"2399860233\",\"time_zone\":\"Pacific Time (US
vosechu commented 12 years ago

The to_json method in Restaurant doesn't seem to make any difference. I removed it and got the same results.

jperrine commented 12 years ago

I was using the data class because there was some loading issue trying to do it in the console, yes you should always use the model class and have that delegate

vosechu commented 12 years ago

Did you get the superclass mismatch from issue #10?

jperrine commented 12 years ago

No because peacekeeper wasn't involved

jballanc commented 12 years ago

So, for the time being it's probably not effective to randomly add and/or remove methods that should be getting delegated anyway. Instead, we should try to understand what's going on.

Peacekeeper::Model instances use a "data" ivar to hold a reference to the corresponding data object (which can be an ActiveRecord, Sequel, Nasreddin, etc. instance). Nasreddin::Resource instances use a "data" ivar to hold a reference to the raw deserialized JSON data that was returned by the remote API. It seems pretty clear to me that the "data: { data: { ..." nesting is a result of the default implementation of #to_json dumping key/value pairs of "ivar name"/"ivar value.to_json".

So, likely, we'll need to implement our own #to_json, but before we do that I'd like to understand to_json a bit better (i.e. Why is it operating directly on the Peacekeeper::Model instance, when every method should get delegated. My guess is that #to_json is being included in Object after we do our delegation and undefine Object methods we want to be delegated. This could potentially be a problem later on, with other methods, so we should probably find a generic solution instead of just hacking together a #to_json implementation.)

vosechu commented 12 years ago

Jimmy, I was asking about this line you wrote: "I was using the data class because there was some loading issue trying to do it in the console". Was that the superclass mismatch or something entirely else?

Josh, Sounds like a great thing for yak shaving day. In the meantime I'm using mock data and skipping nasreddin which makes me sad.

jperrine commented 12 years ago

@vosechu No, just some loading error that I don't remember, not a superclass mismatch

Also yeah it sounds like @jballanc is on the right track and Monday will be great for looking into this.