Sha256: 8e6c89d7dc2b87274de24f95d3d2fd5f98d038e57f4983d0c073393d52792dc2
Contents?: true
Size: 1.79 KB
Versions: 4
Compression:
Stored size: 1.79 KB
Contents
module ActsAsDailycred def acts_as_dailycred serialize :tags, Array serialize :referred, Array serialize :access_tokens, Hash serialize :identities, Hash extend ActsAsDailycred::SingletonMethods include ActsAsDailycred::InstanceMethods include Dailycred::Helpers end module SingletonMethods def find_or_create_with_omniauth(model) @user = User.find_by_provider_and_uid(model['provider'], model['uid']) || User.new @user.update_from_dailycred model[:info] @user end end module InstanceMethods 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 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 #deprecated, use @user.display def display_name self.display end def referral_link url "https://www.dailycred.com/r/#{self.uid}?redirect_uri=#{url}" end def reset_password get_client.reset_password self.email end def update_from_dailycred dc bad = ['updated_at', 'created_at'] dc.each do |k,v| self.send("#{k}=", v) if self.respond_to?(k) and !bad.include?(k.to_s) end save! end def fire_event key, val="" get_client.event self.uid, key, val end def get_client @dailycred ||= Dailycred::Client.new Rails.configuration.DAILYCRED_CLIENT_ID, Rails.configuration.DAILYCRED_SECRET_KEY end def connect_path provider "/auth/dailycred?identity_provider=#{provider.to_s}" end end end require 'active_record' ActiveRecord::Base.extend ActsAsDailycred
Version data entries
4 entries across 4 versions & 1 rubygems