|
1 | 1 | class Event
|
2 | 2 | RAILSBRIDGE_ORGANIZATION_ID = 1
|
3 | 3 |
|
4 |
| - def self.sorted_events(state = nil, options = {}) |
5 |
| - events = (state == :upcoming) ? upcoming_events(options) : past_events(options) |
6 |
| - sort_by_starts_at(events) |
7 |
| - end |
| 4 | + class << self |
| 5 | + def sorted_events(state = nil, options = {}) |
| 6 | + events = (state == :upcoming) ? upcoming_events(options) : past_events(options) |
| 7 | + sort_by_starts_at(events) |
| 8 | + end |
8 | 9 |
|
9 |
| - private |
| 10 | + private |
10 | 11 |
|
11 |
| - def self.of_type(type, options = {}) |
12 |
| - events = begin |
13 |
| - fetch_json({type: type}.merge(options)) |
14 |
| - rescue StandardError => e |
15 |
| - puts "Error fetching events from BridgeTroll: #{e.message}" |
| 12 | + def of_type(type, options = {}) |
| 13 | + events = begin |
| 14 | + fetch_json({type: type}.merge(options)) |
| 15 | + rescue StandardError => e |
| 16 | + puts "Error fetching events from BridgeTroll: #{e.message}" |
| 17 | + end |
| 18 | + events || [] |
16 | 19 | end
|
17 |
| - events || [] |
18 |
| - end |
19 | 20 |
|
20 |
| - def self.upcoming_events(options = {}) |
21 |
| - of_type('upcoming', options) |
22 |
| - end |
| 21 | + def upcoming_events(options = {}) |
| 22 | + of_type('upcoming', options) |
| 23 | + end |
23 | 24 |
|
24 |
| - def self.past_events(options = {}) |
25 |
| - of_type('past', options).select { |event| event['workshop'] } |
26 |
| - end |
| 25 | + def past_events(options = {}) |
| 26 | + of_type('past', options).select { |event| event['workshop'] } |
| 27 | + end |
27 | 28 |
|
28 |
| - def self.sort_by_starts_at(events) |
29 |
| - events.sort_by { |event| event['sessions'].first['starts_at'].to_time } |
30 |
| - end |
| 29 | + def sort_by_starts_at(events) |
| 30 | + events.sort_by { |event| event['sessions'].first['starts_at'].to_time } |
| 31 | + end |
31 | 32 |
|
32 |
| - def self.fetch_json(options) |
33 |
| - uri = URI::parse(BRIDGETROLL_URL) |
34 |
| - http = Net::HTTP.new(uri.host, uri.port) |
35 |
| - http.use_ssl = true |
36 |
| - response = http.send(:get, "/events.json?#{options.to_query}") |
37 |
| - JSON.parse(response.body) |
| 33 | + def fetch_json(options) |
| 34 | + uri = URI::parse(BRIDGETROLL_URL) |
| 35 | + http = Net::HTTP.new(uri.host, uri.port) |
| 36 | + http.use_ssl = true |
| 37 | + response = http.send(:get, "/events.json?#{options.to_query}") |
| 38 | + JSON.parse(response.body) |
| 39 | + end |
38 | 40 | end
|
39 | 41 | end
|
0 commit comments