Class: Twat::Endpoints::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/twat/endpoints/base.rb

Direct Known Subclasses

Identica, Twitter

Constant Summary collapse

@@endpoint_set =
nil

Instance Method Summary collapse

Instance Method Details

#authorize_account(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/twat/endpoints/base.rb', line 6

def (name)
  oauth_conf = oauth_options.merge ({ :site => url })

  oauth = OAuth::Consumer.new(consumer_info[:consumer_key], consumer_info[:consumer_secret], oauth_conf)
  token_request = oauth.get_request_token()
  puts "Please authenticate the application at #{token_request.authorize_url}, then enter pin"
  pin = STDIN.gets.chomp
  begin
    access_token = token_request.get_access_token(oauth_verifier: pin)
     = {
      oauth_token: access_token.token,
      oauth_token_secret: access_token.secret,
      endpoint: endpoint_name
    }
    config.accounts[name.to_sym] = 
    config.save!
  rescue OAuth::Unauthorized
    puts "Couldn't authenticate you, did you enter the pin correctly?"
  end
end

#configObject



27
28
29
30
31
32
# File 'lib/twat/endpoints/base.rb', line 27

def config
  return @config if @config
  @config = ::Twat::Config.new
  @config.create! unless @config.exists?
  return @config
end

#endpoint_nameObject



34
35
36
# File 'lib/twat/endpoints/base.rb', line 34

def endpoint_name
  raise "Endpoint not set! Naughty programmer"
end