Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/release-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@ jobs:
uses: MarcoIeni/release-plz-action@v0.5
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ CARGO_REGISTRY_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

sync-cargo-docs:
name: Sync cargo docs to gh-pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Sync Docs
run: |
cargo doc
pip install ghp-import
echo '<meta http-equiv=refresh content=0;url=mpesa/index.html>' > target/doc/index.html
ghp-import -n target/doc
git push -qf https://github.com/collinsmuriuki/mpesa-rust.git gh-pages
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Sync Docs
run: |
cargo doc
pip install ghp-import
echo '<meta http-equiv=refresh content=0;url=mpesa/index.html>' > target/doc/index.html
ghp-import -n target/doc
git push -qf https://github.com/collinsmuriuki/mpesa-rust.git gh-pages
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Cargo.lock
.env
.DS_Store

.vscode
.vscode
18 changes: 10 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::RefCell;
use std::borrow::BorrowMut;
use std::sync::{Arc, RwLock};
use std::time::Duration;

use cached::Cached;
Expand Down Expand Up @@ -31,7 +32,7 @@
pub struct Mpesa {
consumer_key: String,
consumer_secret: Secret<String>,
initiator_password: RefCell<Option<Secret<String>>>,
initiator_password: Arc<RwLock<Option<Secret<String>>>>,
pub(crate) base_url: String,
certificate: String,
pub(crate) http_client: HttpClient,
Expand Down Expand Up @@ -77,7 +78,7 @@
Self {
consumer_key: consumer_key.into(),
consumer_secret: Secret::new(consumer_secret.into()),
initiator_password: RefCell::new(None),
initiator_password: Arc::new(RwLock::new(None)),
base_url,
certificate,
http_client,
Expand All @@ -87,8 +88,9 @@
/// Gets the initiator password
/// If `None`, the default password is `"Safcom496!"`
pub(crate) fn initiator_password(&self) -> String {
self.initiator_password
.borrow()
let mut pass = self.initiator_password.read().unwrap();

pass.borrow_mut()
.as_ref()
.map(|password| password.expose_secret().into())
.unwrap_or(DEFAULT_INITIATOR_PASSWORD.to_owned())
Expand Down Expand Up @@ -129,11 +131,11 @@
/// Environment::Sandbox,
/// );
/// client.set_initiator_password("your_initiator_password");
/// assert!(client.is_connected().await);

Check failure on line 134 in src/client.rs

View workflow job for this annotation

GitHub Actions / Test

cannot borrow `client` as mutable, as it is not declared as mutable
/// }
/// ```
pub fn set_initiator_password<S: Into<String>>(&self, initiator_password: S) {
*self.initiator_password.borrow_mut() = Some(Secret::new(initiator_password.into()));
pub fn set_initiator_password<S: Into<String>>(&mut self, initiator_password: S) {
*self.initiator_password.write().unwrap() = Some(Secret::new(initiator_password.into()));
}

/// Checks if the client can be authenticated
Expand Down Expand Up @@ -332,7 +334,7 @@

#[test]
fn test_setting_initator_password() {
let client = Mpesa::new("consumer_key", "consumer_secret", Sandbox);
let mut client = Mpesa::new("consumer_key", "consumer_secret", Sandbox);
assert_eq!(client.initiator_password(), DEFAULT_INITIATOR_PASSWORD);
client.set_initiator_password("foo_bar");
assert_eq!(client.initiator_password(), "foo_bar".to_string());
Expand Down
Loading