Class: SpreeCmCommissioner::VotingCredits::ClaimFreeVotes
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::VotingCredits::ClaimFreeVotes
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb
Instance Attribute Summary collapse
-
#show ⇒ Object
readonly
Returns the value of attribute show.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#votable_id ⇒ Object
readonly
Returns the value of attribute votable_id.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(show:, user:, tenant_id:, votable_id: nil) ⇒ ClaimFreeVotes
constructor
A new instance of ClaimFreeVotes.
Constructor Details
#initialize(show:, user:, tenant_id:, votable_id: nil) ⇒ ClaimFreeVotes
Returns a new instance of ClaimFreeVotes.
16 17 18 19 20 21 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 16 def initialize(show:, user:, tenant_id:, votable_id: nil) @show = show @user = user @tenant_id = tenant_id @votable_id = votable_id end |
Instance Attribute Details
#show ⇒ Object (readonly)
Returns the value of attribute show.
14 15 16 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 14 def show @show end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
14 15 16 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 14 def tenant_id @tenant_id end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
14 15 16 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 14 def user @user end |
#votable_id ⇒ Object (readonly)
Returns the value of attribute votable_id.
14 15 16 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 14 def votable_id @votable_id end |
Instance Method Details
#call ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/spree_cm_commissioner/voting_credits/claim_free_votes.rb', line 23 def call return success(nil) unless effective_limit_type return failure(nil, 'votable_id is required for per_episode/per_voting_session') if requires_votable_id? && votable_id.blank? key_votable_id = effective_limit_type == 'per_episode' ? resolved_voting_session.episode_id : votable_id idempotency_key = show.free_vote_idempotency_key(user_id: user.id, votable_id: key_votable_id, limit_type: effective_limit_type) return failure(nil, 'Free votes have already been claimed') if already_claimed?(idempotency_key) amount = effective_limit.to_i return failure(nil, "Free votes are not available for #{show.voting_credit_scope}") if amount <= 0 credit = grant_votes(amount: amount, idempotency_key: idempotency_key) success(credit) rescue ActiveRecord::RecordNotUnique failure(nil, 'Free votes have already been claimed') rescue StandardError => e failure(nil, e.) end |