edm_train 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/edm_train/artist.rb +14 -0
- data/lib/edm_train/client.rb +64 -0
- data/lib/edm_train/events.rb +129 -0
- data/lib/edm_train/locations.rb +66 -0
- data/lib/edm_train/venue.rb +18 -0
- data/lib/edm_train.rb +17 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd174d7c3a05ddadf9d188db700de939f99c040a1e66b7434ec67e1504cce2db
|
4
|
+
data.tar.gz: 6341fd037b6289af39265e2c98ac825aca768d9094632e986d14ea6e9a2b6112
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d2be861aa799fda6f3390f3babb36634c86fe573ff0045fc28f53bec19baaae9d803117309bc6019db4dfb47b2fdc3f753272e5d878b444570ea6944beb472f
|
7
|
+
data.tar.gz: 38e36b693c9bc8a82f39dbfffcf12147a5d6f8d4408d53f82270a4659c149d45050eb6f2bc6eff9e7b5ed927dad686d376fb68292dc0d315e7c679356478087c
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EdmTrain
|
4
|
+
class Artist
|
5
|
+
attr_reader :id, :name, :link, :b2b_ind
|
6
|
+
|
7
|
+
def initialize(raw_artist)
|
8
|
+
@id = raw_artist['id']
|
9
|
+
@name = raw_artist['name']
|
10
|
+
@link = raw_artist['link']
|
11
|
+
@b2b_ind = raw_artist['b2bInd']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# An API Client for EdmTrain.com
|
7
|
+
module EdmTrain
|
8
|
+
# Helper method to return the client.
|
9
|
+
# @return [EdmTrain::Client] the base client
|
10
|
+
def self.client
|
11
|
+
@client ||= Client.new
|
12
|
+
end
|
13
|
+
|
14
|
+
# EdmTrain API key getter
|
15
|
+
# @return [String] the API key
|
16
|
+
def self.api_key
|
17
|
+
@api_key
|
18
|
+
end
|
19
|
+
|
20
|
+
# EdmTrain API key setter
|
21
|
+
# @param [String] key the API key
|
22
|
+
# @return [String] the API key
|
23
|
+
def self.api_key=(key)
|
24
|
+
@api_key = key
|
25
|
+
end
|
26
|
+
|
27
|
+
# Error for API errors
|
28
|
+
# @return [StandardError] the API error
|
29
|
+
class APIError < StandardError; end
|
30
|
+
|
31
|
+
# Error for missing API key
|
32
|
+
# @return [StandardError] the missing API key error
|
33
|
+
class MissingKeyError < StandardError
|
34
|
+
def initialize
|
35
|
+
super 'Must set EdmTrain.api_key before making requests'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Client for the EdmTrain API
|
40
|
+
class Client
|
41
|
+
# Perform a GET request to the EdmTrain API
|
42
|
+
# @param [String] path the path to the API endpoint
|
43
|
+
# @param [Hash] params the query parameters
|
44
|
+
# @raise [MissingKeyError] if the API key is not set
|
45
|
+
# @return [Hash] the response from the API
|
46
|
+
def get(path, params = {})
|
47
|
+
raise MissingKeyError unless EdmTrain.api_key
|
48
|
+
|
49
|
+
params[:client] = EdmTrain.api_key
|
50
|
+
result = JSON.parse(URI.open("https://edmtrain.com/api/#{path}?#{to_query(params)}").read)
|
51
|
+
raise APIError, result['message'] unless result['success']
|
52
|
+
|
53
|
+
result['data']
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
# Helper method to convert a hash to a query string
|
58
|
+
# @param [Hash] params the query parameters
|
59
|
+
# @return [String] the query string
|
60
|
+
def to_query(params)
|
61
|
+
URI.encode_www_form(params)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EdmTrain
|
4
|
+
# Events API
|
5
|
+
class Events
|
6
|
+
# Returns all known events
|
7
|
+
# @return [Array<Event>]
|
8
|
+
def self.all
|
9
|
+
EdmTrain.client.get('/events').map { |raw_event| Event.new(raw_event) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Search for events matching the given paramaters
|
13
|
+
# @param [Hash] params All fields are optional
|
14
|
+
# @option params [String] :eventName The name of the event, such as the name of a festival. Most events do not have names. If an event has no artists, then it will have a name.
|
15
|
+
# @option params [String] :artistIds One or more artist ids to retrieve events for. Artist ids can be determined by looking at an existing event where they are performing.
|
16
|
+
# @option params [String] :venueIds One or more venue ids to retrieve events for. Venue ids can be determined by looking at an existing event for that location.
|
17
|
+
# @option params [String] :locationIds One or more location ids to retrieve events for. Location ids can be determined by using the Locations API below. All live streams will be included unless livestreamInd is set to false.
|
18
|
+
# @option params [String] :startDate Retrieve events occurring at or after this local date (only future events will be returned).
|
19
|
+
# @option params [String] :endDate Retrieve events occurring at or before this local date.
|
20
|
+
# @option params [String] :createdStartDate Retrieve events added to Edmtrain at or after this UTC date (only future events will be returned).
|
21
|
+
# @option params [String] :createdEndDate Retrieve events added to Edmtrain at or before this UTC date.
|
22
|
+
# @option params [String] :festivalInd Set to true to return only festivals (default is not set). Set to false to exclude festivals.
|
23
|
+
# @option params [String] :livestreamInd Set to true to return only live streams (default is not set). Set to false to exclude live streams.
|
24
|
+
# @return [Array<Event>]
|
25
|
+
# @example
|
26
|
+
# EdmTrain::Events.find(locationIds: 102) # Find events near location 102 (Detroit, Michigan)
|
27
|
+
def self.find(params)
|
28
|
+
EdmTrain.client.get('/events', params).map { |raw_event| Event.new(raw_event) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Event object
|
33
|
+
# @attr_reader [Integer] id the event ID
|
34
|
+
# @attr_reader [String] link the link to the event on EdmTrain
|
35
|
+
# @attr_reader [Date] date the date of the event
|
36
|
+
# @attr_reader [Array<Artist>] artists the artists performing at the event
|
37
|
+
# @attr_reader [Venue] venue the venue of the event
|
38
|
+
class Event
|
39
|
+
attr_reader :id, :link, :ages, :date, :venue, :ages
|
40
|
+
# @param [Hash] raw_event the raw event from the API
|
41
|
+
# @note This is not intended to be called directly
|
42
|
+
def initialize(raw_event)
|
43
|
+
@id = raw_event['id']
|
44
|
+
@link = raw_event['link']
|
45
|
+
@date = Date.parse(raw_event['date'])
|
46
|
+
@start_time = raw_event['startTime']
|
47
|
+
@end_time = raw_event['endTime']
|
48
|
+
@artists = raw_event['artistList'].map {|artist| EdmTrain::Artist.new(artist)}
|
49
|
+
@venue = EdmTrain::Venue.new(raw_event['venue'])
|
50
|
+
@created_at = raw_event['createdDate']
|
51
|
+
@festival = raw_event['festivalInd']
|
52
|
+
@electronic = raw_event['electronicMusicInd']
|
53
|
+
@other_genre = raw_event['otherGenreInd']
|
54
|
+
@live_stream = raw_event['liveStreamInd']
|
55
|
+
@ages = raw_event['ages'] || ''
|
56
|
+
@name = raw_event['name']
|
57
|
+
@festival = raw_event['festivalInd']
|
58
|
+
@electronic = raw_event['electronicMusicInd']
|
59
|
+
@other_genre = raw_event['otherGenreInd']
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns a string representation of the event for event searching
|
63
|
+
# @return [DateTime]
|
64
|
+
def created_at
|
65
|
+
@created_at ? DateTime.parse(raw_event['createdDate']) : nil
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns an array of artists performing at the event
|
69
|
+
# @return [Array<Artist>]
|
70
|
+
def artists
|
71
|
+
@artists || []
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns the name of the event
|
75
|
+
# @return [String]
|
76
|
+
def name
|
77
|
+
@name || @artists.map(&:name).join(', ')
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the start time of the event. This only applies to livestreams
|
81
|
+
# @return [DateTime]
|
82
|
+
def start_time
|
83
|
+
@start_time ? DateTime.parse(@start_time) : date
|
84
|
+
end
|
85
|
+
|
86
|
+
# Returns the end time of the event. This only applies to livestreams
|
87
|
+
# @return [DateTime]
|
88
|
+
def end_time
|
89
|
+
@end_time ? DateTime.parse(@end_time) : date
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns true if the event is an electronic music event
|
93
|
+
# @return [Boolean]
|
94
|
+
def electronic?
|
95
|
+
@electronic
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns true if the event is an other genre event
|
99
|
+
# @return [Boolean]
|
100
|
+
def other_genre?
|
101
|
+
@other_genre
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns true if the event is a festival
|
105
|
+
# @return [Boolean]
|
106
|
+
def festival?
|
107
|
+
@festival
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns true if the event is a livestream
|
111
|
+
# @return [Boolean]
|
112
|
+
def live_stream?
|
113
|
+
@live_stream
|
114
|
+
end
|
115
|
+
|
116
|
+
# Returns an array of artist names performing at the event
|
117
|
+
# @return [Array<String>]
|
118
|
+
def artist_names
|
119
|
+
return "Unknown" unless @artists
|
120
|
+
@artists.map(&:name)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Returns a string representation of the event.
|
124
|
+
# @return [String]
|
125
|
+
def to_s
|
126
|
+
"#{name} - #{artist_names.join(', ')} at #{venue.name}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EdmTrain
|
4
|
+
# Locations API Calls
|
5
|
+
class Locations
|
6
|
+
# Returns all known locations
|
7
|
+
# @return [Array<Location>]
|
8
|
+
def self.all
|
9
|
+
EdmTrain.client.get('/locations').map do |raw_location|
|
10
|
+
Location.new(raw_location)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a location based on city and state
|
15
|
+
# @param [Hash] params
|
16
|
+
# @option params [String] :city the city
|
17
|
+
# @option params [String] :state the state
|
18
|
+
# @example
|
19
|
+
# EdmTrain::Locations.find(city: 'Detroit', state: 'Michigan')
|
20
|
+
# @return [Location]
|
21
|
+
def self.find(params = {})
|
22
|
+
Location.new(EdmTrain.client.get('/locations', city: params[:city], state: params[:state]).first)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Location object
|
27
|
+
# @attr_reader [Integer] id the location ID
|
28
|
+
# @attr_reader [String] city the city (e.g. 'Detroit')
|
29
|
+
# @attr_reader [String] state the state (e.g. 'Michigan')
|
30
|
+
# @attr_reader [String] state_code the state code (e.g. 'MI')
|
31
|
+
# @attr_reader [Float] latitude the latitude
|
32
|
+
# @attr_reader [Float] longitude the longitude
|
33
|
+
# @attr_reader [String] link the link to the location on EdmTrain
|
34
|
+
class Location
|
35
|
+
attr_reader :id, :city, :state, :state_code, :latitude, :longitude, :link
|
36
|
+
|
37
|
+
# @param [Hash] raw_location the raw location from the API
|
38
|
+
# @note This is not intended to be called directly
|
39
|
+
def initialize(raw_location)
|
40
|
+
@id = raw_location['id']
|
41
|
+
@city = raw_location['city']
|
42
|
+
@state = raw_location['state']
|
43
|
+
@state_code = raw_location['stateCode']
|
44
|
+
@latitude = raw_location['latitude']
|
45
|
+
@longitude = raw_location['longitude']
|
46
|
+
@link = raw_location['link']
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns all events for this location
|
50
|
+
# @return [Array<Event>]
|
51
|
+
def events
|
52
|
+
EdmTrain::Events.find(to_h)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns a string representation of the location for event searching
|
56
|
+
# @return [Hash]
|
57
|
+
def to_h
|
58
|
+
{
|
59
|
+
city: @city,
|
60
|
+
state: @state,
|
61
|
+
latitude: @latitude,
|
62
|
+
longitude: @longitude
|
63
|
+
}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EdmTrain
|
4
|
+
# Venue object
|
5
|
+
class Venue
|
6
|
+
attr_reader :id, :name, :location, :address, :state, :latitude, :longitude
|
7
|
+
|
8
|
+
def initialize(raw_venue)
|
9
|
+
@id = raw_venue['id']
|
10
|
+
@name = raw_venue['name']
|
11
|
+
@location = raw_venue['location']
|
12
|
+
@address = raw_venue['address']
|
13
|
+
@state = raw_venue['state']
|
14
|
+
@latitude = raw_venue['latitude']
|
15
|
+
@longitude = raw_venue['longitude']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/edm_train.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'edm_train/client'
|
4
|
+
require 'edm_train/events'
|
5
|
+
require 'edm_train/locations'
|
6
|
+
require 'edm_train/venue'
|
7
|
+
require 'edm_train/artist'
|
8
|
+
|
9
|
+
# An API Client for EdmTrain.com
|
10
|
+
# Search and discover EDM events near you.
|
11
|
+
# @example
|
12
|
+
# EdmTrain.api_key = 'YOUR_API_KEY'
|
13
|
+
# all_locations = EdmTrain::Locations.all
|
14
|
+
# detroit = EdmTrain::Locations.find(city: 'Detroit', state: 'Michigan')
|
15
|
+
# detroit_events = detroit.events
|
16
|
+
module EdmTrain
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edm_train
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Paterni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Pulls events from EdmTrain.com
|
14
|
+
email: james@ruby-code.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/edm_train.rb
|
20
|
+
- lib/edm_train/artist.rb
|
21
|
+
- lib/edm_train/client.rb
|
22
|
+
- lib/edm_train/events.rb
|
23
|
+
- lib/edm_train/locations.rb
|
24
|
+
- lib/edm_train/venue.rb
|
25
|
+
homepage:
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.4.22
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Pulls events from EdmTrain.com
|
48
|
+
test_files: []
|