Skip to content

Commit ecf4e8f

Browse files
committed
Rename commands and methods to be inline with REST API names
1 parent f9d0898 commit ecf4e8f

File tree

6 files changed

+52
-50
lines changed

6 files changed

+52
-50
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust-s3"
3-
version = "0.12.1"
3+
version = "0.13.0"
44
authors = ["Drazen Urch", "Nick Stevens"]
55
description = "Tiny Rust library for working with Amazon S3."
66
repository = "https://github.com/durch/rust-s3"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ it is configured for one week which is the maximum Amazon allows ATM.
2828

2929
```
3030
[dependencies]
31-
rust-s3 = "0.12.1"
31+
rust-s3 = "0.13.0"
3232
```
3333

3434
#### Disable SSL verification for endpoints
3535
```
3636
[dependencies]
37-
rust-s3 = {version = "0.12.1", features = ["no-verify-ssl"]}
37+
rust-s3 = {version = "0.13.0", features = ["no-verify-ssl"]}
3838
```
3939

4040

src/bin/simple_crud.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ pub fn main() -> S3Result<()> {
3333

3434
// Put a "test_file" with the contents of MESSAGE at the root of the
3535
// bucket.
36-
let (_, code) = bucket.put("test_file", MESSAGE.as_bytes(), "text/plain")?;
36+
let (_, code) = bucket.put_object("test_file", MESSAGE.as_bytes(), "text/plain")?;
3737
assert_eq!(200, code);
3838

3939
// Get the "test_file" contents and make sure that the returned message
4040
// matches what we sent.
41-
let (data, code) = bucket.get("test_file")?;
41+
let (data, code) = bucket.get_object("test_file")?;
4242
let string = str::from_utf8(&data).unwrap();
4343
assert_eq!(200, code);
4444
assert_eq!(MESSAGE, string);
4545

4646
// Get bucket location
4747
println!("{:?}", bucket.location()?);
4848

49-
bucket.tag("test_file", &[("test", "tag")])?;
49+
bucket.put_object_tagging("test_file", &[("test", "tag")])?;
5050
println!("Tags set");
51-
let (tags, _status) = bucket.get_tags("test_file")?;
51+
let (tags, _status) = bucket.get_object_tagging("test_file")?;
5252
println!("{:?}", tags);
5353

5454
Ok(())

src/bucket.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ impl Bucket {
7676
/// let credentials = Credentials::default();
7777
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
7878
///
79-
/// let (data, code) = bucket.get("/test.file").unwrap();
79+
/// let (data, code) = bucket.get_object("/test.file").unwrap();
8080
/// println!("Code: {}\nData: {:?}", code, data);
8181
/// ```
82-
pub fn get(&self, path: &str) -> S3Result<(Vec<u8>, u32)> {
83-
let command = Command::Get;
82+
pub fn get_object(&self, path: &str) -> S3Result<(Vec<u8>, u32)> {
83+
let command = Command::GetObject;
8484
let request = Request::new(self, path, command);
8585
request.execute()
8686
}
@@ -105,7 +105,7 @@ impl Bucket {
105105
/// println!("{}", bucket.location().unwrap().0)
106106
/// ```
107107
pub fn location(&self) -> S3Result<(Region, u32)> {
108-
let request = Request::new(self, "?location", Command::BucketOpGet);
108+
let request = Request::new(self, "?location", Command::GetBucketLocation);
109109
let result = request.execute()?;
110110
let result_string = String::from_utf8_lossy(&result.0);
111111
let region = match serde_xml::deserialize(result_string.as_bytes()) {
@@ -137,11 +137,11 @@ impl Bucket {
137137
/// let credentials = Credentials::default();
138138
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
139139
///
140-
/// let (_, code) = bucket.delete("/test.file").unwrap();
140+
/// let (_, code) = bucket.delete_object("/test.file").unwrap();
141141
/// assert_eq!(204, code);
142142
/// ```
143-
pub fn delete(&self, path: &str) -> S3Result<(Vec<u8>, u32)> {
144-
let command = Command::Delete;
143+
pub fn delete_object(&self, path: &str) -> S3Result<(Vec<u8>, u32)> {
144+
let command = Command::DeleteObject;
145145
let request = Request::new(self, path, command);
146146
request.execute()
147147
}
@@ -164,11 +164,11 @@ impl Bucket {
164164
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
165165
///
166166
/// let content = "I want to go to S3".as_bytes();
167-
/// let (_, code) = bucket.put("/test.file", content, "text/plain").unwrap();
167+
/// let (_, code) = bucket.put_object("/test.file", content, "text/plain").unwrap();
168168
/// assert_eq!(201, code);
169169
/// ```
170-
pub fn put(&self, path: &str, content: &[u8], content_type: &str) -> S3Result<(Vec<u8>, u32)> {
171-
let command = Command::Put {
170+
pub fn put_object(&self, path: &str, content: &[u8], content_type: &str) -> S3Result<(Vec<u8>, u32)> {
171+
let command = Command::PutObject {
172172
content,
173173
content_type,
174174
};
@@ -208,12 +208,12 @@ impl Bucket {
208208
/// let credentials = Credentials::default();
209209
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
210210
///
211-
/// let (_, code) = bucket.tag("/test.file", &[("Tag1", "Value1"), ("Tag2", "Value2")]).unwrap();
211+
/// let (_, code) = bucket.put_object_tagging("/test.file", &[("Tag1", "Value1"), ("Tag2", "Value2")]).unwrap();
212212
/// assert_eq!(201, code);
213213
/// ```
214-
pub fn tag(&self, path: &str, tags: &[(&str, &str)]) -> S3Result<(Vec<u8>, u32)> {
214+
pub fn put_object_tagging(&self, path: &str, tags: &[(&str, &str)]) -> S3Result<(Vec<u8>, u32)> {
215215
let content = self._tags_xml(&tags);
216-
let command = Command::Tag {
216+
let command = Command::PutObjectTagging {
217217
tags: &content.to_string()
218218
};
219219
let request = Request::new(self, path, command);
@@ -237,15 +237,15 @@ impl Bucket {
237237
/// let credentials = Credentials::default();
238238
/// let bucket = Bucket::new(bucket_name, region, credentials).unwrap();
239239
///
240-
/// let (tags, code) = bucket.get_tags("/test.file").unwrap();
240+
/// let (tags, code) = bucket.get_object_tagging("/test.file").unwrap();
241241
/// if code == 200 {
242242
/// for tag in tags.expect("No tags found").tag_set {
243243
/// println!("{}={}", tag.key(), tag.value());
244244
/// }
245245
/// }
246246
/// ```
247-
pub fn get_tags(&self, path: &str) -> S3Result<(Option<Tagging>, u32)> {
248-
let command = Command::GetTags {};
247+
pub fn get_object_tagging(&self, path: &str) -> S3Result<(Option<Tagging>, u32)> {
248+
let command = Command::GetObjectTagging {};
249249
let request = Request::new(self, path, command);
250250
let result = request.execute()?;
251251

@@ -265,7 +265,7 @@ impl Bucket {
265265
delimiter: Option<&str>,
266266
continuation_token: Option<&str>)
267267
-> S3Result<(ListBucketResult, u32)> {
268-
let command = Command::List {
268+
let command = Command::ListBucket {
269269
prefix,
270270
delimiter,
271271
continuation_token,

src/command.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
use reqwest::Method;
22

33
pub enum Command<'a> {
4-
Put {
4+
DeleteObject,
5+
DeleteObjectTagging,
6+
GetObject,
7+
GetObjectTagging,
8+
PutObject {
59
content: &'a [u8],
610
content_type: &'a str,
711
},
8-
Tag {
12+
PutObjectTagging {
913
tags: &'a str
1014
},
11-
GetTags,
12-
Get,
13-
Delete,
14-
List {
15+
16+
ListBucket {
1517
prefix: &'a str,
1618
delimiter: Option<&'a str>,
1719
continuation_token: Option<&'a str>
1820
},
19-
BucketOpGet
21+
GetBucketLocation
2022
}
2123

2224
impl<'a> Command<'a> {
2325
pub fn http_verb(&self) -> Method {
2426
match *self {
25-
Command::Get | Command::List { .. } | Command::BucketOpGet | Command::GetTags => Method::GET,
26-
Command::Put { .. } | Command::Tag { .. } => Method::PUT,
27-
Command::Delete => Method::DELETE,
27+
Command::GetObject | Command::ListBucket { .. } | Command::GetBucketLocation | Command::GetObjectTagging => Method::GET,
28+
Command::PutObject { .. } | Command::PutObjectTagging { .. } => Method::PUT,
29+
Command::DeleteObject | Command::DeleteObjectTagging => Method::DELETE,
2830
}
2931
}
3032
}

src/request.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl<'a> Request<'a> {
5252

5353
fn url(&self) -> Url {
5454
let mut url_str = match self.command {
55-
Command::BucketOpGet => format!("{}://{}", self.bucket.scheme(), self.bucket.self_host()),
55+
Command::GetBucketLocation => format!("{}://{}", self.bucket.scheme(), self.bucket.self_host()),
5656
_ => format!("{}://{}", self.bucket.scheme(), self.bucket.host())
5757
};
5858
match self.command {
59-
Command::BucketOpGet => {}
59+
Command::GetBucketLocation => {}
6060
_ => {
6161
url_str.push_str("/");
6262
url_str.push_str(&self.bucket.name());
@@ -66,7 +66,7 @@ impl<'a> Request<'a> {
6666
url_str.push_str("/");
6767
}
6868
match self.command {
69-
Command::BucketOpGet => url_str.push_str(self.path),
69+
Command::GetBucketLocation => url_str.push_str(self.path),
7070
_ => url_str.push_str(&signing::uri_encode(self.path, false))
7171
};
7272

@@ -78,7 +78,7 @@ impl<'a> Request<'a> {
7878
url.query_pairs_mut().append_pair(key, value);
7979
}
8080

81-
if let Command::List { prefix, delimiter, continuation_token } = self.command {
81+
if let Command::ListBucket { prefix, delimiter, continuation_token } = self.command {
8282
let mut query_pairs = url.query_pairs_mut();
8383
delimiter.map(|d| query_pairs.append_pair("delimiter", d));
8484
query_pairs.append_pair("prefix", prefix);
@@ -89,7 +89,7 @@ impl<'a> Request<'a> {
8989
}
9090

9191
match self.command {
92-
Command::Tag { .. } | Command::GetTags => {
92+
Command::PutObjectTagging { .. } | Command::GetObjectTagging | Command::DeleteObjectTagging => {
9393
url.query_pairs_mut().append_pair("tagging", "");
9494
},
9595
_ => {}
@@ -101,27 +101,27 @@ impl<'a> Request<'a> {
101101

102102
fn content_length(&self) -> usize {
103103
match self.command {
104-
Command::Put { content, .. } => content.len(),
105-
Command::Tag { tags } => tags.len(),
104+
Command::PutObject { content, .. } => content.len(),
105+
Command::PutObjectTagging { tags } => tags.len(),
106106
_ => 0,
107107
}
108108
}
109109

110110
fn content_type(&self) -> String {
111111
match self.command {
112-
Command::Put { content_type, .. } => content_type.into(),
112+
Command::PutObject { content_type, .. } => content_type.into(),
113113
_ => "text/plain".into(),
114114
}
115115
}
116116

117117
fn sha256(&self) -> String {
118118
match self.command {
119-
Command::Put { content, .. } => {
119+
Command::PutObject { content, .. } => {
120120
let mut sha = Sha256::default();
121121
sha.input(content);
122122
sha.result().as_slice().to_hex()
123123
},
124-
Command::Tag { tags } => {
124+
Command::PutObjectTagging { tags } => {
125125
let mut sha = Sha256::default();
126126
sha.input(tags.as_bytes());
127127
sha.result().as_slice().to_hex()
@@ -185,7 +185,7 @@ impl<'a> Request<'a> {
185185
.map(|(k, v)| Ok((k.parse::<HeaderName>()?, v.parse::<HeaderValue>()?)))
186186
.collect::<Result<HeaderMap, S3Error>>()?;
187187
match self.command {
188-
Command::BucketOpGet => headers.insert(header::HOST, self.bucket.self_host().parse()?),
188+
Command::GetBucketLocation => headers.insert(header::HOST, self.bucket.self_host().parse()?),
189189
_ => headers.insert(header::HOST, self.bucket.host().parse()?)
190190
};
191191
headers.insert(
@@ -200,7 +200,7 @@ impl<'a> Request<'a> {
200200
headers.insert("X-Amz-Security-Token", token.parse()?);
201201
}
202202

203-
if let Command::Tag { tags } = self.command {
203+
if let Command::PutObjectTagging { tags } = self.command {
204204
let digest = md5::compute(tags);
205205
let hash = base64::encode(digest.as_ref());
206206
headers.insert("Content-MD5", hash.parse()?);
@@ -236,9 +236,9 @@ impl<'a> Request<'a> {
236236
let headers = self.headers()?;
237237

238238
// Get owned content to pass to reqwest
239-
let content = if let Command::Put { content, .. } = self.command {
239+
let content = if let Command::PutObject { content, .. } = self.command {
240240
Vec::from(content)
241-
} else if let Command::Tag { tags } = self.command {
241+
} else if let Command::PutObjectTagging { tags } = self.command {
242242
Vec::from(tags)
243243
} else {
244244
Vec::new()
@@ -290,7 +290,7 @@ mod tests {
290290
let region = "custom-region".parse()?;
291291
let bucket = Bucket::new("my-first-bucket", region, fake_credentials())?;
292292
let path = "/my-first/path";
293-
let request = Request::new(&bucket, path, Command::Get);
293+
let request = Request::new(&bucket, path, Command::GetObject);
294294

295295
assert_eq!(request.url().scheme(), "https");
296296

@@ -306,7 +306,7 @@ mod tests {
306306
let region = "http://custom-region".parse()?;
307307
let bucket = Bucket::new("my-second-bucket", region, fake_credentials())?;
308308
let path = "/my-second/path";
309-
let request = Request::new(&bucket, path, Command::Get);
309+
let request = Request::new(&bucket, path, Command::GetObject);
310310

311311
assert_eq!(request.url().scheme(), "http");
312312

0 commit comments

Comments
 (0)