Class: PostCommit::Hooks::FriendFeed

Inherits:
Base
  • Object
show all
Defined in:
lib/post_commit/hooks/friend_feed.rb

Overview

To send a FriendFeed post commit, you have to setup your username and API token. You can retrieve your API token at friendfeed.com/account/api.

post_commit :friendfeed do
  authorize :username => "johndoe", :token => "abc"
  post "Some message", :url => "http://example.com/"
end

Instance Attribute Summary

Attributes inherited from Base

#credentials, #options, #request, #response, #uri

Instance Method Summary (collapse)

Methods inherited from Base

#authorize, #convert_to_params, #convert_to_xml, inherited, #initialize, #set

Constructor Details

This class inherits a constructor from PostCommit::Hooks::Base

Instance Method Details

- (Object) post(message, options = {})

Post message to FriendFeed.

post "We're working on it!"
post "Google", :url => "http://google.com"


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/post_commit/hooks/friend_feed.rb', line 16

def post(message, options = {})
  @uri = URI.parse("http://friendfeed-api.com/v2/entry")
  http = Net::HTTP.new(uri.host, uri.port)

  @request = Net::HTTP::Post.new(uri.path)
  @request.basic_auth credentials[:username], credentials[:token]
  @request.form_data = {
    :body => message,
    :link => options[:url]
  }

  @response = http.request(@request)

  if response.code == "200"
    JSON.parse response.body
  else
    false
  end
rescue Exception
  false
end