pub struct ContentApiKey { /* private fields */ }Expand description
Content API key for authentication.
The Content API uses a simple API key mechanism where the key is passed as a query parameter (?key=…) in requests. Keys are 26-character hexadecimal strings generated by Ghost.
§Format
Content API keys are 26-character hexadecimal strings (lowercase).
Example: 22444f78447824223cefc48062
§Security
Content API keys are safe for public use as they only grant read access to published content. They should still be treated with care to avoid quota exhaustion.
§Example
use ghost_io_api::auth::content::ContentApiKey;
// Valid key
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
assert_eq!(key.as_str(), "22444f78447824223cefc48062");
// Invalid key (too short)
let result = ContentApiKey::new("invalid");
assert!(result.is_err());Implementations§
Source§impl ContentApiKey
impl ContentApiKey
Sourcepub const MIN_KEY_LENGTH: usize = 26
pub const MIN_KEY_LENGTH: usize = 26
Minimum valid key length (26 characters).
Sourcepub const MAX_KEY_LENGTH: usize = 26
pub const MAX_KEY_LENGTH: usize = 26
Maximum valid key length (26 characters).
Sourcepub fn new(key: impl Into<String>) -> Result<Self>
pub fn new(key: impl Into<String>) -> Result<Self>
Creates a new Content API key with validation.
§Validation
- Must be exactly 26 characters long
- Must contain only hexadecimal characters (0-9, a-f)
- Automatically converts uppercase to lowercase
§Errors
Returns GhostError::Auth if:
- Key is not 26 characters long
- Key contains non-hexadecimal characters
- Key is empty
§Example
use ghost_io_api::auth::content::ContentApiKey;
// Valid key
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
assert!(key.is_valid());
// Invalid - too short
assert!(ContentApiKey::new("short").is_err());
// Invalid - non-hex characters
assert!(ContentApiKey::new("gggggggggggggggggggggggggg").is_err());Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the key as a string slice.
§Example
use ghost_io_api::auth::content::ContentApiKey;
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
assert_eq!(key.as_str(), "22444f78447824223cefc48062");Sourcepub fn as_query_param(&self) -> String
pub fn as_query_param(&self) -> String
Returns the key formatted as a query parameter.
This returns the key in the format key=<value> ready to be
appended to a URL query string.
§Example
use ghost_io_api::auth::content::ContentApiKey;
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
let param = key.as_query_param();
assert_eq!(param, "key=22444f78447824223cefc48062");
// Can be used in URLs
let url = format!("https://demo.ghost.io/ghost/api/content/posts/?{}", param);
assert!(url.contains("?key="));Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Validates the key format.
Returns true if the key is valid (correct length and hex characters).
Note: This will always return true for keys created via new()
since validation happens at construction time.
§Example
use ghost_io_api::auth::content::ContentApiKey;
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
assert!(key.is_valid());Trait Implementations§
Source§impl AsRef<str> for ContentApiKey
impl AsRef<str> for ContentApiKey
Source§impl Clone for ContentApiKey
impl Clone for ContentApiKey
Source§fn clone(&self) -> ContentApiKey
fn clone(&self) -> ContentApiKey
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ContentApiKey
impl Debug for ContentApiKey
Source§impl Display for ContentApiKey
impl Display for ContentApiKey
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the key for display (shows first 8 and last 4 characters).
For security, the full key is not displayed. Use as_str() if you
need the complete key.
§Example
use ghost_io_api::auth::content::ContentApiKey;
let key = ContentApiKey::new("22444f78447824223cefc48062").unwrap();
let display = format!("{}", key);
assert_eq!(display, "ContentApiKey(22444f78...8062)");impl Eq for ContentApiKey
Source§impl PartialEq for ContentApiKey
impl PartialEq for ContentApiKey
Source§fn eq(&self, other: &ContentApiKey) -> bool
fn eq(&self, other: &ContentApiKey) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ContentApiKey
Auto Trait Implementations§
impl Freeze for ContentApiKey
impl RefUnwindSafe for ContentApiKey
impl Send for ContentApiKey
impl Sync for ContentApiKey
impl Unpin for ContentApiKey
impl UnsafeUnpin for ContentApiKey
impl UnwindSafe for ContentApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.