-
Notifications
You must be signed in to change notification settings - Fork 2
Friend relations API
Jack Zhao edited this page Apr 7, 2019
·
5 revisions
/author/{author_id}/friends
/friendrequest
/author/{author1_id}/friends/{author2_id}
Endpoint: /author/{author_id}/friends
Request
/author/{author_id}/friends:
get:
summary: Get friend list of a author
tags:
- friend
parameters:
- name: author_id
in: path
description: Author ID
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: friends
authors:
type: array
items:
type: string
example:
[
"http://host3/author/de305d54-75b4-431b-adb2-eb6b9e546013",
"http://host2/author/ae345d54-75b4-431b-adb2-fb6b9e547891",
]
post:
summary: Ask a service if anyone in the list is a friend
tags:
- friend
parameters:
- name: author_id
in: path
description: Author ID
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: 'friends'
author:
type: string
example: author_id
authors:
type: array
items:
type: string
example: ['http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013', 'http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891']
responses:
'200':
$ref: '#/components/responses/IfFriendsResponse'
Response
IfFriendsResponse:
description: OK
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: 'friends'
author:
type: string
example: author_id
authors:
type: array
items:
type: string
example: ['http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013', 'http://127.0.0.1:5454/author/ae345d54-75b4-431b-adb2-fb6b9e547891']
Example GET
GET
/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b/friends
HTTP 200 OK
Allow: GET, POST, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"query": "friends",
"authors": [
"97a2c5a6-5079-4454-a6bf-de217ac07f3c",
"1820ef5b-dac0-44d5-8572-68fb89e39771",
"902f61fd-9513-49cf-9722-17d40230976d"
]
}
Example POST
POST
/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b/friends
REQUEST:
{
"query": "friends",
"author": "7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"authors":["902f61fd-9513-49cf-9722-17d40230976d"]
}
RESPONSE:
{
"query": "friends",
"author": "7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"authors":["902f61fd-9513-49cf-9722-17d40230976d"]
}
Endpoint: /friendrequest
Request
/friendrequest:
post:
summary: Make a friend request
tags:
- friend
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: 'friendrequest'
author:
type: object
properties:
id:
type: string
example: 'http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013'
host:
type: string
example: 'http://127.0.0.1:5454'
displayName:
type: string
example: 'Greg Johnson'
url:
type: string
example: 'http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e546013'
friend:
type: object
properties:
id:
type: string
example: 'http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281'
host:
type: string
example: 'http://127.0.0.1:5454'
displayName:
type: string
example: 'Lara Croft'
url:
type: string
example: 'http://127.0.0.1:5454/author/de305d54-75b4-431b-adb2-eb6b9e637281'
get: (This is not in spec. We implement this by our own use.)
summary: Get number of friend requests that are not respond by current user
tags:
- friends
Response
MakeFriendRequestResponse:
description: Make friend request response
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: 'friendrequest'
success:
type: boolean
message:
type: string
example: 'Friend request sent'
GetFriendRequestResponse:
description: Get number of friend requests that are not respond by current user
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: 'friendrequest_count'
counts:
type: integer
example: '0'
Example POST
POST
/friendrequest (*Include Authorization header with user:password")
REQUEST:
{
"author":{
"id": "5267fe13-a757-4c94-896d-1e552257e32d",
"host": "http://socialdist2.herokuapp.com",
"displayName": "User From Remote 1",
"url": "http://socialdist2.herokuapp.com/author/5267fe13-a757-4c94-896d-1e552257e32d"
},
"friend":{
"id": "7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"host": "http://conet-socialdistribution.herokuapp.com",
"displayName": "Andoryu",
"url": "http://conet-socialdistribution.herokuapp.com/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b"
}
}
RESPONSE:
{
"query": "friendrequest",
"message": "Your friend request is sent successfully.",
"success": true
}
Example GET(Not a requirement of specs.)
GET
/friendrequest (*Include Authorization header with user:password")
RESPONSE:
{
"query": "friendrequest_count",
"counts":0
}
Request
/author/{author1_id}/friends/{author2_id}:
get:
summary: Ask if 2 authors are friends
description: |
STRIP the `http://` and `https://` from the URI in the restful query
If you need a template (optional): `GET http://service/author/<authorid1>/friends/<service2>/author/<authorid2>`
where `authorid1` = `de305d54-75b4-431b-adb2-eb6b9e546013` (actually `author` `http://service/author/de305d54-75b4-431b-adb2-eb6b9e546013` )
where `authorid2` =
`GET http://service/author/de305d54-75b4-431b-adb2-eb6b9e546013/friends/127.0.0.1%3A5454%2Fauthor%2Fae345d54-75b4-431b-adb2-fb6b9e547891`
Please escape / of IDs with %2F e.g. urllib.parse.quote( "http://service/author/whatever" , safe='~()*!.\'')
tags:
- friend
parameters:
- name: author1_id
in: path
description: Author ID
required: true
schema:
type: string
- name: author2_id
in: path
description: Author ID
required: true
schema:
type: string
Response
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
query:
type: string
example: friends
friends:
type: boolean
example: true
authors:
type: array
items:
type: string
example:
[
"http://host3/author/de305d54-75b4-431b-adb2-eb6b9e546013",
"http://host2/author/ae345d54-75b4-431b-adb2-fb6b9e547891",
]
Example GET
GET
author/7afa94d2-0e2f-41b4-947e-7fa46a91375b/friends/902f61fd-9513-49cf-9722-17d40230976d
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"query": "friends",
"friends": true,
"authors": [
"http://conet-socialdistribution.herokuapp.com/author/7afa94d2-0e2f-41b4-947e-7fa46a91375b",
"https://myblog-cool.herokuapp.com/author/902f61fd-9513-49cf-9722-17d40230976d"
]
}