Class: ItunesController::DummyITunesController

Inherits:
BaseITunesController show all
Defined in:
lib/itunesController/dummy_itunescontroller.rb

Overview

This is a dummy implementation of the itunes controller which can be used in tests to check that they talk to the server correctly. Any commands that are recived are logged in the COMMNAD_LOG list. Tests can read these to make sure they did the correct thing

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDummyITunesController

The constructor



32
33
# File 'lib/itunesController/dummy_itunescontroller.rb', line 32

def initialize            
end

Class Method Details

.forceAddTrack(track) ⇒ Object



47
48
49
50
51
# File 'lib/itunesController/dummy_itunescontroller.rb', line 47

def self.forceAddTrack(track)
    ItunesController::ItunesControllerLogging::debug("Force Adding track #{track}")
    dummyTrack=DummyItunesTrack.new(track.location,track.databaseId,track.title)
    @@tracks.push(dummyTrack)
end

.getCommandLogObject



35
36
37
# File 'lib/itunesController/dummy_itunescontroller.rb', line 35

def self.getCommandLog()
    return @@commandLog
end

.resetCommandLogObject



39
40
41
# File 'lib/itunesController/dummy_itunescontroller.rb', line 39

def self.resetCommandLog()
    @@commandLog=[]
end

.resetTracksObject



43
44
45
# File 'lib/itunesController/dummy_itunescontroller.rb', line 43

def self.resetTracks()
    @@tracks=[]
end

Instance Method Details

#addFilesToLibrary(files) ⇒ Array[ItunesController::Track]

Used to add a list of files to the itunes library. This is a dummy implementaion that is used with tests. It pushes messages into the ItunesController::DummyITunesController::COMMAND_LOG so that tests can check the result.

Parameters:

  • A (Array[String])

    list of files to add to the itunes library

Returns:



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/itunesController/dummy_itunescontroller.rb', line 85

def addFilesToLibrary(files)
    tracks=[]          
    files.each do | file |                                                                             
        track=ItunesController::Track.new(file,@@tracks.length,"Test #{@@tracks.length}")                
        ItunesController::ItunesControllerLogging::debug("Adding track #{track}")              
        dummyTrack=DummyItunesTrack.new(track.location,track.databaseId,track.title)
        tracks.push(track)                
        @@tracks.push(dummyTrack)                           
        @@commandLog.push("addFilesToLibrary("+file+")")                
    end
    return tracks
end

#findPlaylists(types) ⇒ Object



98
99
100
101
102
# File 'lib/itunesController/dummy_itunescontroller.rb', line 98

def findPlaylists(types)
    playlists=[]
    @@commandLog.push("findPlaylists(types)")
    return playlists
end

#getTrackCountObject



104
105
106
107
# File 'lib/itunesController/dummy_itunescontroller.rb', line 104

def getTrackCount()
    @@commandLog.push("getTrackCount() = #{@@tracks.length}")
    return @@tracks.length
end

#getTrackDatabaseId(track) ⇒ Object

Used to get the database of a itunes track

Parameters:

  • track

    the track

Returns:

  • The database id



135
136
137
# File 'lib/itunesController/dummy_itunescontroller.rb', line 135

def getTrackDatabaseId(track)
    return track.databaseID
end

#getTracks(&b) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/itunesController/dummy_itunescontroller.rb', line 109

def getTracks(&b)
    @@commandLog.push("getTracks()")
    for i in (0..@@tracks.length-1)
        track=@@tracks[i]                
        dead=!File.exist?(track.location)
        ItunesController::ItunesControllerLogging::debug("Getting track: #{track}, dead = #{dead}")
        b.call(ItunesController::Track.new(track.location,track.databaseID,track.name),i,@@tracks.length,dead)
    end
end

#refreshTracks(tracks) ⇒ Object

Used to tell iTunes to refresh a list of tracks data from the info stored in the files. This is a dummy implementaion that is used with tests. It pushes messages into the ItunesController::DummyITunesController::COMMAND_LOG so that tests can check the result.

Parameters:

  • track

    The track



61
62
63
64
65
66
# File 'lib/itunesController/dummy_itunescontroller.rb', line 61

def refreshTracks(tracks)
    tracks.each do | track |
        ItunesController::ItunesControllerLogging::debug("Refresh track #{track}")
        @@commandLog.push("refreshTracks(#{track})")
    end
end

#removeTracksFromLibrary(tracks) ⇒ Object

Used to remove tracks from the libaray. This is a dummy implementaion that is used with tests. It pushes messages into the ItunesController::DummyITunesController::COMMAND_LOG so that tests can check the result.

Parameters:

  • tracks (Array)

    A list of tracks to remove from the itunes libaray



72
73
74
75
76
77
78
# File 'lib/itunesController/dummy_itunescontroller.rb', line 72

def removeTracksFromLibrary(tracks)
    tracks.each do | track |
        ItunesController::ItunesControllerLogging::debug("Remove track #{track}")
        @@commandLog.push("removeTracksFromLibrary(#{track})")
        @@tracks.delete(track)
    end
end

#searchLibrary(title) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/itunesController/dummy_itunescontroller.rb', line 120

def searchLibrary(title)
    tracks=[]
    ItunesController::ItunesControllerLogging::debug("Searching for tracks with title '#{title}'")            
    @@tracks.each do | track |
        if (track.name == title)                    
            tracks.push(track)                    
            ItunesController::ItunesControllerLogging::debug("Found track '#{track}'")
        end
    end
    return tracks
end

#versionObject



53
54
55
# File 'lib/itunesController/dummy_itunescontroller.rb', line 53

def version
    return "Dummy"
end