ejaydj 0.0.2 → 0.0.3

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: f38b5750ecee9604f8398c422f9e2452b1711fdf
4
- data.tar.gz: ab623da78d7a86b04939a968e45465543c3708ad
3
+ metadata.gz: 1c7b3aac4292a3b24563d8e1adaabf9444ce3954
4
+ data.tar.gz: 72da1fddaa35c3c8fd223bce31e14c5cc35d5c6e
5
5
  SHA512:
6
- metadata.gz: 131e5c70deb7eadffd3c1d948fc599162fda8613a473c612f494292630b66d4d214fbf5bf269432025671d01eb4261c131602795f0d8ea04b1ebec4b044fe8e9
7
- data.tar.gz: c0bf2ee4c103d4995f8b6541e16d6e62c7de92184460fd16a841c3b123ecdf18d6f62d8ddb71d2bfbe92e0030e4775040cd06b4401c1583f16e7192816fc9c3d
6
+ metadata.gz: 55a91144630f2b6da1211b2a55c9da9dfaa0b49ee62178e4969ee077a7eee9499274d1863b66032e044bc2760abea2c0d58e0bece780003a3a681fff7c57e9d5
7
+ data.tar.gz: d3e2db30fba50dc890d78d2e26d57179de69571909df28c8eb1021e2454fa9d989a72a1e34505ca91f86a92a652b85c690bb6a6c62173beeded225ea096e99b6
data/ejaydj.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "rest-client", "~> 1.7"
22
22
  spec.add_runtime_dependency "json"
23
23
  spec.add_runtime_dependency "twitter"
24
+ spec.add_runtime_dependency "googl"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.6"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,4 +1,5 @@
1
1
  require 'twitter'
2
+ require 'googl'
2
3
 
3
4
  module Ejaydj
4
5
  module Djs
@@ -9,20 +10,42 @@ module Ejaydj
9
10
  :twitter_access_token_secret,
10
11
  :twitter_client
11
12
 
13
+ MAX_SONG_LENGTH = 50
14
+ MAX_ARTIST_LENGTH = 50
15
+
12
16
  def initialize(attributes={}, &block)
13
17
  super(attributes, &block)
14
18
  end
15
19
 
16
20
  def tweet_me_a_song(time: Time.now)
17
- song = play_me_a_song(time: time)
18
- tweet = "NP: #{song.name} by #{song.artist} from #{song.playlist.name} playlist: #{song.playlist.url}"
21
+ @song = play_me_a_song(time: time)
22
+ tweet = tweet_string
23
+
19
24
  twitter_client.update(tweet)
20
25
 
21
- {message: tweet, song: song}
26
+ {message: tweet, song: @song}
22
27
  end
23
28
 
24
29
  private
25
30
 
31
+ def tweet_string
32
+ tweet_string = ("NP: #{@song.name} by #{@song.artist} from playlist: #{shorten_url(@song.playlist.url)}")
33
+ shorten_tweet(tweet_string)
34
+ end
35
+
36
+ def shorten_tweet(tweet_string)
37
+ return tweet_string unless tweet_string.length > 140
38
+
39
+ @song.name = "#{@song.name[0..MAX_SONG_LENGTH]}..." if @song.name.length > MAX_SONG_LENGTH
40
+ @song.artist = "#{@song.artist[0..MAX_ARTIST_LENGTH]}..." if @song.artist.length > MAX_ARTIST_LENGTH
41
+
42
+ "NP: #{@song.name} by #{@song.artist} | #{shorten_url(@song.playlist.url)}"
43
+ end
44
+
45
+ def shorten_url(url)
46
+ Googl.shorten(url).short_url
47
+ end
48
+
26
49
  def twitter_client
27
50
  @twitter_client ||= Twitter::REST::Client.new do |config|
28
51
  config.consumer_key = @twitter_consumer_key
data/lib/ejaydj/track.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  module Ejaydj
2
2
  class Track
3
- attr_reader :name,
3
+ attr_accessor :name,
4
4
  :album,
5
5
  :artist,
6
- :duration_ms
7
-
8
- attr_accessor :playlist
6
+ :duration_ms,
7
+ :playlist
9
8
 
10
9
  def initialize(attributes={})
11
10
  @id = attributes[:id]
@@ -1,3 +1,3 @@
1
1
  module Ejaydj
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -27,7 +27,7 @@ RSpec.describe Ejaydj::Djs::TwitterBot do
27
27
 
28
28
  let(:playlist_items) do
29
29
  [
30
- {"name" => "Morning Playlist", "owner" => {"id" => 1}, "external_urls" => {"spotify" => "/playlist_morning"}, "tracks" => {"total" => 10}}
30
+ {"name" => "Morning Playlist", "owner" => {"id" => 1}, "external_urls" => {"spotify" => "http://spotify.com"}, "tracks" => {"total" => 10}}
31
31
  ]
32
32
  end
33
33
 
@@ -41,9 +41,12 @@ RSpec.describe Ejaydj::Djs::TwitterBot do
41
41
  ]
42
42
  end
43
43
 
44
+ let(:shorten_url) { 'http://goo.gl' }
45
+
44
46
  before do
45
47
  allow(music_client).to receive(:user_playlists).and_return(playlist_items)
46
48
  allow(music_client).to receive(:playlist_tracks).and_return(track_items)
49
+ allow(Googl).to receive(:shorten).and_return(double('GoogleURL', short_url: shorten_url))
47
50
  end
48
51
 
49
52
  describe '#tweet_me_a_song' do
@@ -51,7 +54,18 @@ RSpec.describe Ejaydj::Djs::TwitterBot do
51
54
  tweet = twitter_bot_dj.tweet_me_a_song(time: Time.new(2014, 11, 20, 7, 0, 0))
52
55
  song = tweet[:song]
53
56
 
54
- expect(tweet[:message]).to eq("NP: #{song.name} by #{song.artist} from #{song.playlist.name} playlist: #{song.playlist.url}")
57
+ expect(tweet[:message]).to eq("NP: #{song.name} by #{song.artist} from playlist: #{shorten_url}")
58
+ end
59
+
60
+ context "when tweet string is over 140" do
61
+ it "shrinks the tweet less than 140 text" do
62
+ track_items.first["track"]["name"] = "This is a very long track name, yeah it is, yeah it is yeah it is...................................."
63
+
64
+ tweet = twitter_bot_dj.tweet_me_a_song(time: Time.new(2014, 11, 20, 7, 0, 0))
65
+ song = tweet[:song]
66
+
67
+ expect(tweet[:message].length).to be <= 140
68
+ end
55
69
  end
56
70
  end
57
71
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ejaydj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ejay Canaria
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: googl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement