chiark / gitweb /
Decentralise version component of API URLs.
authorSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 07:01:41 +0000 (07:01 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 2 Jan 2024 17:30:18 +0000 (17:30 +0000)
I thought it was /api/v1/whatever, but I've just realised that it's
actually /api/v2/instance in particular. _That's_ why I keep seeing
"uri" from some servers and "domain" from others: if I requested the
up-to-date version of the record, it would agree on "domain".

src/client.rs
src/types.rs

index 14fbed536c78fab7de6a73be089f3128d1ea88a8..66a32ef94521d9961b1cbf4aa859d77e668e9599 100644 (file)
@@ -188,7 +188,7 @@ impl Client {
                 "Non-GET request attempted in readonly mode".to_string()));
         }
 
-        let urlstr = self.auth.instance_url.clone() + "/api/v1/" +
+        let urlstr = self.auth.instance_url.clone() + "/api/" +
             &req.url_suffix;
         let parsed = if req.parameters.is_empty() {
             Url::parse(&urlstr)
@@ -216,7 +216,7 @@ impl Client {
             return Ok(inst.clone());
         }
 
-        let (url, req) = self.api_request(Req::get("instance"))?;
+        let (url, req) = self.api_request(Req::get("v2/instance"))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let inst: Instance = if !rspstatus.is_success() {
@@ -255,7 +255,7 @@ impl Client {
         }
 
         let (url, req) = self.api_request(Req::get(
-            &("accounts/".to_owned() + id)))?;
+            &("v1/accounts/".to_owned() + id)))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let ac: Account = if !rspstatus.is_success() {
@@ -280,7 +280,7 @@ impl Client {
         Result<Relationship, ClientError>
     {
         let (url, req) = self.api_request(
-            Req::get("accounts/relationships").param("id", id))?;
+            Req::get("v1/accounts/relationships").param("id", id))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let rels: Vec<Relationship> = if !rspstatus.is_success() {
@@ -314,7 +314,7 @@ impl Client {
         }
 
         let (url, req) = self.api_request(Req::get(
-            &("statuses/".to_owned() + id)))?;
+            &("v1/statuses/".to_owned() + id)))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let st: Status = if !rspstatus.is_success() {
@@ -359,7 +359,7 @@ impl Client {
         }
 
         let (url, req) = self.api_request(Req::get(
-            &("notifications/".to_owned() + id)))?;
+            &("v1/notifications/".to_owned() + id)))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let not: Notification = if !rspstatus.is_success() {
@@ -411,26 +411,26 @@ impl Client {
         }
 
         let req = match id {
-            FeedId::Home => Req::get("timelines/home"),
+            FeedId::Home => Req::get("v1/timelines/home"),
             FeedId::Local => {
-                Req::get("timelines/public").param("local", true)
+                Req::get("v1/timelines/public").param("local", true)
             }
             FeedId::Public => {
-                Req::get("timelines/public").param("local", false)
+                Req::get("v1/timelines/public").param("local", false)
             }
             FeedId::Hashtag(ref tag) => {
-                Req::get(&format!("timelines/tag/{}", &tag))
+                Req::get(&format!("v1/timelines/tag/{}", &tag))
             }
             FeedId::User(id, boosts, replies) => {
-                Req::get(&format!("accounts/{}/statuses", id))
+                Req::get(&format!("v1/accounts/{}/statuses", id))
                     .param("exclude_reblogs", *boosts == Boosts::Hide)
                     .param("exclude_replies", *replies == Replies::Hide)
             }
             FeedId::Mentions => {
-                Req::get("notifications").param("types[]", "mention")
+                Req::get("v1/notifications").param("types[]", "mention")
             }
             FeedId::Ego => {
-                Req::get("notifications")
+                Req::get("v1/notifications")
                     .param("types[]", "reblog")
                     .param("types[]", "follow")
                     .param("types[]", "favourite")
@@ -551,7 +551,7 @@ impl Client {
         &self, id: &StreamId, receiver: Box<Recv>) -> Result<(), ClientError>
     {
         let req = match id {
-            StreamId::User => Req::get("streaming/user"),
+            StreamId::User => Req::get("v1/streaming/user"),
         };
         
         let client = reqwest::blocking::Client::new();
@@ -651,7 +651,7 @@ impl Client {
         Result<Account, ClientError>
     {
         let (url, req) = self.api_request(
-            Req::get("accounts/lookup").param("acct", name))?;
+            Req::get("v1/accounts/lookup").param("acct", name))?;
         let rsp = req.send()?;
         let rspstatus = rsp.status();
         let ac: Account = if !rspstatus.is_success() {
index ef6a4549b2289afa950c34d86b7c625117a80187..ff84ad55dcbce075f93f3cd55d4e6034b1a242a1 100644 (file)
@@ -245,11 +245,7 @@ pub struct InstanceConfig {
 
 #[derive(Deserialize, Debug, Clone)]
 pub struct Instance {
-    // At least one major live instance (hachyderm.io) uses the key
-    // "uri" for its instance domain. But the Mastodon test instance
-    // uses "domain". Bah.
-    #[serde(alias="uri")] pub domain: Option<String>,
-
+    pub domain: String,
     pub configuration: InstanceConfig,
 
     // FIXME: lots of things are missing from here!