Skip to content

Commit

Permalink
Adds Hyves strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Menno de Gier committed Feb 3, 2011
1 parent 1a33c3f commit 72f3fb9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions oa-oauth/lib/omniauth/oauth.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module Strategies
autoload :Bitly, 'omniauth/strategies/bitly' autoload :Bitly, 'omniauth/strategies/bitly'
autoload :Vimeo, 'omniauth/strategies/vimeo' autoload :Vimeo, 'omniauth/strategies/vimeo'
autoload :YouTube, 'omniauth/strategies/you_tube' autoload :YouTube, 'omniauth/strategies/you_tube'
autoload :Hyves, 'omniauth/strategies/hyves'
end end
end end
67 changes: 67 additions & 0 deletions oa-oauth/lib/omniauth/strategies/hyves.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'omniauth/oauth'
require 'multi_json'


module OmniAuth
module Strategies
class Hyves < OmniAuth::Strategies::OAuth
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
client_options = {
:request_token_path => request_token_path,
:authorize_path => "http://www.hyves.nl/api/authorize",
:access_token_path => access_token_path,
:http_method => :get,
:scheme => :header
}
super(app, :hyves, consumer_key, consumer_secret, client_options, options, &block)
end

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

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

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

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

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

def request_token_options
to_params( { :methods => "users.get,friends.get,wwws.create", :ha_method => "auth.requesttoken", :strict_oauth_spec_response => true } )
end

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

def to_params(options)
options.collect { |key, value| "#{key}=#{value}"}.join('&')
end
end
end
end
5 changes: 5 additions & 0 deletions oa-oauth/spec/omniauth/strategies/hyves_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe OmniAuth::Strategies::Hyves do
it_should_behave_like "an oauth strategy"
end

0 comments on commit 72f3fb9

Please sign in to comment.