Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save megstang/4d6b823200f0ce43155c84c5046f2a32 to your computer and use it in GitHub Desktop.
Save megstang/4d6b823200f0ce43155c84c5046f2a32 to your computer and use it in GitHub Desktop.
Market Money Advanced AR Challenge

Advanced Active Record Workshop

Challenge:

Work through as many of the following endpoints as you can/would like:

1. Get one Vendor, list states that vendor sells in

Details:

  1. Update your GET /api/v0/vendors/:id such that it returns an attribute, states_sold_in, that lists the states that Vendor sells in.

  2. If a Vendor only sells at Markets in one state, the data type of the states_sold_in key should still be an array.

    Example

    Request:

      GET /api/v0/vendors/54876
      Content-Type: application/json
      Accept: application/json
    

    Response: status: 200

    {
      "data": {
          "id": "54876",
          "type": "vendor",
          "attributes": {
              "name": "The Sourdough Queen",
              "description": "This vendor bakes a variety of artisanal breads using sourdough starter, from crusty baguettes to hearty whole wheat loaves.",
              "contact_name": "Kasi Greenholt",
              "contact_phone": "(172) 129-4294",
              "credit_accepted": true,
              "states_sold_in": ["California","Nevada"]
          }
      }
    }

2. Get all vendors that sell in more than one state

Details:

  1. The URI should follow this pattern: GET /api/v0/vendors/multiple_states

  2. The response should include a list of vendors that sell at Markets in more than one state.

  3. To make it a little extra spicy, you might try ordering the vendors by number of states sold in.

    Example

    Request:

      GET /api/v0/vendors/54876
      Content-Type: application/json
      Accept: application/json
    

    Response: status: 200

    {
      "results": 56
      "data": [
                {
                  "id": "54876",
                  "type": "vendor",
                  "attributes": {
                      "name": "The Sourdough Queen",
                      "description": "This vendor bakes a variety of artisanal breads using sourdough starter, from crusty baguettes to hearty whole wheat loaves.",
                      "contact_name": "Kasi Greenholt",
                      "contact_phone": "(172) 129-4294",
                      "credit_accepted": true,
                      "states_sold_in": ["California","Nevada"]
                    }
                },
                {
                  "id": "54949",
                  "type": "vendor",
                  "attributes": {
                      "name": "The Handmade Candle Company",
                      "description": "This vendor sells handmade candles made from natural waxes and essential oils.",
                      "contact_name": "Zachariah Emmerich",
                      "contact_phone": "609.634.9167",
                      "credit_accepted": true,
                      "states_sold_in": ["Ohio", "Pennsylvania"]
                    }
                },
            ...
            ...
      ]
            
    }

3. Get a list of the most popular states where vendors sell

Details:

  1. The URI should follow this pattern: GET /api/v0/vendors/popular_states

  2. The response should return a list of states, in order of total number of vendors that sell at Markets in that state.

  3. A little extra: add a limit parameter so a client can search for a certain number of top states. (api/v0/vendors/popular_states?limit=5)

    Example

    Request:

      GET /api/v0/vendors/popular_states?limit=5
      Content-Type: application/json
      Accept: application/json
    

    Response: status: 200

    {
     "data": [
              {
                  "state": "California", 
                  "number_of_vendors": 152
              },
              {
                  "state": "New York", 
                  "number_of_vendors": 134
              },
              {
                  "state": "Massachusetts", 
                  "number_of_vendors": 70 
              },
              {
                  "state": "Michigan", 
                  "number_of_vendors": 68
              },
              {
                  "state": "Ohio", 
                  "number_of_vendors": 66
              },
      ...
      ...

4. Get vendors that sell in a particular state, and order them by most popular

Details:

  1. The URI should follow this pattern: GET /api/v0/vendors?state=<state>
  2. The vendors returned should be ordered in order of their popularity.
  • popularity is determined by how many Markets that vendor sells at.
  1. Note: The example response does not show the states_sold_in attribute. If you'd like to add that in, you can.

    Example

    Request:

      GET /api/v0/vendors?state=Alabama
      Content-Type: application/json
      Accept: application/json
    

    Response: status: 200

    {
      "data": [
                {
                  "id": "55406",
                  "type": "vendor",
                  "attributes": {
                      "name": "Olive My Heart",
                      "description": "Artisanal olive oils and vinegars",
                      "contact_name": "Lyndia Kutch",
                      "contact_phone": "1-495-066-9447",
                      "credit_accepted": false
                    }
                },
                {
                  "id": "56153",
                  "type": "vendor",
                  "attributes": {
                      "name": "Rainbow Knits",
                      "description": "Vibrantly colored knitwear for all ages.",
                      "contact_name": "Hilton Pacocha",
                      "contact_phone": "1-267-788-2536",
                      "credit_accepted": true,
                    }
                },
                {
                  "id": "55400",
                  "type": "vendor",
                  "attributes": {
                      "name": "Pretzel Perfect",
                      "description": "Soft pretzels and dipping sauces",
                      "contact_name": "Rafael Bogisich",
                      "contact_phone": "1-720-033-3107",
                      "credit_accepted": false,
                    }
                },
            ...
            ...
      ]
            
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment