Top Level Namespace

Defined Under Namespace

Modules: Hangout Classes: String

Instance Method Summary collapse

Instance Method Details

#authorize(client_id, redirect_uri) ⇒ Object



3
4
5
6
# File 'lib/hangout/auth.rb', line 3

def authorize client_id, redirect_uri
  uri = authorize_url client_id, redirect_uri
  Launchy.open("#{uri.scheme}://#{uri.host}#{uri.request_uri}")
end

#authorize_url(client_id, redirect_uri) ⇒ Object



8
9
10
11
# File 'lib/hangout/auth.rb', line 8

def authorize_url client_id, redirect_uri
  url = "https://foursquare.com/oauth2/authenticate?response_type=token&client_id=#{client_id}&redirect_uri=#{redirect_uri}"
  URI(url)
end

#get_user_token(config_file, client_id, redirect_uri) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hangout/auth.rb', line 13

def get_user_token config_file, client_id, redirect_uri
  if !File.exists? config_file
    puts "Well shucks, looks like you haven't used this little app before."
    puts "I'm going to open the browser now and grab a number for you. Could"
    puts "you do me a favour and paste it in here?"
    puts
    puts "(It's the big long string after `access_token=` in your URL bar.)"
    puts
    puts "<Press return to open your browser...>"
    gets
    authorize client_id, redirect_uri
    puts "Paste the key in here:"
    key = gets
    File.open(config_file, "w") do |f|
      f.write(key)
    end

    puts "Thanks, please re-run the application."
    exit 0
  end

  File.read config_file
end