-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|