Skip to content

Commit

Permalink
Add support for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
mnutt committed Aug 17, 2009
1 parent dd73747 commit 2b484f0
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 70 deletions.
46 changes: 46 additions & 0 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'json'

class CollectionsController < ApplicationController
self.allow_forgery_protection = false

def index
@collections = Limewire::Collection.all
render :json => JSON::pretty_generate({:collections => @collections})
end

def create
@collection = Limewire::Collection.create(params[:name])
render :json => JSON::pretty_generate(@collection)
end

def destroy
@collection = Limewire::Collection.find(params[:id])
@collection.destroy
render :json => {:response => 200}
end

def update
@collection = Limewire::Collection.find(params[:id])
@collection.reorder(params[:sha1s]) if params[:sha1s]
@collection.name = params[:name] if params[:name]
@collection.save
render :json => {:response => 200}
end

def add_items
@collection = Limewire::Collection.find(params[:id])
params[:sha1s].each do |sha1|
@collection.add sha1
end
render :json => {:response => 200}
end

def remove_items
@collection = Limewire::Collection.find(params[:id])
params[:sha1s].each do |sha1|
@collection.remove sha1
end

render :json => {:response => 200}
end
end
43 changes: 0 additions & 43 deletions app/controllers/playlists_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
map.resources :library, :member => {:thumbnail => :get}
map.thumb "/library/:id/thumbnail/:s", :controller => 'library', :action => 'thumbnail'

map.resources :playlists
map.resources :collections, :member => {:add_items => :post, :remove_items => :post}
map.resources :searches
map.resources :downloads
map.resources :search
Expand Down
54 changes: 28 additions & 26 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,35 @@ def self.get_singleton(klass)
# Running from Limewire
include Java

Geocoder = org.limewire.geocode.Geocoder
OldURN = com.limegroup.gnutella.URN
ApplicationServicesRef = com.limegroup.gnutella.ApplicationServices
MetaDataFactoryImpl = com.limegroup.gnutella.metadata.MetaDataFactoryImpl
MetaDataFactoryRef = com.limegroup.gnutella.metadata.MetaDataFactory
GUID = org.limewire.io.GUID
URN = org.limewire.core.api.URN
StatisticsRef = com.limegroup.gnutella.Statistics
FilePropertyKey = org.limewire.core.api.FilePropertyKey
MojitoManagerRef = org.limewire.core.api.mojito.MojitoManager
LibraryManagerRef = org.limewire.core.api.library.LibraryManager
SearchManagerRef = org.limewire.core.api.search.SearchManager
DownloadListManagerRef = org.limewire.core.api.download.DownloadListManager
MongrelManagerRef = org.limewire.http.mongrel.MongrelManager # meta
HostCatcherRef = com.limegroup.gnutella.HostCatcher
NetworkManagerRef = com.limegroup.gnutella.NetworkManager
Geocoder = org.limewire.geocode.Geocoder
OldURN = com.limegroup.gnutella.URN
ApplicationServicesRef = com.limegroup.gnutella.ApplicationServices
MetaDataFactoryImpl = com.limegroup.gnutella.metadata.MetaDataFactoryImpl
MetaDataFactoryRef = com.limegroup.gnutella.metadata.MetaDataFactory
GUID = org.limewire.io.GUID
URN = org.limewire.core.api.URN
StatisticsRef = com.limegroup.gnutella.Statistics
FilePropertyKey = org.limewire.core.api.FilePropertyKey
MojitoManagerRef = org.limewire.core.api.mojito.MojitoManager
LibraryManagerRef = org.limewire.core.api.library.LibraryManager
SearchManagerRef = org.limewire.core.api.search.SearchManager
DownloadListManagerRef = org.limewire.core.api.download.DownloadListManager
FileCollectionManagerRef = com.limegroup.gnutella.library.FileCollectionManager
MongrelManagerRef = org.limewire.http.mongrel.MongrelManager # meta
HostCatcherRef = com.limegroup.gnutella.HostCatcher
NetworkManagerRef = com.limegroup.gnutella.NetworkManager

ApplicationServices = self.get_singleton(ApplicationServicesRef)
Statistics = self.get_singleton(StatisticsRef)
MojitoManager = self.get_singleton(MojitoManagerRef)
SearchManager = self.get_singleton(SearchManagerRef)
LibraryManager = self.get_singleton(LibraryManagerRef)
MetaDataFactory = self.get_singleton(MetaDataFactoryRef)
DownloadListManager = self.get_singleton(DownloadListManagerRef)
MongrelManager = self.get_singleton(MongrelManagerRef)
HostCatcher = self.get_singleton(HostCatcherRef)
NetworkManager = self.get_singleton(NetworkManagerRef)
ApplicationServices = self.get_singleton(ApplicationServicesRef)
Statistics = self.get_singleton(StatisticsRef)
MojitoManager = self.get_singleton(MojitoManagerRef)
SearchManager = self.get_singleton(SearchManagerRef)
LibraryManager = self.get_singleton(LibraryManagerRef)
FileCollectionManager = self.get_singleton(FileCollectionManagerRef)
MetaDataFactory = self.get_singleton(MetaDataFactoryRef)
DownloadListManager = self.get_singleton(DownloadListManagerRef)
MongrelManager = self.get_singleton(MongrelManagerRef)
HostCatcher = self.get_singleton(HostCatcherRef)
NetworkManager = self.get_singleton(NetworkManagerRef)
else
# Not running from limewire, no injector available
end
Expand Down
1 change: 1 addition & 0 deletions vendor/plugins/limewire/lib/limewire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require 'limewire/download'
require 'limewire/search'
require 'limewire/mojito'
require 'limewire/collection'

# The Limewire module should be the sole method used to interact with LimeWire's core.
module Limewire
Expand Down
75 changes: 75 additions & 0 deletions vendor/plugins/limewire/lib/limewire/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module Limewire
class Collection
attr_accessor :name

def self.create(name)
self.new Core::FileCollectionManager.create_new_collection(name)
end

def self.all
Core::FileCollectionManager.shared_file_collections.map{|p| self.new(p) }
end

def self.find(id)
self.new Core::FileCollectionManager.collection_by_id(id.to_i)
end

def self.find_by_name(name)
self.all.select{|p| p.name == name}.first
end

def initialize(raw_collection)
@raw_collection = raw_collection
@name = raw_collection.name
end

def add(sha1, position=nil)
item = Library.find_by_sha1(sha1)
if position
@raw_collection.add(item, position.to_i)
else
@raw_collection.add(item)
end
end

def id
@raw_collection.get_id
end

def public?
@raw_collection.public?
end

def remove(sha1)
item = Library.find_by_sha1(sha1)
@raw_collection.remove(item)
end

def addable?(sha1)
item = Library.find_by_sha1(sha1)
@raw_collection.file_addable?(item.file)
end

def clear
@raw_collection.clear
end

def save
@raw_collection.set_name(@name)
end

def destroy
Core::FileCollectionManager.remove_collection_by_id self.id
end

def items
@raw_collection.to_a.map{|i| Limewire::File.new(i) }
end

def to_json(*a)
{ :name => self.name,
:items => self.items,
:id => self.id }.to_json(*a)
end
end
end
4 changes: 4 additions & 0 deletions vendor/plugins/limewire/lib/limewire/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def to_cloud
}
end

def to_json(*a)
self.to_cloud.to_json(*a)
end

def to_yaml
self.to_cloud
end
Expand Down

0 comments on commit 2b484f0

Please sign in to comment.