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.
- Try Ruby! (an online interactive tutorial that lets you type Ruby code online and learn Ruby's basic syntax and programming features)
- Learning Ruby
- Learn to Program Ruby
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 firstname.lastname@example.org: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.
- 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"> <cross-domain-policy> <allow-access-from domain="*" /> </cross-domain-policy>
- 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.
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.
- Install Sqlite3 (http://www.sqlite.org/download.html)
- Install DataMapper
$ 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)
- Official Sinatra README
- Building tiny Web-applications in Ruby using Sinatra
- Creating a Sinatra web service for sorting strings
- Web app in under 10 minutes using the Sinatra web framework (You can see how Sinatra can be used to serve HTML pages)
- 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.