diaspora/app/models/services/twitter.rb
Jonne Haß 2a4db54db9 New configuration system
* Throw away old system
* Add new system
* Add new example files
* Replace all calls
* add the most important docs
* Add Specs
* rename disable_ssl_requirement to require_ssl
* cloudfiles isn't used/called in our code
* since community_spotlight.list is only used as enable flag replace it with such one and remove all legacy and irelevant codepaths around it
* die if session secret is unset and on heroku
* First basic infrastructure for version information
2012-09-26 20:19:37 +02:00

52 lines
1.2 KiB
Ruby

require 'uri'
class Services::Twitter < Service
MAX_CHARACTERS = 140
SHORTENED_URL_LENGTH = 21
def provider
"twitter"
end
def post(post, url='')
Rails.logger.debug("event=post_to_service type=twitter sender_id=#{self.user_id}")
message = public_message(post, url)
configure_twitter
Twitter.update(message)
end
def public_message(post, url)
buffer_amt = 0
URI.extract( post.text(:plain_text => true), ['http','https'] ) do |a_url|
buffer_amt += (a_url.length - SHORTENED_URL_LENGTH)
end
super(post, MAX_CHARACTERS + buffer_amt, url)
end
def profile_photo_url
configure_twitter
Twitter.profile_image(nickname, :size => "original")
end
private
def configure_twitter
twitter_key = AppConfig.services.twitter.key
twitter_consumer_secret = AppConfig.services.twitter.secret
if twitter_key.blank? || twitter_consumer_secret.blank?
Rails.logger.info "you have a blank twitter key or secret.... you should look into that"
end
Twitter.configure do |config|
config.consumer_key = twitter_key
config.consumer_secret = twitter_consumer_secret
config.oauth_token = self.access_token
config.oauth_token_secret = self.access_secret
end
end
end