-
-
Save factore/771711e84d999400ba57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/social_networking.rb | |
class TwitterConnect | |
require 'twitter' | |
def self.tweet(message) | |
oauth = Twitter::OAuth.new('xxx','yyy') | |
oauth.authorize_from_access('zzz', 'aaa') | |
client = Twitter::Base.new(oauth) | |
client.update(message) | |
end | |
end | |
class Bitly | |
include HTTParty | |
base_uri 'api.bit.ly' | |
basic_auth 'factore', 'bitly-api-key' | |
format :json | |
def self.shorten(url) | |
response = get('/shorten', :query => required_params.merge(:longUrl => url)) | |
response['results'][url]['shortUrl'] | |
end | |
def self.required_params | |
{:version => "2.0.1"} | |
end | |
end | |
# In your after_save hook | |
def publish_to_networks | |
require 'social_networking' | |
url = bitly_url | |
TwitterConnect.tweet("New Post! -- #{self.title} #{url}") | |
Mailer::deliver_facebook_update("New Post! -- #{self.title} #{url}") unless Settings.facebook_email.blank? | |
self.published_to_networks = true and self.save | |
end | |
# In Mailer - No view needed | |
def facebook_update(message) | |
recipients Settings.facebook_email | |
subject message | |
body "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment