Skip to content

Commit 8dde633

Browse files
committed
v5.0.0
1 parent 8b36a5c commit 8dde633

File tree

4 files changed

+182
-182
lines changed

4 files changed

+182
-182
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Changelog
22

3-
## v4.3.0
3+
## v5.0.0 - 2025-09-19
44

5-
- Added `get_repository_versions_data`, `get_package_data`,
5+
- Functions renamed to make it more clear if the JSON API is used or if the
6+
repository endpoints are used.
7+
- Added `repository_v2_package_parse_body`, and `repository_v2_get_versions_body`,
68

79
## v4.2.0 - 2025-08-27
810

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hexpm"
3-
version = "4.2.0"
3+
version = "5.0.0"
44
authors = ["Louis Pilfold <[email protected]>"]
55
edition = "2024"
66

src/lib.rs

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn make_request(
9999
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.ex#L137
100100
///
101101
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/key.ex#L6
102-
pub fn create_api_key_request(
102+
pub fn api_create_api_key_request(
103103
username: &str,
104104
password: &str,
105105
key_name: &str,
@@ -121,7 +121,7 @@ pub fn create_api_key_request(
121121
}
122122

123123
/// Parses a request that creates a Hex API key.
124-
pub fn create_api_key_response(response: http::Response<Vec<u8>>) -> Result<String, ApiError> {
124+
pub fn api_create_api_key_response(response: http::Response<Vec<u8>>) -> Result<String, ApiError> {
125125
#[derive(Deserialize)]
126126
struct Resp {
127127
secret: String,
@@ -142,7 +142,7 @@ pub fn create_api_key_response(response: http::Response<Vec<u8>>) -> Result<Stri
142142
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.user.ex#L291
143143
///
144144
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/key.ex#L15
145-
pub fn remove_api_key_request(
145+
pub fn api_remove_api_key_request(
146146
name_of_key_to_delete: &str,
147147
api_key: &str,
148148
config: &Config,
@@ -158,7 +158,7 @@ pub fn remove_api_key_request(
158158
}
159159

160160
/// Parses a request that deleted a Hex API key.
161-
pub fn remove_api_key_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
161+
pub fn api_remove_api_key_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
162162
let (parts, body) = response.into_parts();
163163
match parts.status {
164164
StatusCode::NO_CONTENT | StatusCode::OK => Ok(()),
@@ -175,7 +175,7 @@ pub fn remove_api_key_response(response: http::Response<Vec<u8>>) -> Result<(),
175175
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.retire.ex#L75
176176
///
177177
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release.ex#L28
178-
pub fn retire_release_request(
178+
pub fn api_retire_release_request(
179179
package: &str,
180180
version: &str,
181181
reason: RetirementReason,
@@ -198,7 +198,7 @@ pub fn retire_release_request(
198198
}
199199

200200
/// Parses a request that retired a release.
201-
pub fn retire_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
201+
pub fn api_retire_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
202202
let (parts, body) = response.into_parts();
203203
match parts.status {
204204
StatusCode::NO_CONTENT | StatusCode::OK => Ok(()),
@@ -215,7 +215,7 @@ pub fn retire_release_response(response: http::Response<Vec<u8>>) -> Result<(),
215215
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.retire.ex#L89
216216
///
217217
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release.ex#L35
218-
pub fn unretire_release_request(
218+
pub fn api_unretire_release_request(
219219
package: &str,
220220
version: &str,
221221
api_key: &str,
@@ -232,7 +232,7 @@ pub fn unretire_release_request(
232232
}
233233

234234
/// Parses a request that un-retired a package version.
235-
pub fn unretire_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
235+
pub fn api_unretire_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
236236
let (parts, body) = response.into_parts();
237237
match parts.status {
238238
StatusCode::NO_CONTENT | StatusCode::OK => Ok(()),
@@ -245,15 +245,10 @@ pub fn unretire_release_response(response: http::Response<Vec<u8>>) -> Result<()
245245
/// Create a request that get the names and versions of all of the packages on
246246
/// the package registry.
247247
///
248-
/// Uses the registry v2 API.
249-
/// Responses use gz encoding and are wrapped in a signing message.
250-
/// For direct usage of response see below:
251-
///
252248
/// https://github.com/hexpm/specifications/blob/main/registry-v2.md
253-
/// Recommended sections: (#registry-files, #signing, #decoding-registry-files)
254249
///
255250
/// TODO: Where are the API docs for this?
256-
pub fn get_repository_versions_request(
251+
pub fn repository_v2_get_versions_request(
257252
api_key: Option<&str>,
258253
config: &Config,
259254
) -> http::Request<Vec<u8>> {
@@ -266,7 +261,7 @@ pub fn get_repository_versions_request(
266261

267262
/// Parse a request that gets the names and versions of all of the packages on
268263
/// the package registry.
269-
pub fn get_repository_versions_response(
264+
pub fn repository_v2_get_versions_response(
270265
response: http::Response<Vec<u8>>,
271266
public_key: &[u8],
272267
) -> Result<HashMap<String, Vec<Version>>, ApiError> {
@@ -281,11 +276,11 @@ pub fn get_repository_versions_response(
281276
let mut body = Vec::new();
282277
decoder.read_to_end(&mut body)?;
283278

284-
parse_repository_v2_versions(&body, public_key)
279+
repository_v2_get_versions_body(&body, public_key)
285280
}
286281

287282
/// Parse a signed binary message containing all of the packages on the package registry.
288-
pub fn parse_repository_v2_versions(
283+
pub fn repository_v2_get_versions_body(
289284
protobuf_bytes: &Vec<u8>,
290285
public_key: &[u8],
291286
) -> Result<HashMap<String, Vec<Version>>, ApiError> {
@@ -316,19 +311,9 @@ pub fn parse_repository_v2_versions(
316311

317312
/// Create a request to get the information for a package in the repository.
318313
///
319-
/// Uses the registry v2 API.
320-
/// Responses use gz encoding and are wrapped in a signing message.
321-
/// For direct usage of response see below:
322-
///
323314
/// https://github.com/hexpm/specifications/blob/main/registry-v2.md
324-
/// Recommended sections: (#registry-files, #signing, #decoding-registry-files)
325-
///
326-
/// API Docs:
327-
///
328-
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.package.ex#L348
329315
///
330-
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/package.ex#L36
331-
pub fn get_package_request(
316+
pub fn repository_v2_get_package_request(
332317
name: &str,
333318
api_key: Option<&str>,
334319
config: &Config,
@@ -342,7 +327,7 @@ pub fn get_package_request(
342327

343328
/// Parse a response to get the information for a package in the repository.
344329
///
345-
pub fn get_package_response(
330+
pub fn repository_v2_get_package_response(
346331
response: http::Response<Vec<u8>>,
347332
public_key: &[u8],
348333
) -> Result<Package, ApiError> {
@@ -361,11 +346,11 @@ pub fn get_package_response(
361346
let mut body = Vec::new();
362347
decoder.read_to_end(&mut body)?;
363348

364-
parse_repository_v2_package(&body, public_key)
349+
repository_v2_package_parse_body(&body, public_key)
365350
}
366351

367352
/// Parse a signed binary message containing the information for a package in the repository.
368-
pub fn parse_repository_v2_package(
353+
pub fn repository_v2_package_parse_body(
369354
protobuf_bytes: &Vec<u8>,
370355
public_key: &[u8],
371356
) -> Result<Package, ApiError> {
@@ -392,7 +377,7 @@ pub fn parse_repository_v2_package(
392377

393378
/// Create a request to download a version of a package as a tarball
394379
/// TODO: Where are the API docs for this?
395-
pub fn get_package_tarball_request(
380+
pub fn repository_get_package_tarball_request(
396381
name: &str,
397382
version: &str,
398383
api_key: Option<&str>,
@@ -411,7 +396,7 @@ pub fn get_package_tarball_request(
411396

412397
/// Parse a response to download a version of a package as a tarball
413398
///
414-
pub fn get_package_tarball_response(
399+
pub fn repository_get_package_tarball_response(
415400
response: http::Response<Vec<u8>>,
416401
checksum: &[u8],
417402
) -> Result<Vec<u8>, ApiError> {
@@ -433,7 +418,7 @@ pub fn get_package_tarball_response(
433418
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.publish.ex#L384
434419
///
435420
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release_docs.ex#L19
436-
pub fn remove_docs_request(
421+
pub fn api_remove_docs_request(
437422
package_name: &str,
438423
version: &str,
439424
api_key: &str,
@@ -451,7 +436,7 @@ pub fn remove_docs_request(
451436
.expect("remove_docs_request request"))
452437
}
453438

454-
pub fn remove_docs_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
439+
pub fn api_remove_docs_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
455440
let (parts, body) = response.into_parts();
456441
match parts.status {
457442
StatusCode::NO_CONTENT => Ok(()),
@@ -468,7 +453,7 @@ pub fn remove_docs_response(response: http::Response<Vec<u8>>) -> Result<(), Api
468453
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.publish.ex#L429
469454
///
470455
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release_docs.ex#L11
471-
pub fn publish_docs_request(
456+
pub fn api_publish_docs_request(
472457
package_name: &str,
473458
version: &str,
474459
gzipped_tarball: Vec<u8>,
@@ -489,7 +474,7 @@ pub fn publish_docs_request(
489474
.expect("publish_docs_request request"))
490475
}
491476

492-
pub fn publish_docs_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
477+
pub fn api_publish_docs_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
493478
let (parts, body) = response.into_parts();
494479
match parts.status {
495480
StatusCode::CREATED => Ok(()),
@@ -506,7 +491,7 @@ pub fn publish_docs_response(response: http::Response<Vec<u8>>) -> Result<(), Ap
506491
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.publish.ex#L512
507492
///
508493
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release.ex#L13
509-
pub fn publish_package_request(
494+
pub fn api_publish_package_request(
510495
release_tarball: Vec<u8>,
511496
api_key: &str,
512497
config: &Config,
@@ -524,7 +509,7 @@ pub fn publish_package_request(
524509
.expect("publish_package_request request")
525510
}
526511

527-
pub fn publish_package_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
512+
pub fn api_publish_package_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
528513
// TODO: return data from body
529514
let (parts, body) = response.into_parts();
530515
match parts.status {
@@ -549,7 +534,7 @@ pub fn publish_package_response(response: http::Response<Vec<u8>>) -> Result<(),
549534
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.publish.ex#L371
550535
///
551536
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/release.ex#L21
552-
pub fn revert_release_request(
537+
pub fn api_revert_release_request(
553538
package_name: &str,
554539
version: &str,
555540
api_key: &str,
@@ -567,7 +552,7 @@ pub fn revert_release_request(
567552
.expect("publish_package_request request"))
568553
}
569554

570-
pub fn revert_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
555+
pub fn api_revert_release_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
571556
let (parts, body) = response.into_parts();
572557
match parts.status {
573558
StatusCode::NO_CONTENT => Ok(()),
@@ -602,7 +587,7 @@ impl Display for OwnerLevel {
602587
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.owner.ex#L107
603588
///
604589
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/package.ex#L19
605-
pub fn add_owner_request(
590+
pub fn api_add_owner_request(
606591
package_name: &str,
607592
owner: &str,
608593
level: OwnerLevel,
@@ -624,7 +609,7 @@ pub fn add_owner_request(
624609
.expect("add_owner_request request")
625610
}
626611

627-
pub fn add_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
612+
pub fn api_add_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
628613
let (parts, body) = response.into_parts();
629614
match parts.status {
630615
StatusCode::NO_CONTENT => Ok(()),
@@ -641,7 +626,7 @@ pub fn add_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiEr
641626
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.owner.ex#L125
642627
///
643628
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/package.ex#L19
644-
pub fn transfer_owner_request(
629+
pub fn api_transfer_owner_request(
645630
package_name: &str,
646631
owner: &str,
647632
api_key: &str,
@@ -662,7 +647,7 @@ pub fn transfer_owner_request(
662647
.expect("transfer_owner_request request")
663648
}
664649

665-
pub fn transfer_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
650+
pub fn api_transfer_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
666651
let (parts, body) = response.into_parts();
667652
match parts.status {
668653
StatusCode::NO_CONTENT => Ok(()),
@@ -679,7 +664,7 @@ pub fn transfer_owner_response(response: http::Response<Vec<u8>>) -> Result<(),
679664
/// https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.owner.ex#L139
680665
///
681666
/// https://github.com/hexpm/hex/blob/main/lib/hex/api/package.ex#L28
682-
pub fn remove_owner_request(
667+
pub fn api_remove_owner_request(
683668
package_name: &str,
684669
owner: &str,
685670
api_key: &str,
@@ -695,7 +680,7 @@ pub fn remove_owner_request(
695680
.expect("remove_owner_request request")
696681
}
697682

698-
pub fn remove_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
683+
pub fn api_remove_owner_response(response: http::Response<Vec<u8>>) -> Result<(), ApiError> {
699684
let (parts, body) = response.into_parts();
700685
match parts.status {
701686
StatusCode::NO_CONTENT => Ok(()),
@@ -1005,7 +990,7 @@ fn verify_payload(mut signed: Signed, pem_public_key: &[u8]) -> Result<Vec<u8>,
1005990

1006991
/// Create a request to get the information for a package release.
1007992
///
1008-
pub fn get_package_release_request(
993+
pub fn api_get_package_release_request(
1009994
name: &str,
1010995
version: &str,
1011996
api_key: Option<&str>,
@@ -1024,7 +1009,7 @@ pub fn get_package_release_request(
10241009

10251010
/// Parse a response to get the information for a package release.
10261011
///
1027-
pub fn get_package_release_response(
1012+
pub fn api_get_package_release_response(
10281013
response: http::Response<Vec<u8>>,
10291014
) -> Result<Release<ReleaseMeta>, ApiError> {
10301015
let (parts, body) = response.into_parts();

0 commit comments

Comments
 (0)