Skip to content

2. APIs and Controller

Ibrahim Kosgi edited this page Apr 19, 2022 · 49 revisions

Pins

Get Nearby Pins

Return ReMemri pins that are within a given threshold of the user's current location. If a username and authorization is provided and correct, private pins posted by the user's friends will also be returned. If no username is provided, only public pins will be returned.

Endpoint: GET /nearby_pins/

Code

Request Parameters

Key Location Type Description
current_location Request Parameters String User's current location of the form latitude,longitude
username Request Parameters String Optional unique ID for the current user
radius Request Parameters String Optional maximum radius in miles of nearby pins to return

Response Codes

Code Description
200 Success
400 No location provided
401 User not found
403 Unauthorized user

Returns

Returns a list of objects of form:

When a user is provided and authenticated

Key Location Type Description
comments JSON JSON List List of comments (and their information) associated with the pin (If the pin has any comments)
distance JSON Float Distance between the user and the pin
is_friend JSON Boolean Represents whether or not the given user is friends with the pin owner
is_public JSON Boolean Represents whether or not the pin is public
location JSON Array of Floats Represents the latitude and longitude location of the pin
media_url JSON String Base64 representation of the pin's image
owner_id JSON String Username of the pin owner
pin_id JSON String Unique ID for the pin
timestamp JSON String Timestamp of when the pin was posted

When a user is not provided

Key Location Type Description
comments JSON JSON List List of comments (and their information) associated with the pin (If the pin has any comments)
distance JSON Float Distance between the user and the pin
is_public JSON Boolean Represents whether or not the pin is public
location JSON Array of Floats Represents the latitude and longitude location of the pin
media_url JSON String Base64 representation of the pin's image
owner_id JSON String Username of the pin owner
pin_id JSON String Unique ID for the pin
timestamp JSON String Timestamp of when the pin was posted

Comment -- Nested JSON Object Description

Key Location Type Description
owner_id JSON String Username of comment writer
text JSON String Text of the given comment
timestamp JSON String Time this pin was created

Example

For provided user

[
    {
        "comments": [
            {
                "owner_id": "test user",
                "text": "test text",
                "timestamp": "Thu, 17 Mar 2022 21:11:19 GMT"
            },
            {
                "owner_id": "user4",
                "text": "test text 2",
                "timestamp": "Sat, 26 Mar 2022 17:40:30 GMT"
            },
            ...
        ],
        "distance": 0.0,
        "is_friend": false,
        "is_public": true,
        "location": [
            42.292083,
            -83.71588
        ],
        "media_url": "/9j/4AAQSkZJRgABAQEBLAEsAAD/4hrESUNDX1BST0ZJTEUAAQE...",
        "owner_id": "user0",
        "pin_id": "1234",
        "timestamp": "Thu, 17 Mar 2022 21:03:22 GMT"
    }
]

Get Pin

Return information about a specific ReMemri pin. A pin contains one post with an image and comments.

Endpoint: GET /pin/pin_id/

Code

Request Parameters

Key Location Type Description
pin_id Path Parameters String ID of requested pin
username Request Parameters String Optional username of requester
comments_only Request Parameters Boolean Optional determines whether to return entire pin or just pin's comments

Response Codes

Code Description
200 Success
401 User not found
403 User cannot access pin
404 Pin not found

Returns

Pin without comments

Key Location Type Description
is_public JSON Boolean Represents whether or not the pin is public
location JSON Array of Floats Represents the latitude and longitude location of the pin
media_url JSON String Base64 representation of the pin's image
owner_id JSON String Username of the pin owner
pin_id JSON String Unique ID for the pin
timestamp JSON String Timestamp of when the pin was posted

Only comments

Array of comment objects

Key Location Type Description
owner_id JSON String Username of comment writer
text JSON String Text of the given comment
timestamp JSON String Time this pin was created

Example

Pin only

{
    "is_public": true,
    "location": [
        42.292083,
        -83.71588
    ],
    "media_url": "/9j/4AAQSkZJRgABAQEBLAEsAAD/4hrESUNDX1BST0Z...",
    "owner_id": "user0",
    "pin_id": "1234",
    "timestamp": "Thu, 17 Mar 2022 21:03:22 GMT"
}

Comments only

[
    {
        "owner_id": "test user",
        "text": "test text",
        "timestamp": "Thu, 17 Mar 2022 21:11:19 GMT"
    },
    {
        "owner_id": "user4",
        "text": "test text 2",
        "timestamp": "Sat, 26 Mar 2022 17:40:30 GMT"
    },
    ...
]

Get Friends

Return a list of the current users friends. Note that mutual friendship status is required for one user to see and comment on another user's pins.

Endpoint: GET /friends/

Request Parameters

Key Location Type Description
username Request Parameters String Current User

Response Codes

Code Description
200 Success
400 Error with input
401 User not found
403 Unauthorized user

Returns

Location Type Description
JSON List Unique usernames for the user's friends

Example

GET /friends?username=user0

[
    "user7",
    "user3",
    "user1",
    "user2"
]

Get Incoming Friend Requests

Return a list of the current users pending incoming friend requests. The request and return fields are the same as in Get Friends.

Endpoint: GET /friend_requests/incoming/

Request Parameters

Key Location Type Description
username Request Parameters String Current User

Response Codes

Code Description
200 Success
400 Error with input
401 User not found
403 Unauthorized user

Returns

Location Type Description
JSON List Unique usernames for the user's incoming friend requests

Example

GET /friend_requests/incoming?username=user0

[
    "user1",
    "user2",
    "user3"
]

Get Outgoing Friend Requests

Return a list of the current users pending outgoing friend requests. The request and return fields are the same as in Get Friends.

Endpoint: GET /friend_requests/outgoing/

Request Parameters

Key Location Type Description
username Request Parameters String Current User

Response Codes

Code Description
200 Success
400 Error with input
401 User not found
403 Unauthorized user

Returns

Location Type Description
JSON List Unique usernames for the user's outgoing friend requests

Example

GET /friend_requests/outgoing?username=user0

[
    "user4",
    "user5",
    "user6"
]

Post Pin

Endpoint: POST /pin/

Make a new ReMemri pin and post it to the map. Note that only logged in users can make pins. When a pin is made an image is attached to it and the visibility is set (either public or only friends). Make post is it's own action detailed in the Post Photo section below.

Code

Request Parameters

Key Location Type Description
username JSON String Current User
is_public JSON Boolean Truth value for whether or not the pin has public visibility
pin_location JSON Array of Floats User's current location that the pin is being posted from
image JSON String Base64 encoded image

Response Codes

Code Description
200 Success
403 Unauthorized user
404 User not found

Returns

Returns an object of the form:

Key Location Type Description
success JSON String Response message of True for a successful post
pin_id JSON String The unique pin ID for the new post

Example

{
    "success": True,
    "pin_id": "fa62b410-db..."
}

Post Friends

Make and accept friend requests to/from other users in the ReMemri system. Note that only MUTUAL friends (i.e. both users have friended each other) will be able to view and comment on each other's pins. The JSON object that is used for making and accepting friend requests is the same and is detailed below.

Endpoint is: POST /friend_request/

Request Parameters

Key Location Type Description
user1 JSON String Current User
user2 JSON String Target User
action JSON String User's desired action regarding the friend request, can be either [accept], [reject], or [request]

Response Codes

Code Description
200 Success
400 Error with input (e.g. no target user, user friend requesting existing friend, etc)
403 Unauthorized user

Returns

Returns an object of form:

Key Location Type Description
message JSON String "Success" for a successful friend request action

Example

POST /friend_request with body:

{
    "user1": "user0",
    "user2": "user10",
    "action": "request"
}
{
    "message": "Success"
}

Post Comment

Post a comment on a pin in a nearby location. Note that only signed in users will be able to post comments. If a user is not signed in, comments will be displayed on public pins but the user cannot interact.

Endpoint: POST /comment/

Code

Request Parameters
Note: this is similar to the comment object described in the Get Pin section

Key Location Type Description
username JSON String Current User
comment_text JSON String Text of the given comment
pin_id JSON String Unique ID for the pin this comment is associated with

Response Codes

Code Description
200 Success
400 No username provided
403 Unauthorized user
404 User/pin not found

Returns

Returns an object of form:

Key Location Type Description
success JSON String "success" for a successful comment

Example

{
    "success": True,
}

Sign Up

Endpoint: POST /accounts/sign_up/

Request Parameters

Key Location Type Description
username JSON String Chosen username from sign up form
password JSON String Chosen password from sign up form

Response Codes

Code Description
200 Success
401 Invalid credentials
409 Username already exists

Returns an object of form:

Key Location Type Description
token JSON String The logged in user's authentication token

Example

{
    "token": "eyJ0eXAiOiJKV1..."
}

Sign In

Endpoint: POST /accounts/sign_in/

Code

Request Parameters

Key Location Type Description
username JSON String Chosen username from sign in form
password JSON String Chosen password from sign in form

Response Codes

Code Description
200 Success
401 Invalid credentials

Returns an object of form:

Key Location Type Description
success JSON String "success" for a successful comment
token JSON String The logged in user's authentication token

Example

{
    "success": True,
    "token": "eyJ0eXAiOiJKV1..."
}

Third-Party SDKs

Our front end will be written using a combination of native Kotlin, ARCore, and a third-party SDK called Mapbox.

Mapbox

Mapbox will be used for ReMemri's map view. The pins will be displayed on the map view and the user will be able to click on pins to view them in Augmented Reality mode.

ARCore

ARCore will be used for ReMemri's Augmented Rreality view. When a user clicks on a pin in map view, AR view will launch and the user will be able to see the images at the given pin in AR.

GeoPy API

We use GeoPy API on the back end to calculate distances between two GPS locations.

Clone this wiki locally