Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adds Hyves strategy

  • Loading branch information...
commit 72f3fb9dc5b2bcaeb011c4d6b25d067633ff56a2 1 parent 1a33c3f
Menno de Gier authored
View
1  oa-oauth/lib/omniauth/oauth.rb
@@ -26,5 +26,6 @@ module Strategies
autoload :Bitly, 'omniauth/strategies/bitly'
autoload :Vimeo, 'omniauth/strategies/vimeo'
autoload :YouTube, 'omniauth/strategies/you_tube'
+ autoload :Hyves, 'omniauth/strategies/hyves'
end
end
View
67 oa-oauth/lib/omniauth/strategies/hyves.rb
@@ -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
View
5 oa-oauth/spec/omniauth/strategies/hyves_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.