File tree Expand file tree Collapse file tree 5 files changed +20
-4
lines changed Expand file tree Collapse file tree 5 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ ROOT_URL=https://root.amfoss.in/
33OWNER_ID =
44DEBUG = true
55ENABLE_DEBUG_LIBRARIES = false
6+ AMD_API_KEY =
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ pub struct Config {
3434 pub owner_id : Option < UserId > ,
3535 pub prefix_string : String ,
3636 pub root_url : String ,
37+ pub api_key : String ,
3738}
3839
3940impl Default for Config {
@@ -46,6 +47,8 @@ impl Default for Config {
4647 owner_id : parse_owner_id_env ( "OWNER_ID" ) ,
4748 prefix_string : String :: from ( "$" ) ,
4849 root_url : std:: env:: var ( "ROOT_URL" ) . expect ( "ROOT_URL was not found in env" ) ,
50+ api_key : std:: env:: var ( "AMD_API_KEY" )
51+ . expect ( "AMD_API_KEY was not found in env" ) ,
4952 }
5053 }
5154}
Original file line number Diff line number Diff line change @@ -26,20 +26,26 @@ use reqwest::Client;
2626pub struct GraphQLClient {
2727 http : Client ,
2828 root_url : Arc < String > ,
29+ api_key : Arc < String > ,
2930}
3031
3132impl GraphQLClient {
32- pub fn new ( root_url : String ) -> Self {
33+ pub fn new ( root_url : String , api_key : String ) -> Self {
3334 Self {
3435 http : Client :: new ( ) ,
3536 root_url : Arc :: new ( root_url) ,
37+ api_key : Arc :: new ( api_key) ,
3638 }
3739 }
3840
3941 pub fn root_url ( & self ) -> & str {
4042 & self . root_url
4143 }
4244
45+ pub fn api_key ( & self ) -> & str {
46+ & self . api_key
47+ }
48+
4349 pub fn http ( & self ) -> Client {
4450 self . http . clone ( )
4551 }
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ impl GraphQLClient {
6060 let response = self
6161 . http ( )
6262 . post ( self . root_url ( ) )
63+ . bearer_auth ( self . api_key ( ) )
6364 . json ( & serde_json:: json!( { "query" : query, "variables" : variables} ) )
6465 . send ( )
6566 . await
@@ -115,6 +116,7 @@ impl GraphQLClient {
115116 let response = self
116117 . http ( )
117118 . post ( self . root_url ( ) )
119+ . bearer_auth ( self . api_key ( ) )
118120 . json ( & serde_json:: json!( { "query" : query } ) )
119121 . send ( )
120122 . await
Original file line number Diff line number Diff line change @@ -55,11 +55,11 @@ struct Data {
5555
5656impl Data {
5757 /// Returns a new [`Data`] with an empty `reaction_roles` field and the passed-in `reload_handle`.
58- fn new ( reload_handle : ReloadHandle , root_url : String ) -> Self {
58+ fn new ( reload_handle : ReloadHandle , root_url : String , api_key : String ) -> Self {
5959 Data {
6060 reaction_roles : HashMap :: new ( ) ,
6161 log_reload_handle : reload_handle,
62- graphql_client : GraphQLClient :: new ( root_url) ,
62+ graphql_client : GraphQLClient :: new ( root_url, api_key ) ,
6363 }
6464 }
6565}
@@ -95,7 +95,11 @@ fn build_framework(
9595}
9696
9797fn prepare_data ( config : & Config , reload_handle : ReloadHandle ) -> Data {
98- let mut data = Data :: new ( reload_handle, config. root_url . clone ( ) ) ;
98+ let mut data = Data :: new (
99+ reload_handle,
100+ config. root_url . clone ( ) ,
101+ config. api_key . clone ( ) ,
102+ ) ;
99103 data. populate_with_reaction_roles ( ) ;
100104 data
101105}
You can’t perform that action at this time.
0 commit comments