Skip to content

Commit

Permalink
fix!: Harmonize with_base_url method with with_algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed Nov 1, 2021
1 parent 7fa59b4 commit d95b76f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let config = Config::new("123456", "2", "3", "4", "5");
let api = RestApi::new(config);
# use httpmock::{MockServer, Method::POST};
# let server = MockServer::start();
# let api = RestApi::with_base_url(Config::new("123456", "2", "3", "4", "5"), server.base_url());;
# let api = RestApi::new(Config::new("123456", "2", "3", "4", "5")).with_base_url(server.base_url());;
# let mock = server.mock(|when, then| {
# when.method(POST).path("/query/v1/suiteql");
# then.status(200).body(r#"{"links":[{"rel":"next","href":"https://123456.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=2&offset=2"},{"rel":"last","href":"https://123456.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=2&offset=1998"},{"rel":"self","href":"https://123456.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql?limit=2"}],"count":2,"hasMore":false,"items":[{"links":[],"currency":"1","internalid":"24","item":"24","pricelevel":"15","quantity":"1","saleunit":"1","unitprice":"95.49"},{"links":[],"currency":"1","internalid":"24","item":"24","pricelevel":"21","quantity":"1","saleunit":"1","unitprice":"19.99"}],"offset":0,"totalResults":2000}"#);
Expand Down
4 changes: 4 additions & 0 deletions src/requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl Requester {
}
}

pub fn with_base_url(self, base_url: String) -> Self {
Self { base_url, ..self }
}

pub fn with_algorithm(self, algorithm: oauth1::Algorithm) -> Self {
Self { algorithm, ..self }
}
Expand Down
4 changes: 2 additions & 2 deletions src/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl RestApi {
DEFAULT_BASE_URL.replace("{}", &host_part)
}

pub fn with_base_url(config: Config, base_url: String) -> Self {
let requester = Requester::new(config, base_url);
pub fn with_base_url(self, base_url: String) -> Self {
let requester = self.requester.with_base_url(base_url);
let suiteql = SuiteQl::new(requester.clone());
let metadata = MetadataApi::new(requester.clone());
Self {
Expand Down
2 changes: 1 addition & 1 deletion tests/suiteql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn ensure_logging() {

fn make_api(server: &MockServer) -> RestApi {
let config = Config::new("1", "2", "3", "4", "5");
RestApi::with_base_url(config, server.base_url())
RestApi::new(config).with_base_url(server.base_url())
}

#[test]
Expand Down

0 comments on commit d95b76f

Please sign in to comment.