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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Import the crate. You need the #[macro_use] or none of this will work.
// Needs to be in the crate root
extern crate foundation;
// Bring crates used into scope, use only in the crate root. Not fun part this
// will tie you to specific versions of the crates. Since we reexport stuff from
// them as part of the public API. This is cleaner than importing the huge
// amount of types yourself.
use *;
// Use this anywhere there are macros being used from foundation
use *;
// We'll need this in the code below. It's not required for foundation
extern crate serde_json;
use Value;
// Name of your client type
// A string that points to the API
// A closure that takes the below parameters (one being the name of your client
// type), that allows you to manipulate the `Request` type from Hyper. Perfect
// for setting up required headers or handling a given token value for all
// requests that are made to the API. It shouldn't return a value.
client!;
// Function used for deserialiation using this signature header. Can have
// multiple of these functions if needed (i.e. one for XML, another for JSON,
// or one for MsgPack)
// Define new types, where a type represents a part of the URL. If this part
// of the URL built up can execute a request give it a path to your
// deserialization function in order for it to work when executed.
// You can specify a type that doesn't represent a valid query, but part of
// a URL with something like this:
// new_type!(
// NotDeserializableType;
// User => string_from_bytes;
// Users => string_from_bytes;
// UsersUsername => string_from_bytes;
// )
// as part of the list.
new_type!;
// Here's where you wire everything up between the types. We know what can
// deserialize and what's just a type, but not how to go from one part of the
// URL to the other. You have a few different ways to do this. First thing is
// you name what type you want to make go to another by naming it like so:
//
// MyType {
//
// };
//
// Inside of it you can put two different types of fields:
// 1) parameter_transition
// 2) transition
//
// parameter_transition when utilized looks like this:
//
// MyType {
// parameter_transition {
// (MyType2, my_type_two, type_str)
// (MyType3, my_type_three, type_str)
// }
// };
//
// It takes a list of tuples. The first value is the type you want to go to,
// the second value is the name of the function used to make the transition,
// and the third value is the name of the parameter in the function, that shows
// up in the documentation you can generate.
//
// The transition field when utilized looks like this:
//
// MyType {
// transition {
// (MyType2, ty_two)
// (MyType3, ty_three)
// }
// };
//
// It takes a list of tuples. The first value is the type you want to go to,
// the second value is the name of the function used to make the transition and
// the string used for the URL. So if you were at https://mysite.com/ and you
// called ty_two while building up the query it becomes
// https://mysite.com/ty_two used for the URL.
//
// You can also use both together! The transition field comes before the
// parameter_transition field
// MyType {
// transition {
// (MyType2, ty_two)
// (MyType3, ty_three)
// }
//
// parameter_transition {
// (MyType4, my_type_four, type_str)
// (MyType5, my_type_five, type_str)
// }
// };
//
// You can now repeat the above pattern for every type you need. By default
// in the file you call `client!()` you get a Get, Post, Put, Patch, and Delete
// type that can be wired up to other types. You'll need to wire these up to
// whatever other types you need to or else you'll never be able to make a
// query!
make_connections!;