module SimpleFlickr class Authentication AuthenticationService = 'http://www.flickr.com/services/auth/?' attr_reader :permission def initialize(options) # This class must be subclassed if self.class.name =~ /::Authentication$/ raise "The Authentication class must be subclassed" end unless options.key?(:api_key) && options.key?(:secret) raise ArgumentError.new("Options should contain at least :api_key and :secret") end @permission = (options[:permission] || :read).to_sym @default_params = { :api_key => options[:api_key], :secret => options[:secret] } end def token_url(frob) params = default_params.merge(:frob => frob, :method => 'flickr.auth.getToken') url_for(params) end def get_token_from_frob(frob) response = HTTP.start do |flickr| flickr.get(token_url(frob)) end doc = Hpricot::XML response.body doc.at('token').inner_text end private attr_reader :default_params end end