-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiary.apib
162 lines (110 loc) · 3.91 KB
/
apiary.apib
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
FORMAT: 1A
HOST: http://polls.apiblueprint.org/
# Karma/Rewards Microservice
Overview
--------
This is the repo for the Karhoo **Karma** system. As a microservice, this system functions seperately from core, and is passed information needed through post requests.
As needed, it can return:
- **Karma** earned from a transaction, based on the total cost of the transaction and the users tier in the system.
- Deduction to make from a transaction, based on the total cost of the transaction.
- New total usable **Karma**, based on an amount of **Karma** to add to a user.
- **Karma** earned on a trip.
- **Karma** a user has available to use.
For more information go to the consumer [FAQ](https://docs.google.com/document/d/1fSS13QD2uwF6YQkyK0E4nTndHcyZMrAkbPlJx-RHtAk)
Getting Started - Development
-----------------------------
Create a docker machine
docker-machine create rewards --driver virtualbox
eval $(docker-machine env rewards)
Get IP of Docker Machine, this will be used when interacting with API.
docker-machine ip rewards
Use Docker to start the API
docker-compose run initdb
docker-compose up api
(Optional) Set port forwarding on 8000 and 3306 from virtualbox for the dockermachine.
Example Usage
-------------
Some sample client functions are in the examples directory of this repo. These examples
are simple wrappers for the post requests and show how integration could work.
If port forwarding wasn't set through virtual box, set the host in the examples.py
```python
from examples import RewardsClient
client = RewardsClient()
earned_points = client.earn_points('tripid', 'userid', 50.25, 'USD')
# earned_points is equal to 101, the amount of points earned by a trip of 50.25 USD
```
## Points Collection [/rewards/points/{user_id}]
+ Parameters
+ user_id: testuser (required) - Unique identifier for a user
### Get Usable Points [GET]
+ Response 200 (application/json)
2000
### Add Usable Points [POST]
+ Request (application/json)
{
"event_id": "4",
"points": "500"
}
+ Response 200 (application/json)
2500
## Earn Points [/rewards/earn_points/{user_id}]
+ Parameters
+ user_id: testuser (required) - Unique identifier for a user
### Get Earned Points [GET]
+ Response 200 (application/json)
2000
### Add Earned Points [POST]
+ Request (application/json)
{
"trip_id": "trip1",
"total": "40.53",
"currency": "USD"
}
+ Response 200 (application/json)
81
## Use Points [/rewards/use_points/{user_id}]
+ Parameters
+ user_id: testuser (required) - Unique identifier for a user
### Use Points [POST]
+ Request (application/json)
{
"trip_id": "trip1",
"subtotal": "40.53",
"currency": "USD"
}
+ Response 200 (application/json)
4.10
## Trip Points [/rewards/trip_points/{trip_id}]
+ Parameters
+ trip_id: testuser (required) - Unique identifier for a trip
### Get Points Earned From Trip [GET]
+ Response 200 (application/json)
{
"used": 0,
"earned": 0
}
## User History [/rewards/history/{user_id}]
+ Parameters
+ user_id: testuser (required) - Unique identifier for a user
### Get User's History [GET]
+ Response 200 (application/json)
{
"1": {
"points_prior": "0",
"event_id": "4",
"timestamp": "2016-08-17 15:21:23",
"trip_id": "None",
"user_id": "1",
"id": "1",
"points_after": "200"
},
"2": {
"points_prior": "200",
"event_id": "4",
"timestamp": "2016-08-17 15:22:55",
"trip_id": "None",
"user_id": "1",
"id": "2",
"points_after": "400"
}
}