Git Product home page Git Product logo

crm-web-june-8-2016's Introduction

Customer Relationship Manager - Web (CRM-Web) Assignment

The assignment is to implement a web version of the CRM application which you already built.

Please use the below as a guide and not as an exact "how-to" to implement your solution. Use common sense and judgement where appropriate.

Be sure to read over the entire assignment first to get a general feeling and overview of what you have to do, before digging into each part.

Introduction

We're working our way towards using Rails, which is a pretty hefty framework with lots of concepts to learn all at once. Our first simple project will allow us to explore all the different aspects of making web applications, but by working at a smaller scale, it allows us to hone in on specific concepts. Instead of using all of the framework at once, we will building our way towards it, piece by piece, using Sinatra.

Before we get started, there are a few concepts to introduce to you, and a few chores to do.

1. Requests and Responses

When clients make HTTP requests, they pass along a URL, a method (or verb), a series of headers and sometimes a body containing data. When servers return HTTP responses, they pass along a response code (status code), headers and the response body containing the requested data. We care especially about two properties in general: request methods and response codes: they are able to help describe the nature of a request or response.

Image of Request & Response

Request Methods

What is CRUD?

A request method is important because it tells us what we should be doing with the request data. A server can not only retrieve data, but is also in charge of managing any changes to it as well. A request method is always combined with a URL.

Here a the most common request methods, you should be comfortable with these:

GET: fetch or read a resource. The URL contains all the necessary information the server needs to locate and return the resource.

POST: create a new resource. POST requests usually carry a request body that specifies the data for the new resource.

PUT: change or update a resource. PUTS request should also carry a request body with the updated data

DELETE: delete a resource.

These also correspond to what we refer to as the CRUD actions. Create, Read, Update, and Delete.

Submitting Data over the Web

Making a GET request is pretty straightforward. Every time you enter a URL in your browser or click on a link, you're making a GET request. They don't require anything more than a URL.

In order to make other types of requests with a browser, you will need to provide an HTML form that your user can submit. Inside the form element, you can specify which "method" to use.

Here's an example using POST

<form action="/" method="post">
    <input type="text" name="first_name">
    <input type="text" name= "last_name">
    <input type="submit" value="Submit">
</form>

Response Codes

Response codes are important because they let the browser know exactly what happened with the request. Was it successful? Was the resource found? Did it move from where it used to be? Did the server crash? All of these events can be described to the browser with a response code.

Response codes are grouped by number, some of them you may have heard of before, like 200 OK and 404 Not Found.

1xx: Informational These types of response codes aren't really used. They were added in HTTP 1.1

2xx: Success This tells the client that the request was successfully processed. The most common code is 200 OK. For a GET request, the server sends the resource in the message body.

3xx: Redirection This requires the client to take additional action. The most common use-case is to jump to a different URL in order to fetch the resource.

4xx: Client Error These codes are used when the server thinks that the client is at fault, either by requesting an invalid resource or making a bad request. The most popular code in this class is 404 Not Found, which I think every one of us has seen. 404 indicates that the resource is invalid and does not exist on the server.

5xx: Server Error This class of codes are used to indicate a server failure while processing the request. The most commonly used error code is 500 Internal Server Error.

A full list of all response codes is available inside the HTTP official spec.

2. Sinatra

Now that you're familiar with the nitty-gritty details of how a simple web server works, we're going to add a bit of complexity. Given the fact that every single web application requires running atop a web server, we programmers don't tend to "reinvent the wheel" each time, we use well-written, well-supported libraries that'll do this for us!

There also comes a time where it makes sense to start separating the application code with the server code. It makes things a lot easier to read if both concerns are well-separated. By using an existing library for your server, you don't really ever need to look at this code, you can focus on making things instead!

For this assignment, you'll be working with the Sinatra web framework. It's a pretty "lightweight" framework that doesn't offer too many bells and whistles, but it provides enough functionality to help you build great web applications.

Install Sinatra

Unlike sockets, which we used in the 'Build Your Own Web Server' assignment, Sinatra isn't part of the the Ruby standard library. It's available as a Ruby Gem (a prepackaged piece of ) that you will need to download and install with the following command.

$ gem install sinatra

Once it's installed, you'll be able to require it inside your project, just like sockets.

A sample hello_world.rb using Sinatra:

require 'sinatra'

get '/' do
  'Hello World'
end

As you can see, it really doesn't take much to get started with Sinatra! The blocks (aka routes) you provide in your application are what define the responses the corresponding request method and matching url.

3. Code Reuse

Re-use the Contact Class

We are now almost ready to start this assignment!

But first, please copy & paste the Contact class from your crm assignment into the provided contact.rb file that has been provided to you. We are going to reuse that class in this assignment.

After you've copied & pasted the Contact class into contact.rb, run the following at the command line:

ruby test/contact_test.rb

If your Contact class has been implemented "correctly", you should see something like the following:

$ ruby test/contact_test.rb
Run options: --seed 13446

# Running:

.......

Finished in 0.001099s, 6369.0612 runs/s, 6369.0612 assertions/s.

7 runs, 7 assertions, 0 failures, 0 errors, 0 skips

Isn't that awesome? This is part of the power of testing, in that you can be sure a certain piece of code still works even if you use it in another project. We'll be learning more about testing in the coming weeks.

If your Contact class didn't quite pass muster and some of the tests are failing, don't sweat it. We don't want you to get hung up here. Ask an Instructor nicely and they'll provide you with a Contact class that'll work for the purposes of this assignment.

Go ahead and commit your changes now that you've updated the Contact class.

What about the CRM Class?

What about the CRM class from the non-web CRM assignment? I'm glad you asked! The previous CRM class was built as a command-line interface. But now we are going to build a web interface, so the old CRM class is obsolete and we won't be using it here!

That's the great thing about classes in that you can build them in such a way that you can re-use them across projects! As we upgrade parts of the application, we can get rid of obsolete parts and keep the parts that don't have anything to do with what we're upgrading.

4. Assignment Parts

This is a fairly large assignment that is spread out over four days/parts. On each day, follow the instructions on the following pages:

As you are working on this assignment, you should be getting in the habit of commit each significant piece of work throughout the day. At the end of each day don't forget to push your code to Github!

Additional Resources

crm-web-june-8-2016's People

Contributors

samunt avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.