# HG changeset patch # User Tero Koskinen # Date 1318997298 -10800 # Wed Oct 19 07:08:18 2011 +0300 # Node ID 553d3140f1fe74f461e98fa88c54b1438473b754 # Parent 4112728b88bbb591c2a541007409f7bbb7e7b2ca Make Twitter/Identi.ca selection a compile time option handled via one constant variable. diff --git a/src/twitter.adb b/src/twitter.adb --- a/src/twitter.adb +++ b/src/twitter.adb @@ -4,8 +4,13 @@ with OAuth.Easy; with Properties; with HTTP; +with URLs; package body Twitter is + use URLs; + + Microblog : constant Microblog_Type := TWITTER_BLOG; -- IDENTICA_BLOG; + procedure Init (Manager : out Twitter_Type) is begin Manager.My_Token := To_Unbounded_String (Secrets.Get_Token); @@ -38,10 +43,10 @@ Consumer_Secret => Secrets.Get_Consumer_Secret); OAuth.Easy.Request_Token (Context => Manager.C, - URL => "https://identi.ca/api/oauth/request_token", + URL => Request_Token_URL (Microblog), Method => "GET"); URL := To_Unbounded_String - ("https://identi.ca/api/oauth/authorize?oauth_token=" + (OAuth_Token_URL (Microblog) & "?oauth_token=" & To_String (OAuth.Easy.Get_Token (Manager.C))); end Auth_Get_PIN_URL; @@ -52,7 +57,7 @@ begin OAuth.Easy.Access_Token (Context => Manager.C, - URL => "https://identi.ca/api/oauth/access_token", + URL => Access_Token_URL (Microblog), Method => "GET", Verifier => PIN, User_Id => User_Id, @@ -66,8 +71,7 @@ Tweets : out Charbuf.Char_Buffer) is use OAuth; - Home_URL : constant String := - "http://identi.ca/api/statuses/home_timeline.json"; + Home_URL : constant String := Home_Timeline_URL (Microblog); OAuth_Header : Unbounded_String; Extra_Params : Parameter_List.List := Parameter_List.Empty_List; Result : Charbuf.Char_Buffer; @@ -95,8 +99,7 @@ Message : String) is use OAuth; - Update_URL : constant String := - "http://identi.ca/api/statuses/update.json"; + Update_Address : constant String := Update_URL (Microblog); OAuth_Header : Unbounded_String; Extra_Params : Parameter_List.List := Parameter_List.Empty_List; Result : Charbuf.Char_Buffer; @@ -106,10 +109,10 @@ (To_Unbounded_String ("status"), To_Unbounded_String (Message))); Easy.As_Header - (Manager.C, Update_URL, "POST", Extra_Params, OAuth_Header); + (Manager.C, Update_Address, "POST", Extra_Params, OAuth_Header); Put_Line ("Header: " & To_String (OAuth_Header)); HTTP.Post_Page - (URL => Update_URL, + (URL => Update_Address, Header_Key => "Authorization", Header_Value => To_String (OAuth_Header), Fields => "status=" & Message, diff --git a/src/urls.adb b/src/urls.adb new file mode 100644 --- /dev/null +++ b/src/urls.adb @@ -0,0 +1,53 @@ + +package body URLs is + function Request_Token_URL (Blog : Microblog_Type) return String is + begin + case Blog is + when TWITTER_BLOG => + return "https://api.twitter.com/oauth/request_token"; + when IDENTICA_BLOG => + return "https://identi.ca/api/oauth/request_token"; + end case; + end Request_Token_URL; + + function OAuth_Token_URL (Blog : Microblog_Type) return String is + begin + case Blog is + when TWITTER_BLOG => + return "https://api.twitter.com/oauth/authorize"; + when IDENTICA_BLOG => + return "https://identi.ca/api/oauth/authorize"; + end case; + end OAuth_Token_URL; + + function Access_Token_URL (Blog : Microblog_Type) return String is + begin + case Blog is + when TWITTER_BLOG => + return "https://api.twitter.com/oauth/access_token"; + when IDENTICA_BLOG => + return "https://identi.ca/api/oauth/access_token"; + end case; + end Access_Token_URL; + + function Home_Timeline_URL (Blog : Microblog_Type) return String is + begin + case Blog is + when TWITTER_BLOG => + return "http://api.twitter.com/1/statuses/home_timeline.json"; + when IDENTICA_BLOG => + return "http://identi.ca/api/statuses/home_timeline.json"; + end case; + end Home_Timeline_URL; + + function Update_URL (Blog : Microblog_Type) return String is + begin + case Blog is + when TWITTER_BLOG => + return "http://api.twitter.com/1/statuses/update.json"; + when IDENTICA_BLOG => + return "http://identi.ca/api/statuses/update.json"; + end case; + end Update_URL; + +end URLs; diff --git a/src/urls.ads b/src/urls.ads new file mode 100644 --- /dev/null +++ b/src/urls.ads @@ -0,0 +1,15 @@ + +package URLs is + type Microblog_Type is (TWITTER_BLOG, IDENTICA_BLOG); + + function Request_Token_URL (Blog : Microblog_Type) return String; + + function OAuth_Token_URL (Blog : Microblog_Type) return String; + + function Access_Token_URL (Blog : Microblog_Type) return String; + + function Home_Timeline_URL (Blog : Microblog_Type) return String; + + function Update_URL (Blog : Microblog_Type) return String; + +end URLs;