Skip to content
Browse files

add bitly for shorten url

  • Loading branch information...
1 parent 43db5ac commit cef339a5be76be5254e4ebf1e377570a6f2c151d @flyerhzm flyerhzm committed Jul 19, 2010
Showing with 15 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 Gemfile
  3. +3 −1 app/models/implementation.rb
  4. +3 −1 app/models/post.rb
  5. +7 −0 lib/tweetable.rb
View
1 .gitignore
@@ -11,3 +11,4 @@ public/images/css_sprite.png
app/stylesheets/css_sprite.scss
public/*.xml.gz
config/twitter.yml
+config/bitly.yml
View
1 Gemfile
@@ -44,6 +44,7 @@ gem "meta-tags", :require => 'meta_tags'
gem "sitemap_generator", ">= 0.3.3"
gem "twitter"
gem "resque"
+gem "bitly"
gem "mongrel", :group => :development
gem "awesome_print", :require => 'ap', :group => :development
View
4 app/models/implementation.rb
@@ -15,6 +15,8 @@ def belongs_to?(user)
end
def tweet_content
- "Implementation of #{post.title}"
+ bitly = load_bitly
+ url = bitly.shorten("http://rails-bestpractices/posts/#{post.to_param}/implementation").short_url
+ "Implementation of #{post.title} #{url}"
end
end
View
4 app/models/post.rb
@@ -21,7 +21,9 @@ def self.per_page
end
def tweet_content
- "#{self.title}"
+ bitly = load_bitly
+ url = bitly.shorten("http://rails-bestpractices/posts/#{self.to_param}").short_url
+ "#{self.title} #{url}"
end
def belongs_to?(user)
View
7 lib/tweetable.rb
@@ -6,6 +6,13 @@ def self.included(base)
end
end
+ BITLY_YAML = Rails.root.join('config', 'bitly.yml')
+
+ def load_bitly
+ config = YAML.load_file(BITLY_YAML)[RAILS_ENV]
+ Bitly.new(config['username'], config['api_key'])
+ end
+
def async_tweet
Resque.enqueue(Resque::TweetJob, tweet_content)
end

0 comments on commit cef339a

Please sign in to comment.
Something went wrong with that request. Please try again.