jam-cloud/web/app/controllers/api_affiliate_controller.rb

54 lines
1.5 KiB
Ruby

class ApiAffiliateController < ApiController
before_filter :api_signed_in_user, :except => [ :create ]
include ErrorsHelper
respond_to :json
def log
@log || Logging.logger[ApiAffiliateController]
end
def create
if current_user
# is this user already an affiliate? Then kick this back
if current_user.affiliate_partner
render :json => simple_error('affiliate_partner', 'You are already an affiliate.'), status: 422
return
else
@partner = AffiliatePartner.create_with_web_params(current_user, params)
respond_with_model(@partner)
return
end
else
@partner = AffiliatePartner.create_with_web_params(nil, params)
respond_with_model(@partner)
end
end
def traffic_index
data = AffiliateTrafficTotal.index(current_user, params)
@traffics, @next = data[0], data[1]
render "api_affiliates/traffic_index", :layout => nil
end
def monthly_index
data = AffiliateMonthlyPayment.index(current_user, params)
@monthlies, @next = data[0], data[1]
render "api_affiliates/monthly_index", :layout => nil
end
def quarterly_index
data = AffiliateQuarterlyPayment.index(current_user, params)
@quarterlies, @next = data[0], data[1]
render "api_affiliates/quarterly_index", :layout => nil
end
def payment_index
data = AffiliatePayment.index(current_user, params)
@payments, @next = data[0], data[1]
render "api_affiliates/payment_index", :layout => nil
end
end