Sha256: 6f06fb2ab24188e34a86011a6f8be0056cf486d7e813c7429fc6588111467d7e

Contents?: true

Size: 708 Bytes

Versions: 2

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

require_relative 'api_wrapper'

module Stash
  module Rewards
    class EnrolUserInCampaign < ApiWrapper
      def call(campaign_id:, user_identifier:)
        api_response = api_wrapper.post("campaigns/#{campaign_id}/users") do |req|
          req.body = user_payload(user_identifier)
        end

        response = Stash::Rewards::Response.new(api_response)
        raise Stash::Rewards::Error, response.error_message if response.error?

        response
      rescue Faraday::Error => e
        raise Stash::Rewards::Error, e.message
      end

      private

      def user_payload(user_identifier)
        [{ refId: user_identifier }].to_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stash-rewards-0.0.4 lib/stash/rewards/enrol_user_in_campaign.rb
stash-rewards-0.0.3 lib/stash/rewards/enrol_user_in_campaign.rb