Skip to content

Commit

Permalink
support for twitter compatible microblogging apis like identi.ca
Browse files Browse the repository at this point in the history
  • Loading branch information
herestomwiththeweather committed Feb 10, 2009
1 parent 548a725 commit 502be03
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/models/person.rb
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions app/models/preference.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/req.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/preferences/edit.html.erb
Expand Up @@ -37,6 +37,11 @@
<%= f.password_field :twitter_password %>
</div>

<div class="form_row">
<label for="twitter_api">Twitter api</label>
<%= f.text_field :twitter_api %>
</div>

<div class="form_row">
<label for="exception_notification">Exception Notify Emails</label>
<%= f.text_field :exception_notification %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/preferences/show.html.erb
Expand Up @@ -25,6 +25,11 @@
<%=h @preferences.twitter_name %>
</p>

<p>
<b>Twitter api:</b>
<%=h @preferences.twitter_api %>
</p>

<p>
<b>Exception notify emails (space separated):</b>
<%=h @preferences.exception_notification %>
Expand Down
9 changes: 9 additions & 0 deletions 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

0 comments on commit 502be03

Please sign in to comment.