Sha256: 3a840f5f19bc89344f23a92dd8d0780297d2e2b085090e410258d86cd9f597b5

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module SimpleFlickr
  class DesktopAuthentication < Authentication
    
    # Returns URL where to get a frob.
    def frob_url
      url_for(default_params.merge(:method => 'flickr.auth.getFrob'))
    end

    # Returns the frob from the response
    def frob_from_response(response)
      doc = Hpricot::XML response.body
      doc.at('frob').inner_text
    end

    # Constructs an URL for the user to go to and authenticate
    def authentication_url_for_frob(frob)
      params = default_params.merge(:perms => 'read', :frob => frob)
      AuthenticationService + query_string(params)
    end
    
    # Goes through the process of requesting a frob and constructing
    # an authentication URL for the user all in one call
    def authentication_url
      response = HTTP.start do |flickr|
        flickr.get(frob_url)
      end
      @frob = frob_from_response(response)
      authentication_url_for_frob(@frob)
    end
    
    # Tries to get a token from the previously used frob.
    def get_token(arg = nil)
      raise "Please specify a frob to use" if frob.nil? && arg.nil?
      get_token_from_frob(frob.nil? ? arg : frob)
    end
    
    private
      attr_reader :frob
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pietern-simpleflickr-0.2.2 lib/simpleflickr/authentication/desktop.rb