Skip to content

Instantly share code, notes, and snippets.

@empika
Created May 25, 2010 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save empika/413670 to your computer and use it in GitHub Desktop.
Save empika/413670 to your computer and use it in GitHub Desktop.
def self.fetch_yams
config_path = File.join(RAILS_ROOT, 'config', 'yammer.yml')
yammer = Yammer::Client.new(:config => config_path)
# this is the ID of the main link hashtag (should be 402387)
link_tag_id = 0
tags = yammer.tags
tags.each do |tag|
if( tag.name == "link")
link_tag_id = tag.id
end
end
messages = yammer.messages({:tagged_with => link_tag_id})
puts RAILS_ENV
messages.each do |message|
url = message.body.plain.slice(URI.regexp)
doc = open(url) {|f| Hpricot(f)}
title = doc.at("title").inner_html
#user = User.find(:first, :conditions => {:})
link = Link.create(:url => url, :title => title,:yammer_message_id => message.id,:body => message.body.parsed,:plain => message.body.plain,:published_at => message.created_at,:sender_id => message.sender_id, :msg_url => message.url,:web_url => message.web_url)
puts "Created a link: " + url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment