Skills Dev 1

Skills Dev Assignment

This assignment will ask you to explore the concepts introduced in class and set up a basic Sinatra web service:

Brief: Build a basic web app that provides information on this course

Due Date: Tuesday Nov 1, 12pm ET

Submission: Add completed code to ‘skills1’ folder in Student section of the course’s GitHub Repo.

Learning Objectives

As part of the exercise, students will:

  • build familiarity with Sinatra web applications using Ruby;
  • become familiar with the structures and syntax of a Sinatra web application;
  • learn how to define ‘endpoints’ and paramters that provide a response to a web request; and
  • apply basic concepts in programming to create dynamic responses (conditions, etc.);

Requirements

For this project, you are to start with a basic sinatra application (see template in the code repo).

Using this template, create a basic web ‘api’ that will serve up information about this course to someone who might want to make use of it.

As part of this project you will be asked to add the following functionality to your Sinatra application. For all of the following use a get request.

Root

  • For the root path / return a 422 error
  • Alternatively redirect it to the title endpoint i.e. don’t allow a response from this route (see below)

Hint: Errors can be defined by using the error number as the response from the route’s block Hint: You’ll need to define a block that handles an error e.g. error 403 do 'Access forbidden' end Hint: You can use redirect to('/bar') to redirect to another route in your sinatra application.

Basic

  1. Define an endpoint called title that returns a string that matches the full title of this course
  2. Define an endpoint called catalog_description that returns a full catalog description of the course
  3. Define an endpoint called units that returns the number of units of the course
  4. Define an endpoint called instructor that returns the name of the instructor, email address and Slack id
    • Suggested: Explore objects as a better way to return this information

Parameters and Conditions

Hint You’ll need to use conditional logic (if elsif else end statements) to make this bit work.

1) Add a configuration block and provide settings that define three links (to the course slack, the main site and the github repository). Then,

  • Define a endpoint called link_to that takes one parameter named item and that will return one of the three links.
  • It should respond with the appropriate url if the paramter equals “slack”, “site”, or “repo”.
  • If it doesn’t receive any of these, it should return a default message.

2) Add an endpoint to look up meeting times for the course.

  • Define an endpoint called meeting_times that takes one parameter
  • If the parameter is a string matching “class”, it will return the class times
  • If the parameter is a string matching “officehours”, it will return the office hour times

Explore: If you’re feeling adventurous try working with date and time objects in Ruby for this part.

Dynamic

We’ll explore some more advanced but richer ways to add some interactivity and dynamic data through date and time, conditions and arrays.

1) Create an endpoint that lets someone know if we’re in class or not.

  • Define a endpoint called in_session that takes no paramters
  • Use Time.now * to look up the time on the server
  • Use Time.new * to create a time instance for the beginning and end of each meeting times
  • Use conditions (if statements) to test if the course is meeting
  • Respond with “Yes” or “No”

2) Return a random link

  • Create an array that contains a list of strings. Each string is a URL to a link from the Resources page of the site.
  • Add this array to the setting configuration for the site.
  • Define an endpoint called interesting_link that returns one of those links each time it’s called

Hint: .sample is a useful method on array that will pick an item from it at random.

User Session

For the interesting_link, use sessions to store what links the user has already seen.

Modify the response to:

  • Send back a link, as well as the last 3 links they’ve seen.

Experiment

Try out some other stuff. Practice beyond these examples and add at least two of your own end points

Grading

Each component above is graded equally. Full grade (100%) is awarded for

  • all required endpoints and paramters correctly defined;
  • returing the correct information in response to a request; and
  • a valid implementation of the functionality to deliver that response;