Class: RailsSignUp::Model::Race

Inherits:
Record
  • Object
show all
Defined in:
lib/railsSignUp/model/race.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#initialize

Constructor Details

This class inherits a constructor from RailsSignUp::Record

Instance Attribute Details

#access_tokenObject

access token for oauth



33
34
35
# File 'lib/railsSignUp/model/race.rb', line 33

def access_token
  @access_token
end

#api_keyObject (readonly)

api_key



35
36
37
# File 'lib/railsSignUp/model/race.rb', line 35

def api_key
  @api_key
end

#api_secretObject (readonly)

api_secret



37
38
39
# File 'lib/railsSignUp/model/race.rb', line 37

def api_secret
  @api_secret
end

#cityObject (readonly)

city of race



23
24
25
# File 'lib/railsSignUp/model/race.rb', line 23

def city
  @city
end

#country_codeObject (readonly)

country of race



29
30
31
# File 'lib/railsSignUp/model/race.rb', line 29

def country_code
  @country_code
end

#descriptionObject (readonly)

description



9
10
11
# File 'lib/railsSignUp/model/race.rb', line 9

def description
  @description
end

#eventsObject

list of events of races



31
32
33
# File 'lib/railsSignUp/model/race.rb', line 31

def events
  @events
end

#idObject (readonly)

race id



5
6
7
# File 'lib/railsSignUp/model/race.rb', line 5

def id
  @id
end

#is_draft_raceObject (readonly)

if is a draft race



19
20
21
# File 'lib/railsSignUp/model/race.rb', line 19

def is_draft_race
  @is_draft_race
end

#is_registration_openObject (readonly)

(BOOL) if registration is open



17
18
19
# File 'lib/railsSignUp/model/race.rb', line 17

def is_registration_open
  @is_registration_open
end

#last_dateObject (readonly)

last date race took place



15
16
17
# File 'lib/railsSignUp/model/race.rb', line 15

def last_date
  @last_date
end

#nameObject (readonly)

name of race



7
8
9
# File 'lib/railsSignUp/model/race.rb', line 7

def name
  @name
end

#next_dateObject (readonly)

next date race takes place



13
14
15
# File 'lib/railsSignUp/model/race.rb', line 13

def next_date
  @next_date
end

#stateObject (readonly)

state of race



25
26
27
# File 'lib/railsSignUp/model/race.rb', line 25

def state
  @state
end

#streetObject (readonly)

street of race



21
22
23
# File 'lib/railsSignUp/model/race.rb', line 21

def street
  @street
end

#urlObject (readonly)

runsignup url for race



11
12
13
# File 'lib/railsSignUp/model/race.rb', line 11

def url
  @url
end

#zip_codeObject (readonly)

zip code of race



27
28
29
# File 'lib/railsSignUp/model/race.rb', line 27

def zip_code
  @zip_code
end

Instance Method Details

#add_event(event) ⇒ Object



74
75
76
77
# File 'lib/railsSignUp/model/race.rb', line 74

def add_event event
  self.events = [] if self.events.nil?
  self.events << event
end

#get_eventsObject

Retrieve all events for a race

Raises:

Author:

  • Khang Le



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/railsSignUp/model/race.rb', line 42

def get_events
  response = self.access_token.get("/rest/race/#{self.id}/?format=json&race_id=#{self.id}&api_key=#{self.api_key}&api_secret=#{self.api_secret}")
  json_response = JSON.parse(response.body)
  
				raise RailsSignUp::RaceError, "RailsSignUp race.get Error: #{json_response['error']['error_code']} - #{json_response['error']['error_msg']}" unless json_response['error'].nil?
  
  json_response['race']['events'].each do |event|
    _event = RailsSignUp::Model::Event.new(
      :id => event['id'],
      :name => event['name'],
      :details => event['details'],
      :start_time =>  event['start_time'],
      :registration_opens => event['registration_opens'],
      :event_type => event['event_type'],
      :distance => event['distance'],
      :volunteer => event['volunteer'],
      :require_dob => event['require_dob'],
      :require_phone => event['require_phone'],
      :give_away => event['give_away']
    )
    event['registration_periods'].each do |period|
      _period = RailsSignUp::Model::RegistrationPeriod.new(
        :registration_opens => period['registration_opens'],
        :registration_closes => period['registration_closes'],
        :race_fee => period['race_fee']
      )
      _event.add_registration_period _period
    end
    self.add_event _event
  end
end