ejaydj 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9812683c836ac5484095c4ea461f544d38ffa4ec
4
- data.tar.gz: 8934f32b70874c13c2222c3ae2c75d9fdfcb8cd5
3
+ metadata.gz: d5060bcb5ae6ef7ae2cf3a75627164313c76b918
4
+ data.tar.gz: 18994145135deecba2939b136452962cc60feeb9
5
5
  SHA512:
6
- metadata.gz: bb76809bf2a7ab1e78b409598daae49b38baba9c4b60f39018998d48c95d925cb1e48c4a304aaaf72e815f434ee7b4872b2a8aaf1b9e3fe069ae22182f7c4460
7
- data.tar.gz: f8588a303c859e12403c7fa191780ae0ca8fbb0ba447567d33759109fce32c1510e58dcb833c141ad7005e1c64a64bf8d9550da1b20e59255ce01addbd2d1d54
6
+ metadata.gz: 852b21e0f4c8ddf64906343242cec4fef702376e315480dadfbb7c32feaaec73cbbaedaa025c165d07eceaccd9d76bbb440ec8aa365349f4cf01124f3c123c97
7
+ data.tar.gz: 9762aac22846b2805e9dd1c6aca7fa650b7e6ca2b8155fd863f548f995dfcf989363bbcd11386e2c5787b7c697c50d3651bdb6b1898f85d33e049149e1f6ee7e
data/README.md CHANGED
@@ -21,8 +21,8 @@ Or install it yourself as:
21
21
  ## Configuration
22
22
 
23
23
  ### Prerequisites
24
- 1. [Twitter consumer and access token](https://developer.spotify.com/my-applications/#!/)
25
- 2. [Spotify client id and secret](https://apps.twitter.com/)
24
+ 1. [Spotify client id and secret](https://apps.twitter.com/)
25
+ 2. [Twitter consumer and access token](https://developer.spotify.com/my-applications/#!/)
26
26
 
27
27
  ### Set the Spotify and Twitter credentials in your new TwitterBot DJ then add your playlists
28
28
 
@@ -1,8 +1,11 @@
1
1
  require 'ejaydj/services/playlist_service'
2
2
  require 'ejaydj/spotify/client'
3
+ require 'ejaydj/mixins'
3
4
 
4
5
  module Ejaydj
5
6
  class Dj
7
+ include Mixins
8
+
6
9
  PLAYLIST_SCHEDULE = {
7
10
  600..1159 => :morning_playlists, # 6AM - 12PM
8
11
  1200..1759 => :noon_playlists, # 12PM - 5:59PM
@@ -20,7 +23,6 @@ module Ejaydj
20
23
  :night_playlists,
21
24
  :late_night_playlists
22
25
 
23
-
24
26
  def initialize(attributes={})
25
27
  instantiate_variables_from attributes
26
28
  yield self if block_given?
@@ -36,23 +38,20 @@ module Ejaydj
36
38
 
37
39
  def reload!
38
40
  @playlists = all_playlists
39
- @playlists.each {|playlist| playlist.reload!}
41
+ @playlists.each(&:reload!)
40
42
  end
41
43
 
42
44
  private
43
45
 
44
46
  def current_playlist(time)
45
47
  playlist_name = scheduled_playlist(time.strftime('%k%M').to_i)
46
- playlist = playlists.select do |playlist|
48
+ playlist = playlists.find do |playlist|
47
49
  playlist.name == playlist_name
48
- end.first
50
+ end
49
51
  end
50
52
 
51
53
  def scheduled_playlist(time)
52
- scheduled_playlists = PLAYLIST_SCHEDULE.select do |schedule, value|
53
- schedule.cover? time
54
- end.values.first
55
-
54
+ scheduled_playlists = PLAYLIST_SCHEDULE.select {|sched| sched.cover? time}.values[0]
56
55
  send(scheduled_playlists).sample
57
56
  end
58
57
 
@@ -71,9 +70,5 @@ module Ejaydj
71
70
  client_id: music_client_id,
72
71
  client_secret: music_client_secret)
73
72
  end
74
-
75
- def instantiate_variables_from(attributes)
76
- attributes.each {|key, val| instance_variable_set(:"@#{key}", val) }
77
- end
78
73
  end
79
74
  end
@@ -0,0 +1,10 @@
1
+ module Ejaydj
2
+ module Mixins
3
+
4
+ protected
5
+
6
+ def instantiate_variables_from(attributes)
7
+ attributes.each {|key, val| instance_variable_set(:"@#{key}", val) }
8
+ end
9
+ end
10
+ end
@@ -1,21 +1,18 @@
1
1
  require 'ejaydj/services/track_service'
2
+ require 'ejaydj/mixins'
2
3
 
3
4
  module Ejaydj
4
5
  class Playlist
5
- attr_reader :id,
6
- :user_id,
7
- :name,
8
- :url,
9
- :number_of_tracks
6
+ include Mixins
10
7
 
11
- def initialize(attributes={})
12
- @id = attributes[:id]
13
- @user_id = attributes[:user_id]
14
- @name = attributes[:name]
15
- @url = attributes[:url]
16
- @number_of_tracks = attributes[:number_of_tracks]
8
+ attr_accessor :id,
9
+ :user_id,
10
+ :name,
11
+ :url,
12
+ :number_of_tracks
17
13
 
18
- @music_client = attributes[:music_client]
14
+ def initialize(attributes={})
15
+ instantiate_variables_from attributes
19
16
  end
20
17
 
21
18
  def next_track
@@ -1,5 +1,9 @@
1
+ require 'ejaydj/mixins'
2
+
1
3
  module Ejaydj
2
4
  class Track
5
+ include Mixins
6
+
3
7
  attr_accessor :name,
4
8
  :album,
5
9
  :artist,
@@ -8,13 +12,7 @@ module Ejaydj
8
12
  :playlist
9
13
 
10
14
  def initialize(attributes={})
11
- @id = attributes[:id]
12
- @name = attributes[:name]
13
- @album = attributes[:album]
14
- @artist = attributes[:artist]
15
- @playlist = attributes[:playlist]
16
- @duration_ms = attributes[:duration_ms]
17
- @url = attributes[:url]
15
+ instantiate_variables_from attributes
18
16
  end
19
17
  end
20
18
  end
@@ -1,3 +1,3 @@
1
1
  module Ejaydj
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ejaydj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ejay Canaria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2015-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -140,6 +140,7 @@ files:
140
140
  - lib/ejaydj.rb
141
141
  - lib/ejaydj/dj.rb
142
142
  - lib/ejaydj/djs/twitter_bot.rb
143
+ - lib/ejaydj/mixins.rb
143
144
  - lib/ejaydj/playlist.rb
144
145
  - lib/ejaydj/services/playlist_service.rb
145
146
  - lib/ejaydj/services/track_service.rb