Module: ActsAsDailycred::InstanceMethods

Defined in:
lib/dailycred/acts_as_dailycred.rb

Instance Method Summary collapse

Instance Method Details

#connect_path(provider) ⇒ Object



80
81
82
# File 'lib/dailycred/acts_as_dailycred.rb', line 80

def connect_path provider
  "/auth/dailycred?identity_provider=#{provider.to_s}"
end

#display_nameObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dailycred/acts_as_dailycred.rb', line 44

def display_name
  display = self.email || ""
  if self.facebook != {}
    return self.facebook["name"]
  elsif self.google != {}
    return self.google["name"]
  elsif self.twitter != {}
    return "@"+self.twitter["screen_name"]
  end
  display
end

#fire_event(key, val = "") ⇒ Object



72
73
74
# File 'lib/dailycred/acts_as_dailycred.rb', line 72

def fire_event key, val=""
  get_client.event self.uid, key, val
end

#get_clientObject



76
77
78
# File 'lib/dailycred/acts_as_dailycred.rb', line 76

def get_client
  @dailycred ||= Dailycred::Client.new Rails.configuration.DAILYCRED_CLIENT_ID, Rails.configuration.DAILYCRED_SECRET_KEY
end


56
57
58
# File 'lib/dailycred/acts_as_dailycred.rb', line 56

def referral_link url
  "https://www.dailycred.com/r/#{self.uid}?redirect_uri=#{url}"
end

#reset_passwordObject



59
60
61
# File 'lib/dailycred/acts_as_dailycred.rb', line 59

def reset_password
  get_client.reset_password self.email
end

#tag(tag) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/dailycred/acts_as_dailycred.rb', line 24

def tag tag
  dc = get_client
  response = dc.tag self.uid, tag
  json = JSON.parse(response.body)
  if json['worked']
    self.tags << tag
    save!
  end
end

#untag(tag) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/dailycred/acts_as_dailycred.rb', line 34

def untag tag
  dc = get_client
  response = dc.untag self.uid, tag
  json = JSON.parse(response.body)
  if json['worked']
    self.tags.delete tag
    save!
  end
end

#update_from_dailycred(dc) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/dailycred/acts_as_dailycred.rb', line 63

def update_from_dailycred dc
  bad = ['updated_at', 'created_at']
  p dc
  dc.each do |k,v|
    self[k] = v if self.respond_to?(k) and !bad.include?(k.to_s)
  end
  save!
end