diaspora/app/models/services/facebook.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

41 lines
1.3 KiB
Ruby

require 'uri'
class Services::Facebook < Service
include Rails.application.routes.url_helpers
OVERRIDE_FIELDS_ON_FB_UPDATE = [:contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username]
MAX_CHARACTERS = 420
def provider
"facebook"
end
def post(post, url='')
Rails.logger.debug("event=post_to_service type=facebook sender_id=#{self.user_id}")
if post.public?
post_to_facebook("https://graph.facebook.com/me/joindiaspora:make", create_open_graph_params(post).to_param)
else
post_to_facebook("https://graph.facebook.com/me/feed", create_post_params(post).to_param)
end
end
def post_to_facebook(url, body)
Faraday.post(url, body)
end
def create_open_graph_params(post)
{:post => "#{AppConfig.environment.url}#{short_post_path(post)}", :access_token => self.access_token}
end
def create_post_params(post)
message = post.text(:plain_text => true)
{:message => message, :access_token => self.access_token, :link => URI.extract(message, ['https', 'http']).first}
end
def public_message(post, url)
super(post, MAX_CHARACTERS, url)
end
def profile_photo_url
"https://graph.facebook.com/#{self.uid}/picture?type=large&access_token=#{URI.escape(self.access_token)}"
end
end