Skip to content

Instantly share code, notes, and snippets.

@grahamb
Last active January 23, 2017 23:26
Show Gist options
  • Save grahamb/777f4500609434f19b6a99a286cda755 to your computer and use it in GitHub Desktop.
Save grahamb/777f4500609434f19b6a99a286cda755 to your computer and use it in GitHub Desktop.

Users API

API for accessing information about a user

Usage notes:

The :username parameter can either be self, or the user's SFU Computing ID (e.g. kipling).

Authentication

Get a user profile

GET /api/v1/users/:username

Retrieve a user's profile.

Returns a user object.

Example Request

curl https://snap.sfu.ca/api/v1/users/self \
  -X GET \
  -H 'Authorization: Bearer <...JWT...>'

Example Response

{
  "id": 12345,
  "username": "kipling",
  "uid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "lastname": "Kipling",
  "firstnames": "Joseph Rudyard",
  "commonname": "Rudy",
  "barcode": "1234567890"
}

Get a user's transit bookmarks

GET /api/v1/users/:username/transitBookmarks

Retrieve the saved transit bookmarks for a user.

Returns an array of transit bookmark objects.

Example Request

curl https://snap.sfu.ca/api/v1/users/self/transitBookmarks \
  -X GET \
  -H 'Authorization: Bearer <...JWT...>'

Example Response

[
  {
    "stop": "50490",
    "route": "209",
    "destination": "VANCOUVER"
  },
  {
    "stop": "50490",
    "route": "004",
    "destination": "UBC"
  }
]

Add a transit bookmark for a user

POST /api/v1/users/:username/transitBookmarks

Add a transit bookmark for a user and return the new list of all bookmarks.

Usage notes

The new bookmark will be merged with the user's existing bookmarks. The array of bookmarks is unique'd when saving; no duplicate bookmarks will be saved.

The JSON payload must conform to the following schema:

{
  type: 'object',
  properties: {
    stop: {
      type: 'string',
      required: true,
      minLength: 5,
      maxLength: 5
    },
    route: {
      type: 'string',
      required: true
    },
    destination: {
      type: 'string',
      required: true
    }
  }
}

Example Request

curl https://snap.sfu.ca/api/v1/users/self/transitBookmarks \
  -X POST \
  -H 'Authorization: Bearer <...JWT...>' \
  -d '{"stop":"51861","route":"145","destination":"PRODUCTION STN"}'

Example Response

[
  {
    "stop": "50490",
    "route": "209",
    "destination": "VANCOUVER"
  },
  {
    "stop": "50490",
    "route": "004",
    "destination": "UBC"
  },
  {
    "stop": "51861",
    "route": "145",
    "destination": "PRODUCTION STN"
  }
]

Delete a transit bookmark for a user

DELETE /api/v1/users/:username/transitBookmarks

Delete a transit bookmark for a user and return the new list of all bookmarks.

Usage notes

Bookmark objects that are not present in the user's bookmarks are ignored; no error is thrown.

The JSON payload must conform to the following schema:

{
  type: 'object',
  properties: {
    stop: {
      type: 'string',
      required: true,
      minLength: 5,
      maxLength: 5
    },
    route: {
      type: 'string',
      required: true
    },
    destination: {
      type: 'string',
      required: true
    }
  }
}
curl https://snap.sfu.ca/api/v1/users/self/transitBookmarks \
  -X DELETE \
  -H 'Authorization: Bearer <...JWT...>' \
  -d '{"stop":"51861","route":"145","destination":"PRODUCTION STN"}'

Example Response

[
  {
    "stop": "50490",
    "route": "209",
    "destination": "VANCOUVER"
  },
  {
    "stop": "50490",
    "route": "004",
    "destination": "UBC"
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment