From 502be037f161011e67e3aea309b04952fedd8530 Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Tue, 10 Feb 2009 01:37:08 -0600 Subject: [PATCH] support for twitter compatible microblogging apis like identi.ca --- app/models/person.rb | 3 ++- app/models/preference.rb | 14 ++++++++++++-- app/models/req.rb | 3 ++- app/views/admin/preferences/edit.html.erb | 5 +++++ app/views/admin/preferences/show.html.erb | 5 +++++ .../20090210064135_add_twitter_api_preferences.rb | 9 +++++++++ 6 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20090210064135_add_twitter_api_preferences.rb diff --git a/app/models/person.rb b/app/models/person.rb index 9c9f18b8..516160c2 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -467,8 +467,9 @@ def log_activity_description_changed def follow(twitter_id) twitter_name = Person.global_prefs.twitter_name twitter_password = Person.global_prefs.plaintext_twitter_password + twitter_api = Person.global_prefs.twitter_api - twit = Twitter::Base.new(twitter_name,twitter_password) + twit = Twitter::Base.new(twitter_name,twitter_password, :api_host => twitter_api ) begin twit.create_friendship(twitter_id) rescue Twitter::CantConnect => e diff --git a/app/models/preference.rb b/app/models/preference.rb index 8b25c453..9a65265a 100644 --- a/app/models/preference.rb +++ b/app/models/preference.rb @@ -24,12 +24,14 @@ class Preference < ActiveRecord::Base :email_notifications, :email_verifications, :analytics, :about, :demo, :whitelist, :gmail, :registration_notification, :practice, :steps, :questions, :memberships, :contact, - :twitter_name, :twitter_password + :twitter_name, :twitter_password, :twitter_api validates_presence_of :domain, :if => :using_email? validates_presence_of :smtp_server, :if => :using_email? + validates_presence_of :twitter_api, :if => :using_twitter? before_save :encrypt_twitter_password + before_validation :set_default_twitter_api_if_using_twitter # Can we send mail with the present configuration? def can_send_email? @@ -58,7 +60,15 @@ def encrypt_twitter_password return if twitter_password.blank? self.crypted_twitter_password = encrypt(twitter_password) end - + + def set_default_twitter_api_if_using_twitter + self.twitter_api = 'twitter.com' if self.twitter_api.blank? + end + + def using_twitter? + twitter_name? + end + def using_email? email_notifications? or email_verifications? end diff --git a/app/models/req.rb b/app/models/req.rb index 9c0b145e..94c3cc5d 100644 --- a/app/models/req.rb +++ b/app/models/req.rb @@ -29,8 +29,9 @@ def tweet(url) twitter_name = Req.global_prefs.twitter_name twitter_password = Req.global_prefs.plaintext_twitter_password + twitter_api = Req.global_prefs.twitter_api - twit = Twitter::Base.new(twitter_name,twitter_password) + twit = Twitter::Base.new(twitter_name,twitter_password, :api_host => twitter_api ) begin twit.update("#{name}: #{url}") rescue Twitter::CantConnect => e diff --git a/app/views/admin/preferences/edit.html.erb b/app/views/admin/preferences/edit.html.erb index e742dee2..7e5d899a 100644 --- a/app/views/admin/preferences/edit.html.erb +++ b/app/views/admin/preferences/edit.html.erb @@ -37,6 +37,11 @@ <%= f.password_field :twitter_password %> +
+ + <%= f.text_field :twitter_api %> +
+
<%= f.text_field :exception_notification %> diff --git a/app/views/admin/preferences/show.html.erb b/app/views/admin/preferences/show.html.erb index 8d5484c3..bc5008e1 100644 --- a/app/views/admin/preferences/show.html.erb +++ b/app/views/admin/preferences/show.html.erb @@ -25,6 +25,11 @@ <%=h @preferences.twitter_name %>

+

+ Twitter api: + <%=h @preferences.twitter_api %> +

+

Exception notify emails (space separated): <%=h @preferences.exception_notification %> diff --git a/db/migrate/20090210064135_add_twitter_api_preferences.rb b/db/migrate/20090210064135_add_twitter_api_preferences.rb new file mode 100644 index 00000000..3c496dc1 --- /dev/null +++ b/db/migrate/20090210064135_add_twitter_api_preferences.rb @@ -0,0 +1,9 @@ +class AddTwitterApiPreferences < ActiveRecord::Migration + def self.up + add_column :preferences, :twitter_api, :string + end + + def self.down + remove_column :preferences, :twitter_api + end +end