Skip to content

Commit e79996b

Browse files
committed
Getting started
1 parent 0a8c73a commit e79996b

File tree

2 files changed

+116
-54
lines changed

2 files changed

+116
-54
lines changed

source/index.md

Lines changed: 115 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
---
2-
title: API Reference
2+
title: Koken API Reference
33

44
language_tabs:
55
- shell
6-
- ruby
7-
- python
8-
9-
toc_footers:
10-
- <a href='#'>Sign Up for a Developer Key</a>
11-
- <a href='http://github.com/tripit/slate'>Documentation Powered by Slate</a>
126

137
includes:
148
- errors
@@ -18,67 +12,120 @@ search: true
1812

1913
# Introduction
2014

21-
Welcome to the Kittn API! You can use our API to access Kittn API endpoints, which can get information on various cats, kittens, and breeds in our database.
15+
Every installation of Koken exposes an API that can be used to read and write data from that install.
2216

23-
We have language bindings in Shell, Ruby, and Python! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.
17+
To make a request to the API, you will need the install's API path, which is the domain and path to the Koken installation. For the rest of this document, we'll assume that the API path is:
2418

25-
This example API documentation page was created with [Slate](http://github.com/tripit/slate). Feel free to edit it and use it as a base for your own API's documentation.
19+
`http://myphotosite.com/koken`
2620

27-
# Authentication
21+
# Making a request
2822

29-
> To authorize, use this code:
23+
```shell
24+
curl http://myphotosite.com/koken/api.php?/content
25+
```
3026

31-
```ruby
32-
require 'kittn'
27+
To make a request, you will need to form the URL to the endpoint using the supplied API path and the endpoint you are wishing to access. To determine the URL to call, think of this psuedo code:
3328

34-
api = Kittn::APIClient.authorize!('meowmeowmeow')
29+
`API Path + 'api.php?' + endpoint`
30+
31+
For example, to call the `/content` endpoint, the full URL would be:
32+
33+
`http://myphotosite.com/koken/api.php?/content`
34+
35+
# Response format
36+
37+
```shell
38+
curl -H "Accept: application/json" http://myphotosite.com/koken/api.php?/content
3539
```
3640

37-
```python
38-
import 'kittn'
41+
Currently, all Koken API responses return data as JSON. For future proofing, we recommend explicitly passing the `Accept` header.
3942

40-
api = Kittn.authorize('meowmeowmeow')
43+
# Errors
44+
45+
> Accessing an image that does not exist
46+
47+
```shell
48+
curl -i -H "Accepts: application/json" http://koken.dev:8888/api.php?/content/2222
49+
50+
HTTP/1.1 404 Not Found
51+
Server: Apache/2.4.7 (Ubuntu)
52+
Content-Length: 95
53+
Content-Type: application/json
54+
55+
{
56+
"request": "/api.php?/content/2222",
57+
"error": "Content with ID: 2222 not found.",
58+
"http": "404"
59+
}
4160
```
4261

62+
When the Koken API encounters an error, it returns an appropriate HTTP error code as well as a JSON payload with more information about the error.
63+
64+
# Authentication
65+
66+
> To authorize, send the token in a custom HTTP header:
67+
4368
```shell
44-
# With shell, you can just pass the correct header with each request
45-
curl "api_endpoint_here"
46-
-H "Authorization: meowmeowmeow"
69+
curl -H "Accepts: application/json" \
70+
-H "X-Koken-Token: your-token-here" \
71+
http://myphotosite.com/koken/api.php?/content
4772
```
4873

49-
> Make sure to replace `meowmeowmeow` with your API key.
74+
To read public data from a Koken install, authorization is not required. To read unlisted or private information, or to make modifications to content via the API, authorization is required via *tokens*. There are two levels of token permissions:
5075

51-
Kittn uses API keys to allow access to the API. You can register a new Kittn API key at our [developer portal](http://example.com/developers).
76+
Permissions | Description
77+
--------- | -----------
78+
read | Access to all public, unlisted and private content, albums and essays.
79+
read-write | Same permissions as read but also with permission to create and delete.
5280

53-
Kittn expects for the API key to be included in all API requests to the server in a header that looks like the following:
81+
The user of the install will need to generate and supply your application with the appropriate token by logging in to their Koken install and visiting `Settings > Applications`.
5482

55-
`Authorization: meowmeowmeow`
83+
# Pagination
5684

57-
<aside class="notice">
58-
You must replace `meowmeowmeow` with your personal API key.
59-
</aside>
85+
> Example JSON info included in list responses:
6086
61-
# Kittens
87+
```json
88+
{
89+
"page": 1,
90+
"pages": 4,
91+
"per_page": 10,
92+
"albums": [
6293

63-
## Get All Kittens
94+
]
95+
}
96+
```
97+
> Get the next page
6498
65-
```ruby
66-
require 'kittn'
99+
```shell
100+
curl -H "Accepts: application/json" \
101+
http://myphotosite.com/koken/api.php?/albums/page:2/limit:10
102+
```
67103

68-
api = Kittn::APIClient.authorize!('meowmeowmeow')
69-
api.kittens.get
104+
Any API endpoint that returns a list will also return information that can be used to paginate over that list.
105+
106+
# Parameters
107+
108+
```shell
109+
curl -H "Accepts: application/json" \
110+
http://myphotosite.com/koken/api.php?/albums/order_by:published_on/order_direction:desc
70111
```
71112

72-
```python
73-
import 'kittn'
113+
Because Koken's entire endpoint is contained in the query string, parameters are passed as key/value pairs in the URL itself. All parameters should be placed at the end of the API URL.
74114

75-
api = Kittn.authorize('meowmeowmeow')
76-
api.kittens.get()
115+
> Boolean parameters should be passed as a 0 (for false) or 1 (for true);
116+
117+
```shell
118+
curl -H "Accepts: application/json" \
119+
http://myphotosite.com/koken/api.php?/albums/include_empty:0
77120
```
78121

122+
# Albums
123+
124+
## Get all albums
125+
79126
```shell
80-
curl "http://example.com/api/kittens"
81-
-H "Authorization: meowmeowmeow"
127+
curl -H "Accepts: application/json" \
128+
http://myphotosite.com/koken/api.php?/albums
82129
```
83130

84131
> The above command returns JSON structured like this:
@@ -102,24 +149,39 @@ curl "http://example.com/api/kittens"
102149
]
103150
```
104151

105-
This endpoint retrieves all kittens.
152+
Without authentication, this endpoint retrieves all public albums. When authenticated, unlisted albums are also returned.
106153

107-
### HTTP Request
154+
### Endpoint
108155

109-
`GET http://example.com/kittens`
156+
`GET /albums`
110157

111158
### Query Parameters
112159

113-
Parameter | Default | Description
114-
--------- | ------- | -----------
115-
include_cats | false | If set to true, the result will also include cats.
116-
available | true | If set to false, the result will include kittens that have already been adopted.
117-
118-
<aside class="success">
119-
Remember — a happy kitten is an authenticated kitten!
120-
</aside>
121-
122-
## Get a Specific Kitten
160+
Parameter | Default | Description | Valid values
161+
--------- | ------- | ----------- | ------------
162+
day | false | Return albums from a particular day. Requires a valid year and month parameter. | Any valid day. ex: 1
163+
day_not | false | Return albums from all buy one particular day. Requires a valid year and month parameter. | Any valid day. ex: 1
164+
flat | false | Return all albums in the list, regardless of their hierachacal level. | true or false
165+
id_not | false | Exclude albums from the list by id. | Any album ID. Exclude multiple IDs using a comma. Ex: 1,2
166+
include_empty | true | If false, albums containing no content are omitted from the results. | true or false
167+
limit | false | Limit the number of albums to return per page of results. | Any number greater than zero.
168+
listed | true | If false, unlisted albums are retured as well. Requires authorization. | true or false
169+
match_all_tags | false | When using tags or tags_not, whether to look for all of the supplied tags. | true or false
170+
month | false | Return albums from a particular month. Requires a valid year parameter. | Any valid month. ex: 1
171+
month_not | false | Return albums from all buy one particular month. Requires a valid year parameter. | Any valid month. ex: 1
172+
order_by | title | What data is used to sort the returned list. | title, published_on, modified_on, created_on
173+
order_direction | ASC | Whether to sort in ASC or DESC order. | ASC or DESC
174+
page | 1 | See pagination. | Any number from 1 to total_pages.
175+
search | false | String to search by. Search is performed on the album's title, description and tag fields unless search_filter is defined. | Any string
176+
search_filter | false | Limit the fields used in the search. | title, description or tags
177+
tags | false | Search for albums with specific tags. | Any string. Separate multiple tags with a comma.
178+
tags_not | false | Search for albums without specific tags. | Any string. Separate multiple tags with a comma.
179+
types | all | Return only sets or standard albums. | all, set or standard
180+
with_covers | true | Whether or not to return cover data with each album | true or false
181+
year | false | Return albums from a particular year. | Any valid year. ex: 2014
182+
year_not | false | Return albums from all buy one particular year. | Any valid year. ex: 2014
183+
184+
## Get a specific album
123185

124186
```ruby
125187
require 'kittn'

source/stylesheets/variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ $lang-select-pressed-text: #fff; // color of language tab text when mouse is pre
5353
// SIZES
5454
////////////////////
5555
$nav-width: 230px; // width of the navbar
56-
$examples-width: 50%; // portion of the screen taken up by code examples
56+
$examples-width: 40%; // portion of the screen taken up by code examples
5757
$logo-margin: 20px; // margin between nav items and logo, ignored if search is active
5858
$main-padding: 28px; // padding to left and right of content & examples
5959
$nav-padding: 15px; // padding to left and right of navbar

0 commit comments

Comments
 (0)