A => src/mblog.ads +3 -0
@@ 0,0 1,3 @@
+package MBlog is
+ type Microblog_Type is (TWITTER_BLOG, IDENTICA_BLOG);
+end MBlog;
No newline at end of file
M src/secrets.adb +22 -12
@@ 1,33 1,43 @@
with App;
package body Secrets is
- function Get_Consumer_Key return String is
+ function B_S (Blog : Microblog_Type) return String is
begin
- return App.Get ("ladybird.consumer_key");
+ case Blog is
+ when TWITTER_BLOG =>
+ return "twitter";
+ when IDENTICA_BLOg =>
+ return "identica";
+ end case;
+ end B_S;
+
+ function Get_Consumer_Key (Blog : Microblog_Type) return String is
+ begin
+ return App.Get ("ladybird." & B_S(Blog) & ".consumer_key");
end Get_Consumer_Key;
- function Get_Consumer_Secret return String is
+ function Get_Consumer_Secret (Blog : Microblog_Type) return String is
begin
- return App.Get ("ladybird.consumer_secret");
+ return App.Get ("ladybird." & B_S(Blog) & ".consumer_secret");
end Get_Consumer_Secret;
- function Get_Token return String is
+ function Get_Token (Blog : Microblog_Type) return String is
begin
- return App.Get ("ladybird.token");
+ return App.Get ("ladybird." & B_S(Blog) & ".token");
end Get_Token;
- function Get_Token_Secret return String is
+ function Get_Token_Secret (Blog : Microblog_Type) return String is
begin
- return App.Get ("ladybird.token_secret");
+ return App.Get ("ladybird." & B_S(Blog) & ".token_secret");
end Get_Token_Secret;
- procedure Set_Token (Value : String) is
+ procedure Set_Token (Blog : Microblog_Type; Value : String) is
begin
- App.Set ("ladybird.token", Value);
+ App.Set ("ladybird." & B_S(Blog) & ".token", Value);
end Set_Token;
- procedure Set_Token_Secret (Value : String) is
+ procedure Set_Token_Secret (Blog : Microblog_Type; Value : String) is
begin
- App.Set ("ladybird.token_secret", Value);
+ App.Set ("ladybird." & B_S(Blog) & ".token_secret", Value);
end Set_Token_Secret;
end Secrets;
M src/secrets.ads +9 -6
@@ 1,14 1,17 @@
+with MBlog;
package Secrets is
- function Get_Consumer_Key return String;
+ use MBlog;
- function Get_Consumer_Secret return String;
+ function Get_Consumer_Key (Blog : Microblog_Type) return String;
- function Get_Token return String;
+ function Get_Consumer_Secret (Blog : Microblog_Type) return String;
- function Get_Token_Secret return String;
+ function Get_Token (Blog : Microblog_Type) return String;
+
+ function Get_Token_Secret (Blog : Microblog_Type) return String;
- procedure Set_Token (Value : String);
+ procedure Set_Token (Blog : Microblog_Type; Value : String);
- procedure Set_Token_Secret (Value : String);
+ procedure Set_Token_Secret (Blog : Microblog_Type; Value : String);
end Secrets;
M +13 -9
@@ 5,23 5,27 @@ with OAuth.Easy;
with Properties;
with HTTP;
with URLs;
with MBlog;
package body Twitter is
use URLs;
use MBlog;
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);
Manager.My_Secret := To_Unbounded_String (Secrets.Get_Token_Secret);
Manager.My_Token := To_Unbounded_String
(Secrets.Get_Token (Microblog));
Manager.My_Secret := To_Unbounded_String
(Secrets.Get_Token_Secret (Microblog));
if Length (Manager.My_Token) > 0
and Length (Manager.My_Secret) > 0 then
OAuth.Easy.Init
(Context => Manager.C,
Consumer_Key => Secrets.Get_Consumer_Key,
Consumer_Secret => Secrets.Get_Consumer_Secret);
Consumer_Key => Secrets.Get_Consumer_Key (Microblog),
Consumer_Secret => Secrets.Get_Consumer_Secret (Microblog));
OAuth.Easy.Set_Token (Manager.C, To_String (Manager.My_Token));
OAuth.Easy.Set_Token_Secret
(Manager.C, To_String (Manager.My_Secret));
@@ 39,8 43,8 @@ package body Twitter is
begin
OAuth.Easy.Init
(Context => Manager.C,
Consumer_Key => Secrets.Get_Consumer_Key,
Consumer_Secret => Secrets.Get_Consumer_Secret);
Consumer_Key => Secrets.Get_Consumer_Key (Microblog),
Consumer_Secret => Secrets.Get_Consumer_Secret (Microblog));
OAuth.Easy.Request_Token
(Context => Manager.C,
URL => Request_Token_URL (Microblog),
@@ 62,9 66,9 @@ package body Twitter is
Verifier => PIN,
User_Id => User_Id,
Name => Name);
Secrets.Set_Token (To_String (OAuth.Easy.Get_Token (Manager.C)));
Secrets.Set_Token (Microblog, To_String (OAuth.Easy.Get_Token (Manager.C)));
Secrets.Set_Token_Secret
(To_String (OAuth.Easy.Get_Token_Secret (Manager.C)));
(Microblog, To_String (OAuth.Easy.Get_Token_Secret (Manager.C)));
end Auth_Give_PIN;
procedure Homeline (Manager : in out Twitter_Type;
@@ 89,7 93,7 @@ package body Twitter is
Tweets := Result;
else
-- Tweets := To_Unbounded_String ("error");
-- Put_Line ("Error: " & Long_Integer'Image (R_Code));
Put_Line ("Error: " & Long_Integer'Image (R_Code));
-- Put_Line ("Message: " & To_String (Result));
raise Unknown_Error;
end if;
M src/urls.ads +2 -1
@@ 1,6 1,7 @@
+with MBlog;
package URLs is
- type Microblog_Type is (TWITTER_BLOG, IDENTICA_BLOG);
+ use MBlog;
function Request_Token_URL (Blog : Microblog_Type) return String;