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
use hyper;
use serde;
use Error;
use IntoDatabasePath;
use IntoDocumentPath;
use IntoViewPath;
use Revision;
use action;
pub trait IntoUrl: hyper::client::IntoUrl {}
impl<T: hyper::client::IntoUrl> IntoUrl for T {}
pub struct ClientState {
pub http_client: hyper::Client,
pub uri: hyper::Url,
}
impl ClientState {
pub fn new<U: IntoUrl>(uri: U) -> Result<Self, Error> {
let client_state = ClientState {
http_client: hyper::Client::new(),
uri: try!(uri.into_url()
.or_else(|e| Err(Error::UriParse { cause: e }))),
};
Ok(client_state)
}
}
pub struct Client {
state: ClientState,
}
impl<'a> Client {
pub fn new<U: IntoUrl>(uri: U) -> Result<Self, Error> {
let client = Client { state: try!(ClientState::new(uri)) };
Ok(client)
}
pub fn uri(&self) -> &hyper::Url {
&self.state.uri
}
pub fn get_root(&'a self) -> action::GetRoot<'a> {
action::GetRoot::new(&self.state)
}
pub fn get_all_databases(&'a self) -> action::GetAllDatabases<'a> {
action::GetAllDatabases::new(&self.state)
}
pub fn head_database<P: IntoDatabasePath>(&'a self, path: P) -> action::HeadDatabase<'a, P> {
action::HeadDatabase::new(&self.state, path)
}
pub fn get_database<P: IntoDatabasePath>(&'a self, path: P) -> action::GetDatabase<'a, P> {
action::GetDatabase::new(&self.state, path)
}
pub fn put_database<P: IntoDatabasePath>(&'a self, path: P) -> action::PutDatabase<'a, P> {
action::PutDatabase::new(&self.state, path)
}
pub fn delete_database<P: IntoDatabasePath>(&'a self,
path: P)
-> action::DeleteDatabase<'a, P> {
action::DeleteDatabase::new(&self.state, path)
}
pub fn post_database<P: IntoDatabasePath, T: serde::Serialize>
(&'a self,
path: P,
doc_content: &'a T)
-> action::PostDatabase<'a, P, T> {
action::PostDatabase::new(&self.state, path, doc_content)
}
#[doc(hidden)]
pub fn post_to_database<P: IntoDatabasePath, T: serde::Serialize>
(&'a self,
path: P,
doc_content: &'a T)
-> action::PostDatabase<'a, P, T> {
action::PostDatabase::new(&self.state, path, doc_content)
}
pub fn get_changes<P>(&'a self, path: P) -> action::GetChanges<'a, P>
where P: IntoDatabasePath
{
action::GetChanges::new(&self.state, path)
}
pub fn head_document<P: IntoDocumentPath>(&'a self, path: P) -> action::HeadDocument<'a, P> {
action::HeadDocument::new(&self.state, path)
}
pub fn get_document<P: IntoDocumentPath>(&'a self, path: P) -> action::GetDocument<'a, P> {
action::GetDocument::new(&self.state, path)
}
pub fn put_document<P: IntoDocumentPath, T: serde::Serialize>
(&'a self,
path: P,
doc_content: &'a T)
-> action::PutDocument<'a, P, T> {
action::PutDocument::new(&self.state, path, doc_content)
}
pub fn delete_document<P: IntoDocumentPath>(&'a self,
path: P,
rev: &'a Revision)
-> action::DeleteDocument<'a, P> {
action::DeleteDocument::new(&self.state, path, rev)
}
pub fn get_view<P: IntoViewPath,
K: serde::Deserialize + serde::Serialize,
V: serde::Deserialize>
(&'a self,
path: P)
-> action::GetView<'a, P, K, V> {
action::GetView::new(&self.state, path)
}
}