Module: Dailycred::Helpers

Included in:
SessionsController
Defined in:
lib/dailycred/helper.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject

use as a before_filter to only allow signed in users example:

before_filter :authenticate


7
8
9
# File 'lib/dailycred/helper.rb', line 7

def authenticate
  redirect_to_unauth unless current_user
end

#connect_path(params = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/dailycred/helper.rb', line 31

def connect_path(params={})
  url = "#{request.protocol}#{request.host_with_port}/auth/dailycred"
  p = []
  params.each do |k,v|
    p << "#{k}=#{v.to_s}"
  end
  url += "?" if p.size > 0
  url += p.join("&")
end

#connect_user(provider, user = nil) ⇒ Object



41
42
43
44
45
46
# File 'lib/dailycred/helper.rb', line 41

def connect_user provider, user=nil
  if user.nil?
    user = current_user
  end
  connect_path(access_token: user.token, identity_provider: provider)
end

#dailycredObject

helper method for getting an instance of dailycred example:

dailycred.tagUser "user_id", "tag"

for more documentation, visit www.dailycred.com/api/ruby



16
17
18
19
# File 'lib/dailycred/helper.rb', line 16

def dailycred
  config = Rails.configuration
  @dailycred ||= Dailycred::Client.new(config.DAILYCRED_CLIENT_ID, config.DAILYCRED_SECRET_KEY, config.DAILYCRED_OPTIONS)
end

#login_path(params = {}) ⇒ Object



27
28
29
# File 'lib/dailycred/helper.rb', line 27

def (params={})
  connect_path params
end

#redirect_to_auth(opts = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/dailycred/helper.rb', line 48

def redirect_to_auth opts={}
  p 'redirecting to auth'
  conf = Rails.configuration.DAILYCRED_OPTIONS
  path = !conf[:after_auth].nil? ? conf[:after_auth] : dailycred_engine.auth_info_path
  redirect_to path, opts
end

#redirect_to_unauth(opts = {}) ⇒ Object



55
56
57
58
59
# File 'lib/dailycred/helper.rb', line 55

def redirect_to_unauth opts = {}
  conf = Rails.configuration.DAILYCRED_OPTIONS
  path = !conf[:after_unauth].nil? ? conf[:after_unauth] : dailycred_engine.auth_info_path
  redirect_to path, opts
end

#set_stateObject

when making oauth calls, we may need to redirect to our oauth callback url make sure we have the correct state passed back and forth



23
24
25
# File 'lib/dailycred/helper.rb', line 23

def set_state
  @state = session["omniauth.state"] = SecureRandom.hex(24)
end