Class: OmniAuth::Strategies::Hyves

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/hyves.rb

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Hyves

Returns a new instance of Hyves.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 7

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  options = {
    :methods => 'users.get,friends.get,wwws.create',
    :expirationtype => 'default'
  }.merge(options)

  client_options = {
    :authorize_path => 'http://www.hyves.nl/api/authorize',
    :access_token_path => access_token_path,
    :http_method => :get,
    :request_token_path => request_token_path(options),
    :scheme => :header,
  }

  super(app, :hyves, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#access_token_optionsObject



60
61
62
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 60

def access_token_options
  to_params({:ha_method => 'auth.accesstoken', :strict_oauth_spec_response => true})
end

#access_token_pathObject



52
53
54
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 52

def access_token_path
  "http://data.hyves-api.nl/?#{access_token_options}&#{default_options}"
end

#auth_hashObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 24

def auth_hash
  hash = user_hash(@access_token)
  {
    'provider' => 'hyves',
    'uid' => hash['userid'],
    'user_info' => {
      'name' => "#{hash['firstname']} #{hash['lastname']}",
      'first_name' => hash['firstname'],
      'last_name' => hash['lastname'],
    },
    'credentials' => {
      'token' => @access_token.token,
      'secret' => @access_token.secret,
    },
  }
end

#default_optionsObject



56
57
58
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 56

def default_options
  to_params({:ha_version => '2.0', :ha_format => 'json', :ha_fancylayout => false})
end

#request_token_path(options) ⇒ Object



46
47
48
49
50
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 46

def request_token_path(options)
  options['ha_method'] = 'auth.requesttoken'
  options['strict_oauth_spec_response'] = true
  "http://data.hyves-api.nl/?#{to_params(options)}&#{default_options}"
end

#to_params(options) ⇒ Object



64
65
66
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 64

def to_params(options)
  options.collect{|key, value| "#{key}=#{value}"}.join('&')
end

#user_hash(access_token) ⇒ Object



41
42
43
44
# File 'lib/omniauth/strategies/oauth/hyves.rb', line 41

def user_hash(access_token)
  rsp = MultiJson.decode(access_token.get("http://data.hyves-api.nl/?userid=#{access_token.params[:userid]}&ha_method=users.get&#{default_options}").body)
  rsp['user'].first
end