Skip to content

Instantly share code, notes, and snippets.

@bryanmikaelian
Created March 6, 2013 20:55
Show Gist options
  • Save bryanmikaelian/5102969 to your computer and use it in GitHub Desktop.
Save bryanmikaelian/5102969 to your computer and use it in GitHub Desktop.
promos
module Jobs
class PromoRewardsJob
@queue = "social"
class << self
def perform(redeemable_promo_code_id)
@redeemable_promo_code = RedeemablePromoCode.find(redeemable_promo_code_id)
@user = @redeemable_promo_code.redeemed_by
@rewards = @redeemable_promo_code.promo_code.rewards
join_circle(@user.id, @rewards[:circle_id]) if @rewards[:circle_id]
end
def join_circle(user_id, circle_id)
@circle = Circle.find(circle_id)
if @circle.present? && !CircleUser.where(circle_id: circle_id, user_id: user_id).present?
if @circle.is_private?
@circle_admin = @circle.circle_users.where(admin: true).first
invitation = @circle.circle_invitations.new(user_id: user_id, invited_by_user_id: @circle_admin.user_id)
invitation.save
else
CircleUser.create(user_id: user_id, circle_id: circle_id, admin: false)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment