ejaydj 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +1 -1
- data/lib/ejaydj/djs/twitter_bot.rb +4 -5
- data/lib/ejaydj/services/track_service.rb +7 -6
- data/lib/ejaydj/track.rb +2 -0
- data/lib/ejaydj/version.rb +1 -1
- data/spec/dj_spec.rb +4 -2
- data/spec/djs/twitter_bot_spec.rb +4 -3
- data/spec/playlist_spec.rb +4 -2
- data/spec/services/track_service_spec.rb +4 -2
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9812683c836ac5484095c4ea461f544d38ffa4ec
         | 
| 4 | 
            +
              data.tar.gz: 8934f32b70874c13c2222c3ae2c75d9fdfcb8cd5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bb76809bf2a7ab1e78b409598daae49b38baba9c4b60f39018998d48c95d925cb1e48c4a304aaaf72e815f434ee7b4872b2a8aaf1b9e3fe069ae22182f7c4460
         | 
| 7 | 
            +
              data.tar.gz: f8588a303c859e12403c7fa191780ae0ca8fbb0ba447567d33759109fce32c1510e58dcb833c141ad7005e1c64a64bf8d9550da1b20e59255ce01addbd2d1d54
         | 
    
        data/README.md
    CHANGED
    
    | @@ -54,7 +54,7 @@ Given a `dj` object from the above configuration, tweeting your music is as simp | |
| 54 54 | 
             
            ```
         | 
| 55 55 |  | 
| 56 56 | 
             
            The tweet format will look like:
         | 
| 57 | 
            -
            `NP: {song} by {artist} from  | 
| 57 | 
            +
            `NP: {song} by {artist} from playlist: {playlist_url}`
         | 
| 58 58 | 
             
            Each songs is based on the provided time (default is current time). It will automatically lookup for tracks in the scheduled playlists.
         | 
| 59 59 |  | 
| 60 60 | 
             
            ## Playlists Schedule
         | 
| @@ -10,8 +10,8 @@ module Ejaydj | |
| 10 10 | 
             
                                :twitter_access_token_secret,
         | 
| 11 11 | 
             
                                :twitter_client
         | 
| 12 12 |  | 
| 13 | 
            -
                  MAX_SONG_LENGTH   =  | 
| 14 | 
            -
                  MAX_ARTIST_LENGTH =  | 
| 13 | 
            +
                  MAX_SONG_LENGTH   = 40
         | 
| 14 | 
            +
                  MAX_ARTIST_LENGTH = 40
         | 
| 15 15 |  | 
| 16 16 | 
             
                  def initialize(attributes={}, &block)
         | 
| 17 17 | 
             
                    super(attributes, &block)
         | 
| @@ -22,14 +22,13 @@ module Ejaydj | |
| 22 22 | 
             
                    tweet = tweet_string
         | 
| 23 23 |  | 
| 24 24 | 
             
                    twitter_client.update(tweet)
         | 
| 25 | 
            -
             | 
| 26 25 | 
             
                    {message: tweet, song: @song}
         | 
| 27 26 | 
             
                  end
         | 
| 28 27 |  | 
| 29 28 | 
             
                  private
         | 
| 30 29 |  | 
| 31 30 | 
             
                  def tweet_string
         | 
| 32 | 
            -
                    tweet_string = ("NP: #{@song.name} by #{@song.artist}  | 
| 31 | 
            +
                    tweet_string = ("NP: #{@song.name} by #{@song.artist}: #{shorten_url(@song.url)} | playlist: #{shorten_url(@song.playlist.url)}")
         | 
| 33 32 | 
             
                    shorten_tweet(tweet_string)
         | 
| 34 33 | 
             
                  end
         | 
| 35 34 |  | 
| @@ -39,7 +38,7 @@ module Ejaydj | |
| 39 38 | 
             
                    @song.name    = "#{@song.name[0..MAX_SONG_LENGTH]}..." if @song.name.length > MAX_SONG_LENGTH
         | 
| 40 39 | 
             
                    @song.artist  = "#{@song.artist[0..MAX_ARTIST_LENGTH]}..." if @song.artist.length > MAX_ARTIST_LENGTH
         | 
| 41 40 |  | 
| 42 | 
            -
                    "NP: #{@song.name} by #{@song.artist} | #{shorten_url(@song.playlist.url)}"
         | 
| 41 | 
            +
                    "NP: #{@song.name} by #{@song.artist}: #{shorten_url(@song.url)} | #{shorten_url(@song.playlist.url)}"
         | 
| 43 42 | 
             
                  end
         | 
| 44 43 |  | 
| 45 44 | 
             
                  def shorten_url(url)
         | 
| @@ -10,13 +10,14 @@ module Ejaydj | |
| 10 10 | 
             
                  def all
         | 
| 11 11 | 
             
                    response_items = @music_client.playlist_tracks(user_id: @user_id, playlist_id: @playlist_id)
         | 
| 12 12 |  | 
| 13 | 
            -
                    response_items.map do | | 
| 13 | 
            +
                    response_items.map do |item|
         | 
| 14 14 | 
             
                      Track.new(
         | 
| 15 | 
            -
                        id:             | 
| 16 | 
            -
                        name:           | 
| 17 | 
            -
                        album:          | 
| 18 | 
            -
                        artist:         | 
| 19 | 
            -
                        duration_ms:    | 
| 15 | 
            +
                        id:            item["track"]["id"],
         | 
| 16 | 
            +
                        name:          item["track"]["name"],
         | 
| 17 | 
            +
                        album:         item["track"]["album"]["name"],
         | 
| 18 | 
            +
                        artist:        item["track"]["artists"][0]["name"],
         | 
| 19 | 
            +
                        duration_ms:   item["track"]["duration_ms"],
         | 
| 20 | 
            +
                        url:           item["track"]["external_urls"]["spotify"]
         | 
| 20 21 | 
             
                      )
         | 
| 21 22 | 
             
                    end
         | 
| 22 23 | 
             
                  end
         | 
    
        data/lib/ejaydj/track.rb
    CHANGED
    
    | @@ -4,6 +4,7 @@ module Ejaydj | |
| 4 4 | 
             
                              :album,
         | 
| 5 5 | 
             
                              :artist,
         | 
| 6 6 | 
             
                              :duration_ms,
         | 
| 7 | 
            +
                              :url,
         | 
| 7 8 | 
             
                              :playlist
         | 
| 8 9 |  | 
| 9 10 | 
             
                def initialize(attributes={})
         | 
| @@ -13,6 +14,7 @@ module Ejaydj | |
| 13 14 | 
             
                  @artist        = attributes[:artist]
         | 
| 14 15 | 
             
                  @playlist      = attributes[:playlist]
         | 
| 15 16 | 
             
                  @duration_ms   = attributes[:duration_ms]
         | 
| 17 | 
            +
                  @url           = attributes[:url]
         | 
| 16 18 | 
             
                end
         | 
| 17 19 | 
             
              end
         | 
| 18 20 | 
             
            end
         | 
    
        data/lib/ejaydj/version.rb
    CHANGED
    
    
    
        data/spec/dj_spec.rb
    CHANGED
    
    | @@ -30,7 +30,8 @@ RSpec.describe Ejaydj::Dj do | |
| 30 30 | 
             
                                "name"          => "Track 1",
         | 
| 31 31 | 
             
                                "album"         => {"name" => "Album 1"},
         | 
| 32 32 | 
             
                                "artists"       => [{"name" => "Artist 1"}],
         | 
| 33 | 
            -
                                "playlist_id"   => 1
         | 
| 33 | 
            +
                                "playlist_id"   => 1,
         | 
| 34 | 
            +
                                "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 34 35 | 
             
                               }}
         | 
| 35 36 | 
             
                ]
         | 
| 36 37 | 
             
              end
         | 
| @@ -93,7 +94,8 @@ RSpec.describe Ejaydj::Dj do | |
| 93 94 | 
             
                                               "name"          => "Track 2",
         | 
| 94 95 | 
             
                                               "album"         => {"name" => "Album 2"},
         | 
| 95 96 | 
             
                                               "artists"       => [{"name" => "Artist 2"}],
         | 
| 96 | 
            -
                                               "playlist_id"   => 2
         | 
| 97 | 
            +
                                               "playlist_id"   => 2,
         | 
| 98 | 
            +
                                               "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 97 99 | 
             
                                 }}
         | 
| 98 100 | 
             
                  dj.reload!
         | 
| 99 101 | 
             
                  expect(dj.playlists.first.tracks.count).to eq(track_items.count)
         | 
| @@ -36,12 +36,13 @@ RSpec.describe Ejaydj::Djs::TwitterBot do | |
| 36 36 | 
             
                  {"track" => { "id"            => 1,
         | 
| 37 37 | 
             
                                "name"          => "Track 1",
         | 
| 38 38 | 
             
                                "album"         => {"name" => "Album 1"},
         | 
| 39 | 
            -
                                "artists"       => [{"name" => "Artist 1"}]
         | 
| 39 | 
            +
                                "artists"       => [{"name" => "Artist 1"}],
         | 
| 40 | 
            +
                                "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 40 41 | 
             
                               }}
         | 
| 41 42 | 
             
                ]
         | 
| 42 43 | 
             
              end
         | 
| 43 44 |  | 
| 44 | 
            -
              let(:shorten_url) { 'http://goo.gl' }
         | 
| 45 | 
            +
              let(:shorten_url) { 'http://goo.gl/Abc123' }
         | 
| 45 46 |  | 
| 46 47 | 
             
              before do
         | 
| 47 48 | 
             
                allow(music_client).to receive(:user_playlists).and_return(playlist_items)
         | 
| @@ -54,7 +55,7 @@ RSpec.describe Ejaydj::Djs::TwitterBot do | |
| 54 55 | 
             
                  tweet = twitter_bot_dj.tweet_me_a_song(time: Time.new(2014, 11, 20, 7, 0, 0))
         | 
| 55 56 | 
             
                  song = tweet[:song]
         | 
| 56 57 |  | 
| 57 | 
            -
                  expect(tweet[:message]).to eq("NP: #{song.name} by #{song.artist}  | 
| 58 | 
            +
                  expect(tweet[:message]).to eq("NP: #{song.name} by #{song.artist}: #{shorten_url} | playlist: #{shorten_url}")
         | 
| 58 59 | 
             
                end
         | 
| 59 60 |  | 
| 60 61 | 
             
                context "when tweet string is over 140" do
         | 
    
        data/spec/playlist_spec.rb
    CHANGED
    
    | @@ -15,7 +15,8 @@ RSpec.describe Ejaydj::Playlist do | |
| 15 15 | 
             
                                "name"          => "Track 1",
         | 
| 16 16 | 
             
                                "album"         => {"name" => "Album 1"},
         | 
| 17 17 | 
             
                                "artists"       => [{"name" => "Artist 1"}],
         | 
| 18 | 
            -
                                "playlist_id"   => 1
         | 
| 18 | 
            +
                                "playlist_id"   => 1,
         | 
| 19 | 
            +
                                "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 19 20 | 
             
                               }}
         | 
| 20 21 | 
             
                ]
         | 
| 21 22 | 
             
              end
         | 
| @@ -58,7 +59,8 @@ RSpec.describe Ejaydj::Playlist do | |
| 58 59 | 
             
                                               "name"          => "Track 2",
         | 
| 59 60 | 
             
                                               "album"         => {"name" => "Album 2"},
         | 
| 60 61 | 
             
                                               "artists"       => [{"name" => "Artist 2"}],
         | 
| 61 | 
            -
                                               "playlist_id"   => 2
         | 
| 62 | 
            +
                                               "playlist_id"   => 2,
         | 
| 63 | 
            +
                                               "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 62 64 | 
             
                                 }}
         | 
| 63 65 | 
             
                  playlist.reload!
         | 
| 64 66 | 
             
                  expect(playlist.tracks.count).to eq(track_items.count)
         | 
| @@ -13,14 +13,16 @@ RSpec.describe Ejaydj::Services::TrackService do | |
| 13 13 | 
             
                                "name"          => "Track 1",
         | 
| 14 14 | 
             
                                "album"         => {"name" => "Album 1"},
         | 
| 15 15 | 
             
                                "artists"       => [{"name" => "Artist 1"}],
         | 
| 16 | 
            -
                                "playlist_id"   => 1
         | 
| 16 | 
            +
                                "playlist_id"   => 1,
         | 
| 17 | 
            +
                                "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 17 18 | 
             
                               }},
         | 
| 18 19 |  | 
| 19 20 | 
             
                   {"track" => {"id"            => 2,
         | 
| 20 21 | 
             
                                "name"          => "Track 2",
         | 
| 21 22 | 
             
                                "album"         => {"name" => "Album 2"},
         | 
| 22 23 | 
             
                                "artists"       => [{"name" => "Artist 2"}],
         | 
| 23 | 
            -
                                "playlist_id"   => 2
         | 
| 24 | 
            +
                                "playlist_id"   => 2,
         | 
| 25 | 
            +
                                "external_urls" => {"spotify" => "http://www.spotify.com"}
         | 
| 24 26 | 
             
                               }}
         | 
| 25 27 | 
             
                  ]
         | 
| 26 28 | 
             
                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 | 
            +
              version: 0.0.4
         | 
| 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- | 
| 11 | 
            +
            date: 2014-11-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rest-client
         |