Homework I4

From Cmsc434_s10
Jump to: navigation, search

Implementation 4 (Due date: 4/14, 2pm)

The objective of this homework is to help you learn how to build your own web services to support your Flex applications. We've chosen Sinatra as the web application framework and Heroku as the hosting service, because of their simplicity, which allows you to focus more of your efforts on the design and development of the front-end UI.

These slides explain the benefits of this choice: http://www.slideshare.net/ztieee/sinatra-and-heroku-a-comfortable-ruby-way-for-web-service.

Part 1 : Setting up (10 points)

Installing Ruby, RubyGems, and Git

1. Install Ruby (http://www.ruby-lang.org/). You may have already installed Ruby from previous courses such as CMSC 330. You can open a command prompt and type ruby -v to test if it's the case. If you have not used Ruby before, it's a good investment of your time to learn it. Below are some resources to get you started with Ruby programming.

2. Install RubyGems following the instructions at http://docs.rubygems.org/read/chapter/3. RubyGems is a package manager for Ruby that can help you download and install various Ruby libraries easily. Moreover, it allows you to write "require rubygems"in the first line of your Ruby script and download all the other required libraries automatically. There is an option to install RubyGems along with Ruby if you download the One-Click Installer for Ruby (for Windows) so that it doesn't need to be installed separately.

3. Install Git (http://git-scm.com/). Git is a popular version control system invented by the same person who invented Linux. It is used for many open source projects for managing and coordinating development efforts by large teams of contributors. Create your ssh keys by following the instructions provided by github at http://help.github.com/key-setup-redirect. You only need to follow the instructions up to (and including) Generating a Key. You do not need to add keys to Github accounts. We won't be using Github.


  • If you are using Windows, you can watch this video that takes you through the entire installation process. For now, you only need to watch up to 4min 44sec for this part. Later when you are asked to install Sqlite3, you can come back and watch the rest of the video if necessary.

Creating Web Services using Sinatra and Heroku


  • Connect the Virtual STAMP Flex application you've built to your own web services.



  • Create a free account at Heroku (http://heroku.com/). Heroku is a site that can host your web applications written in Ruby. The free version Blossom uses a shared database and has a 5MB space limit, but it is more than enough for the homework and course project. We will use Heroku as the learning platform for you to get some experience on building web services.
  • Follow the steps that Heroku provides once you click the confirmation link sent to your email after signing up. It tells you to install the Heroku gem, among other things.
  • Create and deploy a "Hello World" Sinatra app to Heroku following the instruction at http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/.
  • Use Heroku’s online interface to change the subdomain name randomly generated for you (e.g., severe-spring-77) to something meaningful and unique (e.g., my-cmsc434-i4-app). Then follow the instruction to update your local repository to point at the remote location, which amounts to the following two commands, replace newname with the name you picked.
$ git remote rm heroku
$ git remote add heroku git@heroku.com:newname.git
  • Download the starter code stamp.zip. Unzip and save the content (i.e., stamp.rb) in the same directory as hello.rb.
  • Add the following line to config.ru in order to include the code in your Sinatra app.
  require 'stamp'
  • Create a directory named public and in it create an xml file named crossdomain.xml that has the following content. The purpose is to allow crossdomain calls by your uploaded Flex app in the course wiki to the server app. Make sure there are no spaces proceeding each line because these spaces have been know to cause problems.
 <?xml version="1.0"?>
 <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
 <allow-access-from domain="*" />
  • Type the same three commands to commit changes and push the app to Heroku
  $ git add .
  $ git commit –m 'added stamp.rb'
  $ git push heroku master
  • Test if the app runs properly on the remote server by calling the web service for resetting the menu items (replacing cmsc434-i4 with your app's name). This step must be run in order to populate the content of the database.
  • Modify the HTTPService tags in your Flex application to point at the domain location of your own web app on Heroku. You should do this for list, create, update, and delete. Note that you no longer need to include a unique username in the path.

Part 2: Creating an UI for restaurants (90 points)

In this part, you need to design and build a user interface for administrators to edit the list of restaurant. Also, on the server's side, you need to implement additional web services for listing, creating, updating, and deleting restaurants.

Testing locally

You may find it a big hassle to push your app to the server every time you make a change. To avoid this hassle, it would be nice to run and test the app locally. To do so, you need to install a number of libraries and tools Heroku has already installed for you on the server's side but may not be available on your own machine.

 $ gem install dm-core
 $ gem install do_sqlite3
  • Install Sinatra
 $ gem install sinatra
  • After completing the installation above, start the Sinatra app on your local machine as a server process.
 $ ruby stamp.rb
  • Test if it works by making a call to the web service to reset the menu on localhost at the port 4567.



Figure out how to do the following using DataMapper:

  • define a data model
  • associate one object class with another, for example, making a MenuItem object associated with a Restaurant object
  • retrieve a particular object using its id
  • retrieve a particular object using one of its attributes
  • create a new object and save it in the database
  • update an existing object
  • delete an existing object
  • delete an existing object and all the objects associated with it




  • Administrators should be able to see a list of restaurant names currently in the system. (15 points)
  • Administrators should be able to create a new restaurant by specifying its name. (15 points)
  • Administrators should be able to update the name of an existing restaurant. (15 points)
  • Administrators should be able to delete an existing restaurant. (15 points)
  • In the UI for managing menu items, administrators should be able to select from a dropdown list of restaurant names automatically populated and updated. (15 points)
  • The UI should provide good usability. (15 points)



  • Implement each place in stamp.rb that has a ToDo label.
  • Add an UI to your Virtual STAMP Flex app for listing, adding, updating, and deleting restaurants.


A - H

Name Part 1 Part 2
Firstname lastname Media:swf-I4-1.swf Media:swf-I4-2.swf
Kevin Barrett Media:Barrett_I4_1.swf Media:Barrett_I4_2.swf
Venkat Dinavahi Media:venkatd-i4-1.swf Media:venkatd-i4-2.swf
Michael D Media:Stamp_i4.swf Media:i4-2.swf
Frank Cannavo Media:fcannavo_I4_1.swf Media:fcannavo_I4_2.swf
Amit Chauhan Media:Chauhan-I4-1.swf Media:Chauhan-I4-2.swf
Ben Cwik Media:bcwikI4.swf Media:bcwikI4_2.swf
Patrick Dattilio Media:dattilio-imp4-1a.swf Media:dattilio-imp4-2.swf
Nathan DeSelms Media:Ndeselms-I41.swf Media:Ndeselms-I42.swf
John Fan Media:johnfani4p1.swf Media:johnfani4p2.swf
Andrew Ferguson Media:Ferguson-imp4-1.swf Media:Ferguson-imp4-2.swf
Lucas Gonzalez-Fernandez Media:lgf-I4-1.swf Media:lgf-I4-2.swf
Mark Heneks Media:Mheneks-i4p1-Stamp.swf Media:Mheneks-i4p2-Stamp.swf

I - P

Name Part 1 Part 2
Firstname lastname Media:swf-I4-1.swf Media:swf-I4-2.swf
Joseph Isaac Media:JIsaac-I4-1.swf Media:JIsaac-I4-2.swf
Jeff Jacobs Media:Jacobs-swf-I4-1c.swf Media:Jacobs-swf-I4-2.swf
Asmi Joshi Media:AsmiStamp-part1.swf
Kashif Khan Part 1 Part 2]
Jonathan Lee Media:Lee-I4-1.swf Media:Lee-I4-2.swf
Justin Lindsey Media:Cmsc434-i4-jlindsey.swf Media:Cmsc434-i4-jlindsey2.swf
Ran Liu Media:ran-I4-1.swf Media:ran-I4-2.swf
Kelly McDuffie Media:McDuffie-I4-1-2.swf Media:McDuffie-I4-2-3.swf
Leyla Norooz Media:lnorooz-I4-Stamp.swf Media:lnorooz-I4-part2-2-Stamp.swf
Mihir Patel Media:mpatel88-i4-1.swf Media:mpatel88-i4-2.swf

Q - Z

Name Part 1 Part 2
Firstname lastname Media:swf-I4-1.swf Media:swf-I4-2.swf
Brian Ramnarain Media: ramnarain-swf-I4-1.swf
Corey Richardson Media:Richardson-I4-1.swf Media:Richardson-I4-2.swf
Luis Sanchez Part 1 Part 2
Nidhi Sethi Media:ns_i4Part2.swf Media:nsethi-i4p2-Stamp.swf
Anand Shroff Media:Ashroff-I4-1.swf Media:Ashroff-I4-2.swf
Cody Smith Media:csmith71-I4-1.swf Media:csmith71-I4-2.swf
David Thomas Media:dthom-i4_1.swf Media:dthom-Project4p2.swf
Mekias Yohannes Media: Mekias-I4-p1.swf Media:Mekias-I4-p2.swf