yq: YuQue API Client

Description Usage Arguments Value Source See Also Examples

View source: R/yq.R

Description

Tool to access YuQue.

This is an extremely minimal client. You need to know the API to be able to use this client. All this function does is:

Usage

1
2
3
yq(endpoint, ..., .token = NULL, .destfile = NULL,
  .overwrite = FALSE, .api_url = NULL, .method = "GET",
  .send_headers = NULL)

Arguments

endpoint

YuQue API endpoint. Must be one of the following forms:

  • "METHOD path", e.g. "GET /users/shixiangwang"

  • "path", e.g. "/users/shixiangwang".

  • "METHOD url", e.g. "GET https://www.yuque.com/api/v2/users/shixiangwang"

  • "url", e.g. "https://www.yuque.com/api/v2/users/shixiangwang".

If the method is not supplied, will use .method, which defaults to GET.

...

Name-value pairs giving API parameters. Will be matched into url placeholders, sent as query parameters in GET requests, and in the JSON body of POST requests.

.token

Authentication token. Default to YUQUE_TOKEN environment variables, in this order if any is set.

.destfile

path to write response to disk. If NULL (default), response will be processed and returned as an object. If path is given, response will be written to disk in the form sent.

.overwrite

if destfile is provided, whether to overwrite an existing file. Defaults to FALSE.

.api_url

YuQue API url (default: https://www.yuque.com/api/v2). Used if endpoint just contains a path. Default to YuQue_API_URL environment variable if set.

.method

HTTP method to use if not explicitly supplied in the endpoint.

.send_headers

Named character vector of header field values (excepting Authorization, which is handled via .token). This can be used to override or augment the defaults, which are as follows: the Accept field defaults to "application/json" and the User-Agent field defaults to "https://github.com/ShixiangWang/yq". This can be used to, e.g., provide a custom media type, in order to access a preview feature of the API.

Value

A response object from httr package, which is also a list.

Source

https://www.yuque.com/

See Also

yq_whoami() for details on YuQue API token management.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# For more details, please read API of 'YuQue'
# <https://www.yuque.com/yuque/developer>

# User -----------------------------------------
## Information for a user
yq("/users/shixiangwang")
yq("/users/shixiangwang") %>% headers()     # Obtain headers
yq("/users/shixiangwang") %>% status_code() # Obtain status
yq("/users/shixiangwang") %>% content()     # Obtain response
## Information for the current authenticated user
yq("/user")

# Group -----------------------------------------
## List groups of a user
yq("/users/shixiangwang/groups")
## Information for a group
## Just treat it like a user
yq("/groups/elegant-r")

# Repo -------------------------------------------
## List repo of a user or group
yq("/users/shixiangwang/repos")
yq("/users/elegant-r/repos")
## Information for a repo
yq("/repos/shixiangwang/tools")

# Doc --------------------------------------------
## List documents of a repo
yq("/repos/shixiangwang/tools/docs")
## Information of a document
## Not run: 
yq("/repos/elegant-r/zfc8ub/docs/krle92")

## End(Not run)

ShixiangWang/yq documentation built on Oct. 30, 2019, 11:57 p.m.