require 'twitter'
# Check out the twitter gem docs for using oauth
httpauth = Twitter::HTTPAuth.new("username", "password")
base = Twitter::Base.new(httpauth)
to_follow_ids = base.follower_ids - base.friend_ids
unavailable_count = 0
to_follow_ids.each do |tfid|
begin
base.friendship_create(tfid, true)
rescue Twitter::General
# Twitter::General is raised for 403 errors
# Which occur when you're trying to follow someone who's been banned by twitter
base.block(tfid)
rescue Twitter::Unavailable
# Wait and try again if twitter's telling you to wait
sleep 5
if unavailable_count < 3
retry
unavailable_count += 1
end
end
end
# How to define and use a singleton class
# - modifies the class's class
# - instance methods in the singleton class are class methods externally
class TheClass
class << self
def hello
puts "hi"
end
end
end
# invoke a class method
TheClass.hello # hi
=begin
http://developer.spotify.com/en/metadata-api/overview/
Requests: http://ws.spotify.com/service/version/method[.format]?parameters
http://ws.spotify.com/search/1/track.json?q=kaizers+orchestra
Track Lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:track:6NmXV4o6bmp704aPGyTVVG
Artist lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ&extras=album
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ&extras=albumdetail
Album lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4&extras=track
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4&extras=trackdetail
Search Example
http://ws.spotify.com/search/1/artist?q=Bj%C3%B6rk.
=end
class SpotifyAPIRequest
require 'open-uri'
def initialize
end
def lookup( keyword )
open("http://ws.spotify.com/search/1/track.json?q=" + keyword){
|f|
#Get the Full response which should be the full HTML
@req = f.read
#Find the first place where "No match is found", if nothing is found, it will return 'nil'
puts @req
=begin
@txt = @req.index("No match")
puts @txt
if @txt.nil?
puts "Domain " + word + ".com is available"
else
puts "Domain " + word + ".com is taken"
end
=end
}
end
end
spotify = SpotifyAPIRequest.new
spotify.lookup("beethoven")
using terms from application "Quicksilver"
on process text ThisClipping
tell application "Adium"
set my status message to ThisClipping
set my status type to away
end tell
end process text
end using terms from
before_filter :session_expire
private
def session_expire
if session[:user]
session_length = 60*10 #10 Minutes for logged in users
expire_time = session[:expire_time] || Time.now + 10
if expire_time < Time.now
reset_session
flash[:notice] = "You have been logged out due to an extended period of inactivity"
redirect_to :controller => 'welcome' , :action => 'index'
else
session[:expire_time] = Time.now + session_length
end
end
end