Class: Dawanda::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/dawanda/oauth.rb

Overview

OAuth

Provides access to sesitive user data

Constant Summary collapse

API_PREFIX =
'/api/v1/oauth'

Class Method Summary collapse

Class Method Details

.access_tokenObject



26
27
28
# File 'lib/dawanda/oauth.rb', line 26

def self.access_token
  @@access_token ||= nil
end

.access_token=(access_token) ⇒ Object



30
31
32
# File 'lib/dawanda/oauth.rb', line 30

def self.access_token=(access_token)
  @@access_token = access_token
end

.authorize_urlObject



22
23
24
# File 'lib/dawanda/oauth.rb', line 22

def self.authorize_url
  @@request_token.authorize_url
end

.connect(key, secret) ⇒ Object



10
11
12
13
# File 'lib/dawanda/oauth.rb', line 10

def self.connect key, secret
  @@consumer = Dawanda::OAuth.create_consumer key, secret
  @@request_token = @@consumer.get_request_token  
end

.get(url, options = {}) ⇒ Object



34
35
36
# File 'lib/dawanda/oauth.rb', line 34

def self.get(url, options={})
  Dawanda::Response.new(@@access_token.get(url).body)
end

.rebuild(key, secret, params) ⇒ Object



15
16
17
18
19
20
# File 'lib/dawanda/oauth.rb', line 15

def self.rebuild key, secret, params
  @@consumer = Dawanda::OAuth.create_consumer key, secret
  @@request_token = ::OAuth::RequestToken.from_hash(@@consumer, params) 
  @@request_token.consumer.options.merge!({:oauth_verifier => params[:oauth_verifier]})
  @@access_token = @@request_token.get_access_token
end

.userObject



38
39
40
# File 'lib/dawanda/oauth.rb', line 38

def self.user
  Dawanda::User.new(Dawanda::OAuth.get("#{API_PREFIX}/users.json").result)
end