class RailsRunSignUp::Users
Attributes
users[RW]
Public Class Methods
new(session)
click to toggle source
# File lib/RailsRunSignUp/users.rb, line 9 def initialize session raise RailsRunSignUp::SessionError, "Invalid session (session cannot be nil)" if session.nil? @users = [] @access_token = session.access_token @api_key = session.api_key @api_secret = session.api_secret end
Public Instance Methods
add_user(user)
click to toggle source
# File lib/RailsRunSignUp/users.rb, line 84 def add_user user self.users = [] if self.users.nil? self.users << user end
get_participants(opts = {})
click to toggle source
get users from runsignup events
@author Khang Le @param race_id The race's id @param event_id The event's id @param results_per_page The amount of results to show per page @param page The page number to view participants on @param after_registration_id Get registrations after the given registration id
# File lib/RailsRunSignUp/users.rb, line 26 def get_participants opts = {} raise RailsRunSignUp::ParticipantsError, "Parameter missing {race_id}" if opts[:race_id].nil? raise RailsRunSignUp::ParticipantsError, "Parameter missing {event_id}" if opts[:event_id].nil? response = @access_token.get("/Rest/race/#{opts[:race_id]}/participants/?format=json&#{opts.map{|k, v| "#{k}=#{v}"}.join('&')}") error_response = JSON.parse(response.body) json_response = JSON.parse(response.body).first if error_response.is_a?(Hash) raise RailsRunSignUp::ParticipantsError, "RunSignUp participants.get Error: #{error_response['error']['error_code']} - #{error_response['error']['error_msg']}" unless error_response['error'].nil? end parse_json json_response end
parse_json(json_response, opts = {})
click to toggle source
# File lib/RailsRunSignUp/users.rb, line 41 def parse_json json_response, opts = {} users = [] return if json_response['participants'].nil? json_response['participants'].each do |participant| _participant = RailsRunSignUp::Model::User.new( :user_id => participant['user']['user_id'], :first_name => participant['user']['first_name'], :last_name => participant['user']['last_name'], :email => participant['user']['email'], :street => participant['user']['address']['street'], :city => participant['user']['address']['city'], :state => participant['user']['address']['state'], :zipcode => participant['user']['address']['zipcode'], :country_code => participant['user']['address']['country_code'], :dob => participant['user']['dob'], :gender => participant['user']['gender'], :phone => participant['user']['phone'], :profile_image_url => participant['user']['profile_image_url'], :registration_id => participant['registration_id'], :bib_num => participant['bib_num'], :chip_num => participant['chip_num'], :age => participant['age'], :registration_date => participant['registration_date'], :last_modified => participant['last_modified'], # :imported => participant['imported'], :processing_fee => participant['processing_fee'], :processing_fee_paid_by_user => participant['processing_fee_paid_by_user'], :processing_fee_paid_by_race => participant['processing_fee_paid_by_race'], :partner_fee => participant['partner_fee'], :affiliate_profit => participant['affiliate_profit'], :extra_fees => participant['extra_fees'], :amount_paid => participant['amount_paid'], :usatf_discount_amount_in_cents => participant['usatf_discount_amount_in_cents'], # :usatf_discount_additional_field => participant['usatf_discount_additional_field'], # :giveaway => participant['giveaway'] ) self.add_user _participant end self.users end