Skip to content

Commit

Permalink
moidfy make_url
Browse files Browse the repository at this point in the history
  • Loading branch information
Kouhei Aoyagi committed Apr 2, 2024
1 parent e4effea commit 12c9a94
Show file tree
Hide file tree
Showing 59 changed files with 123 additions and 133 deletions.
110 changes: 55 additions & 55 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
## Changes

### v0.14.1 (2024/04/02)
* prefix url orverride
* Orverride prefix url for each APIs

### v0.14.0 (2024/03/27)
* add upload.twitter.com apis
* add GET /2/usage/tweets
* Add upload.twitter.com APIs
* Add GET /2/usage/tweets

### v0.13.1 (2024/03/25)
* modify oauth with state
* Modify oauth with state

### v0.13.0 (2024/03/25)
* updated reqwest 0.12
* Updated reqwest 0.12

### v0.12.0 (2024/03/09)
* Supported mocks. For example, mockito.

### v0.11.0 (2024/03/08)
* add media_source_tweet_id in attachments
* remove rate_limit
* add headers
* Add media_source_tweet_id in attachments
* Remove rate_limit
* Add headers

### v0.10.1 (2024/01/23)
* modify trend response
* Modify trend response

### v0.10.0 (2024/01/22)
* add user filed connection_status and most_recent_tweet_id
* Add user filed connection_status and most_recent_tweet_id

### v0.9.0 (2023/12/16)
* add get /2/users/search
- add get /2/trend/by/woeid/:woeid
* Add get /2/users/search
- Add get /2/trend/by/woeid/:woeid

### v0.8.1 (2023/12/06)
* feature models
* Add feature models

### v0.8.0 (2023/12/06)
* add v1 to v2 json parser
* Add v1 to v2 json parser
* skip_serializing_if Option::is_none
* add poll_ids in attatchments
* add like_count in users public_metrics
* Add poll_ids in attatchments
* Add like_count in users public_metrics

### v0.7.1 (2023/09/05)
* modify calucurate oauth1.0a path paramter
* Modify calucurate oauth1.0a path paramter

### v0.7.0 (2023/09/05)
* breaking change oauth11a to oauth10a
* updated crates
* Breaking change oauth11a to oauth10a
* Updated crates

### v0.6.0 (2023/08/28)
* breaking change separate authentication
* support OAuth1.1a authentication. feature oauth11a
* Breaking change separate authentication
* Support OAuth1.1a authentication. feature oauth11a

### v0.5.10 (2023/08/01)
* modified typo
* modified test status
* add note_tweet in tweets
* add bookmark_count in public_metrics
* Modified typo
* Modified test status
* Add note_tweet in tweets
* Add bookmark_count in public_metrics

### v0.5.9 (2023/05/11)
* add post_2_oauth2_token_refresh_token
* remove post_2_oauth2_token
* serde rename for request enum
* test get_2_compliance_jobs
* modify parameters
* Add post_2_oauth2_token_refresh_token
* Remove post_2_oauth2_token
* Add serde rename for request enum
* Test get_2_compliance_jobs
* Modify parameters

### v0.5.8 (2023/05/08)
* typo README
* remove no use files
* add test status
* modify parameters
* Modify typo README
* Remove no use files
* Add test status
* Modify parameters

### v0.5.7 (2023/05/04)
* test get_2_users_id_mention etc...
* modify parameters
* Test get_2_users_id_mention etc...
* Modify parameters

### v0.5.6 (2023/05/03)
* add streaming example
* test post_2_tweets_search_stream_rules etc...
* modify post_2_auth2_token interface
* modify parameters
* Add streaming example
* Test post_2_tweets_search_stream_rules etc...
* Modify post_2_auth2_token interface
* Modify parameters

### v0.5.6 (2023/05/03)
* add streaming example
* test post_2_tweets_search_stream_rules etc...
* modify post_2_auth2_token interface
* modify parameters
* Add streaming example
* Test post_2_tweets_search_stream_rules etc...
* Modify post_2_auth2_token interface
* Modify parameters

### v0.5.5 (2023/05/02)
* test post_lists_id_members etc...
* modify parameters
* Test post_lists_id_members etc...
* Modify parameters

### v0.5.4 (2023/04/28)
* test post_2_users_id_retweets, post_2_users_id_likes, post_2_users_id_muting, post_2_users_id_following, post_2_users_id_blocking, post_2_users_id_bookmarks, etc...
* modify parameters
* Test post_2_users_id_retweets, post_2_users_id_likes, post_2_users_id_muting, post_2_users_id_following, post_2_users_id_blocking, post_2_users_id_bookmarks, etc...
* Modify parameters

### v0.5.3 (2023/04/27)
* test post_2_tweets, delete_2_tweets_id, post_2_dm_conversations_with_participant_id_message, etc...
* modify parameters
* Test post_2_tweets, delete_2_tweets_id, post_2_dm_conversations_with_participant_id_message, etc...
* Modify parameters

### v0.5.2 (2023/04/26)
* test get_2_users_me, get_2_tweets_search_recent
* modify response parameters
* Test get_2_users_me, get_2_tweets_search_recent
* Modify response parameters

### v0.5.1 (2023/04/25)
* remove unuse url crate
* pub use reqwest
* Remove unuse url crate
* Add pub use reqwest

### v0.5.0 (2023/04/25)
* Add Api::all, Api::open methods. It's all enum parameter setted.
* In Api::all and Api::open methods, max_results is max value.

### v0.4.0 (2023/04/25)
* Twitter OAuth
* oauth-web example
* Add oauth-web example

### v0.3.0 (2023/04/24)
* Support api::execute_twitter generics parameter
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ BEARER_CODE=XXXXX cargo run
```rust
#[tokio::test]
async fn test_mock_get_2_tweets_search_recent_oauth() -> Result<()> {
// Setup mock server
let mut server = Server::new_async().await;
let mock = server
.mock("GET", "/2/tweets/search/recent")
Expand All @@ -166,23 +167,26 @@ async fn test_mock_get_2_tweets_search_recent_oauth() -> Result<()> {
.create_async()
.await;

// Setup prefix all apis
api::setup_prefix_url(&server.url());
// Setup OAuth
let auth = OAuthAuthentication::new(
std::env::var("CONSUMER_KEY").unwrap_or_default(),
std::env::var("CONSUMER_SECRET").unwrap_or_default(),
std::env::var("ACCESS_KEY").unwrap_or_default(),
std::env::var("ACCESS_SECRET").unwrap_or_default(),
);

// Setup prefix all APIs
api::setup_prefix_url(&server.url());
let builder = get_2_tweets_search_recent::Api::open("東京")
.max_results(10)
.build(&auth);
let (res, _headers) = execute_twitter::<get_2_tweets_search_recent::Response>(builder).await?;
assert_eq!(res.extra.get("origin"), Some(&json!("0.0.0.0")));
mock.assert();

// Setup prefix each apis
// Clear prefix url
api::clear_prefix_url();
// Override prefix url
let twapi_options = TwapiOptions {
prefix_url: Some(server.url().clone())
};
Expand Down
2 changes: 1 addition & 1 deletion maker/api.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Api {
pub fn build(self, authentication: &impl Authentication) -> RequestBuilder {
<%= parameters %>
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL<%= paths.empty? ? "" : paths.map{|it| ".replace(\":#{it[:name].make_field}\", &self.#{it[:name].make_field})"}.join("") %>);
let url = make_url(&self.twapi_options, <%= paths.empty? ? "" : "&" %>URL<%= paths.empty? ? "" : paths.map{|it| ".replace(\":#{it[:name].make_field}\", &self.#{it[:name].make_field})"}.join("") %>);
let builder = client
.<%= yml[:method] %>(&url)<% if queries.present? %>
.query(&query_parameters)<% end %><% if form.present? %>
Expand Down
12 changes: 6 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ pub struct TwapiOptions {
pub prefix_url: Option<String>,
}

fn get_prefix_url() -> String {
std::env::var(ENV_KEY).unwrap_or(PREFIX_URL_TWITTER.to_owned())
}

pub(crate) fn make_url<S: AsRef<str>>(twapi_options: &Option<TwapiOptions>, post_url: S) -> String {
make_url_with_prefix(&get_prefix_url(), twapi_options, post_url.as_ref())
pub(crate) fn make_url(twapi_options: &Option<TwapiOptions>, post_url: &str) -> String {
make_url_with_prefix(
&std::env::var(ENV_KEY).unwrap_or(PREFIX_URL_TWITTER.to_owned()),
twapi_options,
post_url,
)
}

pub(crate) fn make_url_with_prefix(
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_lists_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Api {

pub fn build(self, authentication: &impl Authentication) -> RequestBuilder {
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.delete(&url);
authentication.execute(builder, "DELETE", &url, &[])
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_lists_id_members_user_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":user_id", &self.user_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_tweets_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Api {

pub fn build(self, authentication: &impl Authentication) -> RequestBuilder {
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.delete(&url);
authentication.execute(builder, "DELETE", &url, &[])
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_users_id_bookmarks_tweet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":tweet_id", &self.tweet_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_users_id_followed_lists_list_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":list_id", &self.list_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_users_id_likes_tweet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":tweet_id", &self.tweet_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_users_id_pinned_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":list_id", &self.list_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/delete_2_users_id_retweets_source_tweet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":id", &self.id)
&URL.replace(":id", &self.id)
.replace(":source_tweet_id", &self.source_tweet_id),
);
let builder = client.delete(&url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":source_user_id", &self.source_user_id)
&URL.replace(":source_user_id", &self.source_user_id)
.replace(":target_user_id", &self.target_user_id),
);
let builder = client.delete(&url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":source_user_id", &self.source_user_id)
&URL.replace(":source_user_id", &self.source_user_id)
.replace(":target_user_id", &self.target_user_id),
);
let builder = client.delete(&url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":source_user_id", &self.source_user_id)
&URL.replace(":source_user_id", &self.source_user_id)
.replace(":target_user_id", &self.target_user_id),
);
let builder = client.delete(&url);
Expand Down
2 changes: 1 addition & 1 deletion src/api/get_2_compliance_jobs_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Api {

pub fn build(self, authentication: &impl Authentication) -> RequestBuilder {
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.get(&url);
authentication.execute(builder, "GET", &url, &[])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":dm_conversation_id", &self.dm_conversation_id),
&URL.replace(":dm_conversation_id", &self.dm_conversation_id),
);
let builder = client.get(&url).query(&query_parameters);
authentication.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Api {
let client = reqwest::Client::new();
let url = make_url(
&self.twapi_options,
URL.replace(":participant_id", &self.participant_id),
&URL.replace(":participant_id", &self.participant_id),
);
let builder = client.get(&url).query(&query_parameters);
authentication.execute(
Expand Down
2 changes: 1 addition & 1 deletion src/api/get_2_lists_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Api {
query_parameters.push(("user.fields", user_fields.iter().join(",")));
}
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.get(&url).query(&query_parameters);
authentication.execute(
builder,
Expand Down
2 changes: 1 addition & 1 deletion src/api/get_2_lists_id_followers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Api {
query_parameters.push(("user.fields", user_fields.iter().join(",")));
}
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.get(&url).query(&query_parameters);
authentication.execute(
builder,
Expand Down
2 changes: 1 addition & 1 deletion src/api/get_2_lists_id_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Api {
query_parameters.push(("user.fields", user_fields.iter().join(",")));
}
let client = reqwest::Client::new();
let url = make_url(&self.twapi_options, URL.replace(":id", &self.id));
let url = make_url(&self.twapi_options, &URL.replace(":id", &self.id));
let builder = client.get(&url).query(&query_parameters);
authentication.execute(
builder,
Expand Down

0 comments on commit 12c9a94

Please sign in to comment.