Skip to content

Instantly share code, notes, and snippets.

@netconstructor
Forked from billeisenhauer/tripcase-model-api
Created August 22, 2014 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netconstructor/5d4cd705d5fac420e9e8 to your computer and use it in GitHub Desktop.
Save netconstructor/5d4cd705d5fac420e9e8 to your computer and use it in GitHub Desktop.
// Session
require(['models/session'], function(Session) { window.Session = Session });
s = new Session();
s.fetch();
// Returns a Session model with the following:
// - attributes contain simple attributes
// - trips (TripList) a collection of Trip models; 'light' versions.
// - user (User) the logged in user; check its attributes for email and name.
// - expenseCategories
// - expensePaymentTypes
// - otherEventsMeta - Essential for messing with generic trip items
// TripsList
require(['collections/trip_list'], function(TripList) { window.TripList = TripList });
tl = new TripList();
tl.fetch();
// Collection will containing resulting Trip models. These will be 'light' trips; empty message and trip items collections.
// Trip
require(['models/trip'], function(Trip) { window.Trip = Trip });
t = new Trip({id: 84});
t.fetch();
// Returns a trip model with the following:
// - attributes contain simple trip attributes
// - tripItems (TripItemList) a heterogeneous collection of TripItem models (air, hotel, vehicle, generic)
// - messages (MessageList) a collection of Message models
// AirlineList
require(['collections/airline_list'], function(AirlineList) { window.AirlineList = AirlineList });
al = new AirlineList([], {search_term: 'AA'});
al.fetch();
// Collection will contain resulting Airplane models.
// CountryList
require(['collections/country_list'], function(CountryList) { window.CountryList = CountryList });
cl = new CountryList([], {search_term: 'US'});
cl.fetch();
// Collection will contain resulting Country models.
// Weather
require(['models/weather'], function(Weather) { window.Weather = Weather });
w = new Weather({airport_code: 'DFW'});
w.fetch();
// Inspect attributes for current_conditions, current_forecast, forecasts, location
// Seat Map
require(['models/seat_map'], function(SeatMap) { window.SeatMap = SeatMap });
sm = new SeatMap({}, {air_trip_item: airTripItem}); // Pass in an air trip item instance
sm.fetch();
// NOTE: The proxy isn't ready for this response yet since the serve does not respond with JSON.
// Forgot Password
require(['models/forgot_password'], function(ForgotPassword) { window.ForgotPassword = ForgotPassword });
fp = new ForgotPassword({email: 'john@doe.com'});
fp.save();
// You can see the built-in error handling support on this one. If you pass in an email that the system doesn't know,
// the model will have an error attribute with an error from the server. This is all done in the proxy for you.
// Otherwise, for success, there's a slew of attributes returned that I haven't bothered to parse out since they aren't
// needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment