Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rid of double quotes

  • Loading branch information...
commit 2f09afc3332c9292882374beaf292de136fbca02 1 parent 05e8065
@odiszapc authored
View
74 README.md
@@ -32,26 +32,26 @@ Now you can perform file downloading in two ways: by HTTP url or by absolute pat
First, by the HTTP url, as it has worked before:
```ruby
-@rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
- :downloads_dir => "/tmp",
- :save_as => "file2.txt" # This doesn't work in the original gem at the moment because of Rapidshare API changes
+@rs.download 'https://rapidshare.com/files/4226120320/upload_file_1.txt',
+ :downloads_dir => '/tmp',
+ :save_as => 'file2.txt' # This doesn't work in the original gem at the moment because of Rapidshare API changes
# With a default local file name
- @rs.download "https://rapidshare.com/files/4226120320/upload_file_1.txt",
- :downloads_dir => "/tmp"
+ @rs.download 'https://rapidshare.com/files/4226120320/upload_file_1.txt',
+ :downloads_dir => '/tmp'
```
Download by absolute path from account you owned:
```ruby
-@rs.download "/foo/bar/baz/upload_file_1.txt",
- :downloads_dir => "/tmp"
+@rs.download '/foo/bar/baz/upload_file_1.txt',
+ :downloads_dir => '/tmp'
```
In both the first and second samples the result will be the same.
File uploading is also became very simple:
```ruby
-api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
+api.upload('/home/odiszapc/my_damn_cat.mov', :to => '/gallery/video', :as => 'cat1.mov')
# => {
# :id => 1,
# :size => 12345, # File size in bytes
@@ -61,16 +61,16 @@ api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "ca
#}
```
Destination folder will be created automatically.
-After uploading has been completed the file will be stored in a Rapidshare as "/gallery/video/cat1.mov"
+After uploading has been completed the file will be stored in a Rapidshare as '/gallery/video/cat1.mov'
You can easily get a download url after uploading:
```ruby
-result = api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
+result = api.upload('/home/odiszapc/my_damn_cat.mov', :to => '/gallery/video', :as => 'cat1.mov')
result[:url]
```
By default, file is uploaded into the root folder:
```ruby
-api.upload("/home/odiszapc/my_damn_humster.mov")
+api.upload('/home/odiszapc/my_damn_humster.mov')
```
Rapidshare allows to store multiple files having equal names under the same folder. I believe this behaviour is absolutely wrong.
@@ -79,41 +79,41 @@ If it's true, the upload() just returns info about the existing file with the :a
To force file being overwritten set the :overwrite parameter to true:
```ruby
-api.upload "/home/odiszapc/my_damn_cat.mov",
- :to => "/gallery/video",
- :as => "cat1.mov"
+api.upload '/home/odiszapc/my_damn_cat.mov',
+ :to => '/gallery/video',
+ :as => 'cat1.mov'
# No upload will be performed
-api.upload "/home/odiszapc/my_damn_cat.mov",
- :to => "/gallery/video",
- :as => "cat1.mov"
+api.upload '/home/odiszapc/my_damn_cat.mov',
+ :to => '/gallery/video',
+ :as => 'cat1.mov'
# With the following notation file will be uploaded with overwriting the existing one
-api.upload "/home/odiszapc/my_damn_cat.mov",
- :to => "/gallery/video",
- :as => "cat1.mov",
+api.upload '/home/odiszapc/my_damn_cat.mov',
+ :to => '/gallery/video',
+ :as => 'cat1.mov',
:overwrite => true
```
Deleting files:
```ruby
-api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg")
+api.remove_file('/putin/is/a/good/reason/to/live/abroad/ticket_to_Nicaragua.jpg')
```
Renaming files:
```ruby
-api.rename_file("/foo/bar.rar", "baz.rar")
+api.rename_file('/foo/bar.rar', 'baz.rar')
```
Moving files:
```ruby
-api.move_file("/foo/bar/baz.rar", :to => "/foo") # new file path: "/foo/baz.rar"
-api.move_file("/foo/bar/baz.rar") # move to a root folder
+api.move_file('/foo/bar/baz.rar', :to => '/foo') # new file path: '/foo/baz.rar'
+api.move_file('/foo/bar/baz.rar') # move to a root folder
```
Get the file ID:
```ruby
-api.file_id("/foo/bar/baz.rar") # => <ID>
+api.file_id('/foo/bar/baz.rar') # => <ID>
```
### Folders
@@ -121,19 +121,19 @@ As you note it's possible having a hierarchy of folders in your account.
Creating folder hierarchy:
```ruby
-folder_id = api.add_folder "a/b/c" # => <FOLDER ID>
+folder_id = api.add_folder 'a/b/c' # => <FOLDER ID>
```
Deleting folders:
```ruby
-api.remove_folder("/a/b/c")
+api.remove_folder('/a/b/c')
```
Moving folders:
```ruby
-api.move_folder("/a/b/c", :to => "/a")
+api.move_folder('/a/b/c', :to => '/a')
```
-This moves the folder "c" from the directory "/a/b/" and places it under the directory "/a"
+This moves the folder 'c' from the directory '/a/b/' and places it under the directory '/a'
You can get hierarchy of all the folders in account:
```ruby
@@ -150,7 +150,7 @@ api.folders_hierarchy
Note, that after the folder hierarchy is generated first time it's cached permanently to improve performance.
-So, if you want to invalidate the cache just call the above method with trailing "!":
+So, if you want to invalidate the cache just call the above method with trailing '!':
```ruby
api.folders_hierarchy!
```
@@ -164,15 +164,15 @@ Be careful with the tree consistency, orphan folders may contain a critical data
A more secure way to deal with folder consistency is to fix all orphans first and then generate folder tree:
```ruby
-api.add_folder "/garbage"
-api.move_orphans :to => "/garbage" # Collect all orphans and place them under the /garbage folder
+api.add_folder '/garbage'
+api.move_orphans :to => '/garbage' # Collect all orphans and place them under the /garbage folder
tree = api.folders_hierarchy
```
Get the folder ID or path:
```ruby
-id = api.folder_id("/foo/bar") # <ID>
-api.folder_path(id) # "/foo/bar"
+id = api.folder_id('/foo/bar') # <ID>
+api.folder_path(id) # '/foo/bar'
```
### Orphans
@@ -181,7 +181,7 @@ What does it mean? When you delete parent folder by its ID the folder will be de
For example, let we have the basic directory tree:
```
ROOT
-`-a <- Raw Rapidshare API allows you to delete JUST THIS folder, so hierarchy relation between folders will be lost and the folders "c" and "b" will became orphans
+`-a <- Raw Rapidshare API allows you to delete JUST THIS folder, so hierarchy relation between folders will be lost and the folders 'c' and 'b' will became orphans
`-b
`-c
```
@@ -190,13 +190,13 @@ ROOT
So, the best way to delete a directory tree without washing away consistency of account folder hierarchy is the following:
```ruby
-api.remove_folder "/a" # This will delete all the child directories correctly
+api.remove_folder '/a' # This will delete all the child directories correctly
```
However, if you already have orphans in your account there is possible to fix them.
So ,the next method detects all orphan folders in your account and moves them into a specific folder:
```ruby
-api.move_orphans :to => "/"
+api.move_orphans :to => '/'
```
Or we can just delete all of them (be careful):
View
6 Rakefile
@@ -1,10 +1,10 @@
#!/usr/bin/env rake
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
require 'rake/testtask'
include Rake::DSL
-desc "Run tests"
-task :test => ['test:unit', 'test:integration']
+desc 'Run tests'
+task :test => %w{test:unit test:integration}
task :default => :test
View
8 lib/rapidshare-base/api.rb
@@ -18,7 +18,7 @@ class API
# * *none* - default value, returns response body as it is
# * *csv* - comma-separated values, for example: _getrapidtranslogs_.
# Returns array or arrays, one array per each line.
- # * *hash* - lines with key and value separated by "=", for example:
+ # * *hash* - lines with key and value separated by '=', for example:
# _getaccountdetails_. Returns hash.
# * *server* - option, determines which server will be used to send request
#
@@ -45,10 +45,10 @@ def self.request(service_name, params = {})
end
if response.start_with?(ERROR_PREFIX)
- case error = response.sub(ERROR_PREFIX, "").split('.').first
- when "Login failed"
+ case error = response.sub(ERROR_PREFIX, '').split('.').first
+ when 'Login failed'
raise Rapidshare::API::Error::LoginFailed
- when "Invalid routine called"
+ when 'Invalid routine called'
raise Rapidshare::API::Error::InvalidRoutineCalled.new(service_name)
else
raise Rapidshare::API::Error.new(error)
View
62 lib/rapidshare-ext/api.rb
@@ -2,7 +2,7 @@ module Rapidshare
module Ext
module API
- FILE_COLUMNS = "downloads,lastdownload,filename,size,serverid,type,x,y,realfolder,killdeadline,uploadtime,comment,md5hex,licids,sentby"
+ FILE_COLUMNS = 'downloads,lastdownload,filename,size,serverid,type,x,y,realfolder,killdeadline,uploadtime,comment,md5hex,licids,sentby'
# @param [String] path Folder name with absolute path to be created
# @param [Hash] params
@@ -10,7 +10,7 @@ module API
#
# Creates a folder in a Rapidshare virtual filesystem
#
- # api.add_folder("/a/b/c") #=> <Random folder ID from Rapidshare>, 1234 for example
+ # api.add_folder('/a/b/c') #=> <Random folder ID from Rapidshare>, 1234 for example
def add_folder(path, params = {})
path = path_trim path
@@ -34,7 +34,7 @@ def add_folder(path, params = {})
# The following code deals with #{} because of rest client #to_i returns HTTP code
folder_id = "#{addrealfolder(add_folder_params)}".to_i
- raise "error while creating folder" if parent < 0
+ raise 'error while creating folder' if parent < 0
@tree[folder_id] = {
:parent => parent,
:name => folder_name,
@@ -55,7 +55,7 @@ def add_folder(path, params = {})
# @param [Hash] params
# @return [Array]
#
- # api.remove_folder("/a/b/c")
+ # api.remove_folder('/a/b/c')
def remove_folder(path, params = {})
folder_id = self.folder_id path_trim(path)
raise Exception, "Folder #{path} could not be found" if folder_id.nil?
@@ -84,9 +84,9 @@ def remove_folder(path, params = {})
#
# @param [String] source_path
# @param [Hash] params
- # :to => <destination folder path>, default: "/"
+ # :to => <destination folder path>, default: '/'
#
- # api.move_folder("/a/b/c", :to => "/a")
+ # api.move_folder('/a/b/c', :to => '/a')
def move_folder(source_path, params = {})
dest_path = (params.delete(:to) || '/')
source_folder_id = folder_id(source_path)
@@ -110,13 +110,13 @@ def move_folder(source_path, params = {})
# @param [String] file_path
# @param [Hash] params
# <tt>:to</tt>::
- # Folder to place uploaded file to, default: "/"
+ # Folder to place uploaded file to, default: '/'
# <tt>:as</tt>::
# The name file will have in storage after it has been uploaded
# <tt>:overwrite</tt>::
# Overwrite file if it already exists in the given folder
#
- # api.upload("/home/odiszapc/my_damn_cat.mov", :to => "/gallery/video", :as => "cat1.mov")
+ # api.upload('/home/odiszapc/my_damn_cat.mov', :to => '/gallery/video', :as => 'cat1.mov')
def upload(file_path, params = {})
raise Exception unless File.exist? file_path
dest_path = path_trim(params.delete(:to) || '/')
@@ -128,12 +128,12 @@ def upload(file_path, params = {})
listfiles_params = {
:realfolder => folder_id,
:filename => "#{file_name}",
- :fields => "md5hex,size",
+ :fields => 'md5hex,size',
:parser => :csv
}
listfiles_response = self.listfiles listfiles_params
- file_already_exists = ("NONE" != listfiles_response[0][0])
+ file_already_exists = ('NONE' != listfiles_response[0][0])
remove_file "#{dest_path}/#{file_name}" if file_already_exists && overwrite
# In case of file is not existing then upload it
@@ -181,7 +181,7 @@ def upload(file_path, params = {})
# @param [String] path
# @param [Hash] params
#
- # api.remove_file("/putin/is/a/good/reason/to/live/abroad/ticket_to_Nikaragua.jpg")
+ # api.remove_file('/putin/is/a/good/reason/to/live/abroad/ticket_to_Nikaragua.jpg')
def remove_file(path, params = {})
params = {
:files => file_id(path).to_s
@@ -196,7 +196,7 @@ def remove_file(path, params = {})
# @param [String] name
# @param [Hash] params
#
- # api.rename_file("/foo/bar.rar", "baz.rar")
+ # api.rename_file('/foo/bar.rar', 'baz.rar')
def rename_file(remote_path, name, params = {})
file_id = file_id remote_path
@@ -214,10 +214,10 @@ def rename_file(remote_path, name, params = {})
# @param [String] remote_path
# @param [Hash] params
# <tt>:to</tt>::
- # Destination folder path, default: "/"
+ # Destination folder path, default: '/'
#
- # api.move_file("/foo/bar/baz.rar", :to => "/foo")
- # api.move_file("/foo/bar/baz.rar") # move to a root folder
+ # api.move_file('/foo/bar/baz.rar', :to => '/foo')
+ # api.move_file('/foo/bar/baz.rar') # move to a root folder
def move_file(remote_path, params = {})
file_id = file_id remote_path
dest_path = path_trim(params.delete(:to) || '/')
@@ -318,16 +318,16 @@ def folders_hierarchy(params = {})
# Build tree relative to a specified folder
# If the source tree is:
# tree = {
- # 1 => {:parent => 0, :name => "a", :path => "a"},
- # 2 => {:parent => 1, :name => "b", :path => "a/b"},
- # 3 => {:parent => 2, :name => "c", :path => "a/b/c"},
+ # 1 => {:parent => 0, :name => 'a', :path => 'a'},
+ # 2 => {:parent => 1, :name => 'b', :path => 'a/b'},
+ # 3 => {:parent => 2, :name => 'c', :path => 'a/b/c'},
# ...
# }
- # slice_tree tree, :from => "/a"
+ # slice_tree tree, :from => '/a'
# Result will be as follows:
# {
- # 2 => {:parent => 1, :name => "b", :path => "b"},
- # 3 => {:parent => 2, :name => "c", :path => "b/c"},
+ # 2 => {:parent => 1, :name => 'b', :path => 'b'},
+ # 3 => {:parent => 2, :name => 'c', :path => 'b/c'},
# ...
# }
def slice_tree(tree, params = {})
@@ -369,7 +369,7 @@ def remove_orphans!
# Orphan folder is a folder with non existing parent (yes, it's possible)
#
# Example:
- # move_orphans :to => "/"
+ # move_orphans :to => '/'
def move_orphans(params = {})
new_folder = path_trim(params.delete(:to) || '/')
gaps = detect_gaps
@@ -421,7 +421,7 @@ def gap?(folder_id)
# For example we have the following hierarchy:
#
# ROOT
- # `-a <- if we remove just this folder then the folder "c" and "b" will become orphans
+ # `-a <- if we remove just this folder then the folder 'c' and 'b' will become orphans
# `-b
# `-c
def orphan?(folder_id)
@@ -435,11 +435,11 @@ def orphan?(folder_id)
# Translate folder ID to a human readable path
#
- # api.folder_path(123) # -> "foo/bar/baz"
+ # api.folder_path(123) # -> 'foo/bar/baz'
def folder_path(folder_id)
@tree = folders_hierarchy
- folder_data = @tree[folder_id] || {:parent => 0, :name => "<undefined>", :path => "<undefined>"}
+ folder_data = @tree[folder_id] || {:parent => 0, :name => '<undefined>', :path => '<undefined>'}
parent_id = folder_data[:parent]
path = (folder_path(parent_id) if parent_id.nonzero?).to_s + ('/' if parent_id.nonzero?).to_s + folder_data[:name]
@@ -448,7 +448,7 @@ def folder_path(folder_id)
# Get folder ID by path
#
- # api.folder_id("foo/bar/baz") # -> 123
+ # api.folder_id('foo/bar/baz') # -> 123
def folder_id(folder_path)
folder_path = path_trim(folder_path)
return 0 if folder_path.empty?
@@ -494,12 +494,12 @@ def file_info(file_path, params = {})
}.merge params
resp = listfiles(listfiles_params)[0]
- return nil if "NONE" == resp[0]
+ return nil if 'NONE' == resp[0]
response = {}
fields = listfiles_params[:fields].split(',')
- fields.unshift "id"
+ fields.unshift 'id'
fields.each_with_index do |value, index|
response[value.to_sym] = resp[index]
end
@@ -511,9 +511,9 @@ def file_info(file_path, params = {})
# Returns file ID by absolute path
#
- # api.file_id("foo/bar/baz/file.rar") # => <FILE_ID>
+ # api.file_id('foo/bar/baz/file.rar') # => <FILE_ID>
def file_id(file_path, params = {})
- params[:fields] = ""
+ params[:fields] = ''
file_info = file_info file_path, params
(file_info || {})[:id].to_i
end
@@ -525,7 +525,7 @@ def path_trim(path)
end
def path_canonize(path)
- "/" + path_trim(path)
+ '/' + path_trim(path)
end
end
end
View
2  lib/rapidshare-ext/download.rb
@@ -7,7 +7,7 @@ module Ext
# so the base download function provided by rapidshare gem became broken
#
# In the original method the parameter :filename being interpreted incorrectly now.
- # It's being interpreted like a "save file as" parameter. Actually it must be equal to the file name you want to download
+ # It's being interpreted like a 'save file as' parameter. Actually it must be equal to the file name you want to download
# So, to download file now you must specify exactly two parameters: file id and file name.
class Download < Rapidshare::Download
View
2  lib/rapidshare-ext/version.rb
@@ -1,5 +1,5 @@
module Rapidshare
module Ext
- VERSION = "0.0.6"
+ VERSION = '0.0.6'
end
end
View
10 rapidshare-ext.gemspec
@@ -2,18 +2,18 @@
require File.expand_path('../lib/rapidshare-ext/version', __FILE__)
Gem::Specification.new do |gem|
- gem.name = "rapidshare-ext"
+ gem.name = 'rapidshare-ext'
gem.version = Rapidshare::Ext::VERSION
- gem.authors = ["odiszapc"]
- gem.email = ["odiszapc@gmail.com"]
+ gem.authors = %w{odiszapc}
+ gem.email = %w{odiszapc@gmail.com}
gem.description = %q{Extends the original rapidshare gem with a set of handy features}
gem.summary = %q{Makes your interactions with Rapidshare API more pleasant by providing new handy features: creating/moving/deleting files/folders in a user friendly way, upload files, etc}
- gem.homepage = "http://github.com/odiszapc/rapidshare-ext"
+ gem.homepage = 'http://github.com/odiszapc/rapidshare-ext'
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
- gem.require_paths = ["lib"]
+ gem.require_paths = %w{lib}
gem.add_dependency('rapidshare', '~> 0.5.3')
View
182 test/integration/rapidshare-ext_test.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
require 'digest/md5'
-require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class RapidshareExtTest < Test::Unit::TestCase
@@ -17,22 +17,22 @@ def setup
@rs.erase_all_data!
- @download_dir = File.expand_path(File.dirname(__FILE__) + "/../../tmp")
+ @download_dir = File.expand_path(File.dirname(__FILE__) + '/../../tmp')
File.delete "#@download_dir/file1.txt" if File.exist? "#@download_dir/file1.txt"
File.delete "#@download_dir/file2.txt" if File.exist? "#@download_dir/file2.txt"
File.delete "#@download_dir/upload_file_1.txt" if File.exist? "#@download_dir/upload_file_1.txt"
- @upload_file_1 = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload1.txt")
+ @upload_file_1 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload1.txt')
@upload_file_1_md5 = Digest::MD5.hexdigest(File.read(@upload_file_1))
@upload_file_1_size = File.size @upload_file_1
- @upload_file_2 = File.expand_path(File.dirname(__FILE__) + "/../fixtures/files/upload2.txt")
+ @upload_file_2 = File.expand_path(File.dirname(__FILE__) + '/../fixtures/files/upload2.txt')
@upload_file_2_md5 = Digest::MD5.hexdigest(File.read(@upload_file_2))
@upload_file_2_size = File.size @upload_file_2
end
- context "Api" do
- should "upload file" do
+ context 'Api' do
+ should 'upload file' do
upload_assertion = ->(resp, size_local, digest_local, remote_filename) do
assert_instance_of Hash, resp
assert_kind_of Integer, resp[:id]
@@ -45,8 +45,8 @@ def setup
assert_equal "https://rapidshare.com/files/#{resp[:id]}/#{URI::encode(remote_filename)}", resp[:url]
end
- remote_filename = "upload_file_1.txt"
- remote_dir = "a/b/c"
+ remote_filename = 'upload_file_1.txt'
+ remote_dir = 'a/b/c'
remote_path = "#{remote_dir}/#{remote_filename}"
# Initial upload
@@ -83,140 +83,140 @@ def setup
upload_assertion.call response, @upload_file_2_size, @upload_file_2_md5, remote_filename
end
- should "download file" do
- @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
- assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ should 'download file' do
+ @rs.upload @upload_file_1, :to => '/a/b/c', :as => 'upload_file_1.txt'
+ assert_not_nil @rs.file_info('/a/b/c/upload_file_1.txt')
- @rs.download "/a/b/c/upload_file_1.txt", :downloads_dir => @download_dir, :save_as => "file1.txt"
+ @rs.download '/a/b/c/upload_file_1.txt', :downloads_dir => @download_dir, :save_as => 'file1.txt'
assert_path_exist "#@download_dir/file1.txt"
assert_equal @upload_file_1_size, File.size("#@download_dir/file1.txt")
assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/file1.txt"))
# Download with default :save_as
- @rs.download "/a/b/c/upload_file_1.txt", :downloads_dir => @download_dir
+ @rs.download '/a/b/c/upload_file_1.txt', :downloads_dir => @download_dir
assert_path_exist "#@download_dir/upload_file_1.txt"
assert_equal @upload_file_1_size, File.size("#@download_dir/upload_file_1.txt")
assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/upload_file_1.txt"))
# Download by http url
- download_url = @rs.file_info("/a/b/c/upload_file_1.txt")[:url]
- @rs.download download_url, :downloads_dir => @download_dir, :save_as => "file2.txt"
+ download_url = @rs.file_info('/a/b/c/upload_file_1.txt')[:url]
+ @rs.download download_url, :downloads_dir => @download_dir, :save_as => 'file2.txt'
assert_path_exist "#@download_dir/file2.txt"
assert_equal @upload_file_1_size, File.size("#@download_dir/file2.txt")
assert_equal @upload_file_1_md5, Digest::MD5.hexdigest(File.read("#@download_dir/file2.txt"))
end
- should "rename file" do
- @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
- assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ should 'rename file' do
+ @rs.upload @upload_file_1, :to => '/a/b/c', :as => 'upload_file_1.txt'
+ assert_not_nil @rs.file_info('/a/b/c/upload_file_1.txt')
- @rs.rename_file "/a/b/c/upload_file_1.txt", "file_2.txt"
- info = @rs.file_info "/a/b/c/file_2.txt"
+ @rs.rename_file '/a/b/c/upload_file_1.txt', 'file_2.txt'
+ info = @rs.file_info '/a/b/c/file_2.txt'
assert_not_nil info
- assert_equal info[:filename], "file_2.txt"
- assert_equal info[:realfolder].to_i, @rs.folder_id("/a/b/c")
+ assert_equal info[:filename], 'file_2.txt'
+ assert_equal info[:realfolder].to_i, @rs.folder_id('/a/b/c')
assert_equal info[:size].to_i, @upload_file_1_size
assert_equal info[:md5hex].downcase, @upload_file_1_md5
end
- should "move file" do
- @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
- assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ should 'move file' do
+ @rs.upload @upload_file_1, :to => '/a/b/c', :as => 'upload_file_1.txt'
+ assert_not_nil @rs.file_info('/a/b/c/upload_file_1.txt')
- @rs.move_file "/a/b/c/upload_file_1.txt", :to => "/a/b"
- assert_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ @rs.move_file '/a/b/c/upload_file_1.txt', :to => '/a/b'
+ assert_nil @rs.file_info('/a/b/c/upload_file_1.txt')
- info = @rs.file_info "/a/b/upload_file_1.txt"
+ info = @rs.file_info '/a/b/upload_file_1.txt'
assert_not_nil info
- assert_equal info[:filename], "upload_file_1.txt"
- assert_equal info[:realfolder].to_i, @rs.folder_id("/a/b")
+ assert_equal info[:filename], 'upload_file_1.txt'
+ assert_equal info[:realfolder].to_i, @rs.folder_id('/a/b')
assert_equal info[:size].to_i, @upload_file_1_size
assert_equal info[:md5hex].downcase, @upload_file_1_md5
end
- should "delete file" do
- @rs.upload @upload_file_1, :to => "/a/b/c", :as => "upload_file_1.txt"
- assert_not_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ should 'delete file' do
+ @rs.upload @upload_file_1, :to => '/a/b/c', :as => 'upload_file_1.txt'
+ assert_not_nil @rs.file_info('/a/b/c/upload_file_1.txt')
- @rs.remove_file "/a/b/c/upload_file_1.txt"
- assert_nil @rs.file_info("/a/b/c/upload_file_1.txt")
+ @rs.remove_file '/a/b/c/upload_file_1.txt'
+ assert_nil @rs.file_info('/a/b/c/upload_file_1.txt')
end
- should "folder id <=> path conversions" do
- @rs.add_folder "/a/b/c"
- id = @rs.folder_id("/a/b/c")
- assert_equal "/a/b/c", @rs.folder_path(id)
+ should 'folder id <=> path conversions' do
+ @rs.add_folder '/a/b/c'
+ id = @rs.folder_id('/a/b/c')
+ assert_equal '/a/b/c', @rs.folder_path(id)
end
- should "create folder" do
- folder_id = @rs.add_folder "a/b/c"
+ should 'create folder' do
+ folder_id = @rs.add_folder 'a/b/c'
assert_kind_of Integer, folder_id
assert_not_equal 0, folder_id
tree = @rs.folders_hierarchy
assert_equal 3, tree.count
- assert_equal "/a/b/c", tree[folder_id][:path]
- assert_equal "/a/b", tree[tree[folder_id][:parent]][:path]
- assert_equal "/a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
+ assert_equal '/a/b/c', tree[folder_id][:path]
+ assert_equal '/a/b', tree[tree[folder_id][:parent]][:path]
+ assert_equal '/a', tree[tree[tree[folder_id][:parent]][:parent]][:path]
end
- should "move folder" do
- folder_id = @rs.add_folder "/a/b/c"
+ should 'move folder' do
+ folder_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_id
assert_not_equal 0, folder_id
tree = @rs.folders_hierarchy
assert_equal 3, tree.count
- assert_equal "/a/b/c", tree[folder_id][:path]
- assert_equal "/a/b", tree[tree[folder_id][:parent]][:path]
- assert_equal "/a", tree[tree[tree[folder_id][:parent]][:parent]][:path]
+ assert_equal '/a/b/c', tree[folder_id][:path]
+ assert_equal '/a/b', tree[tree[folder_id][:parent]][:path]
+ assert_equal '/a', tree[tree[tree[folder_id][:parent]][:parent]][:path]
- @rs.move_folder "/a/b/c", :to => 'a'
+ @rs.move_folder '/a/b/c', :to => 'a'
tree = @rs.reload!
assert_equal 3, tree.count
- assert_equal "/a/c", tree[folder_id][:path]
- assert_equal @rs.folder_id("/a"), tree[folder_id][:parent]
+ assert_equal '/a/c', tree[folder_id][:path]
+ assert_equal @rs.folder_id('/a'), tree[folder_id][:parent]
end
- should "remove folder" do
- folder_id = @rs.add_folder "a/b/c"
+ should 'remove folder' do
+ folder_id = @rs.add_folder 'a/b/c'
assert_kind_of Integer, folder_id
assert_not_equal 0, folder_id
tree = @rs.folders_hierarchy
assert_equal 3, tree.count
- @rs.remove_folder "/a/b/c"
+ @rs.remove_folder '/a/b/c'
tree = @rs.folders_hierarchy!
assert_equal 2, tree.count
- folder_id = @rs.add_folder "/a/b/c"
+ folder_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_id
assert_not_equal 0, folder_id
tree = @rs.folders_hierarchy!
assert_equal 3, tree.count
- @rs.remove_folder "/a"
+ @rs.remove_folder '/a'
tree = @rs.folders_hierarchy!
assert_equal 0, tree.count
end
- should "build folders tree" do
+ should 'build folders tree' do
# Create folders
- folder_a_id = @rs.add_folder "/a"
+ folder_a_id = @rs.add_folder '/a'
assert_kind_of Integer, folder_a_id
assert_not_equal 0, folder_a_id
- folder_b_id = @rs.add_folder "/a/b"
+ folder_b_id = @rs.add_folder '/a/b'
assert_kind_of Integer, folder_b_id
assert_not_equal 0, folder_b_id
- folder_c_id = @rs.add_folder "/a/b/c"
+ folder_c_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_c_id
assert_not_equal 0, folder_c_id
@@ -225,28 +225,28 @@ def setup
# Validate tree
assert_equal 3, tree.count
- assert_equal "a", tree[folder_a_id][:name]
- assert_equal "/a", tree[folder_a_id][:path]
+ assert_equal 'a', tree[folder_a_id][:name]
+ assert_equal '/a', tree[folder_a_id][:path]
assert_equal 0, tree[folder_a_id][:parent]
- assert_equal "b", tree[folder_b_id][:name]
- assert_equal "/a/b", tree[folder_b_id][:path]
+ assert_equal 'b', tree[folder_b_id][:name]
+ assert_equal '/a/b', tree[folder_b_id][:path]
assert_equal folder_a_id, tree[folder_b_id][:parent]
- assert_equal "c", tree[folder_c_id][:name]
- assert_equal "/a/b/c", tree[folder_c_id][:path]
+ assert_equal 'c', tree[folder_c_id][:name]
+ assert_equal '/a/b/c', tree[folder_c_id][:path]
assert_equal folder_b_id, tree[folder_c_id][:parent]
# Validate subtree
sub_tree = @rs.folders_hierarchy :from => '/a/b'
assert_equal 1, sub_tree.count
- assert_equal "/c", sub_tree[folder_c_id][:path]
- assert_equal "c", sub_tree[folder_c_id][:name]
+ assert_equal '/c', sub_tree[folder_c_id][:path]
+ assert_equal 'c', sub_tree[folder_c_id][:name]
assert_equal folder_b_id, sub_tree[folder_c_id][:parent]
end
- should "erase all account data" do
- folder_id = @rs.add_folder "/a/b/c"
+ should 'erase all account data' do
+ folder_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_id
folder_ids = @rs.folders_hierarchy.keys
@@ -259,17 +259,17 @@ def setup
assert_equal 0, folder_ids.count
end
- should "move orphans" do
+ should 'move orphans' do
# Create folders
- folder_a_id = @rs.add_folder "/a"
+ folder_a_id = @rs.add_folder '/a'
assert_kind_of Integer, folder_a_id
assert_not_equal 0, folder_a_id
- folder_b_id = @rs.add_folder "/a/b"
+ folder_b_id = @rs.add_folder '/a/b'
assert_kind_of Integer, folder_b_id
assert_not_equal 0, folder_b_id
- folder_c_id = @rs.add_folder "/a/b/c"
+ folder_c_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_c_id
assert_not_equal 0, folder_c_id
@@ -283,7 +283,7 @@ def setup
assert_false @rs.orphan? folder_b_id
assert_false @rs.orphan? folder_c_id
- # Delete just folder "/a" to accomplish tree inconsistency
+ # Delete just folder '/a' to accomplish tree inconsistency
@rs.delrealfolder :realfolder => folder_a_id
@rs.reload! :validate => false
@@ -298,26 +298,26 @@ def setup
assert_true @rs.orphan? folder_c_id
# Move orphan folders to root folder
- @rs.move_orphans :to => "/"
+ @rs.move_orphans :to => '/'
hierarchy_expected = {
- folder_c_id => {:name=>"c", :parent => folder_b_id, :path => "/b/c"},
- folder_b_id => {:name=>"b", :parent => 0, :path => "/b"},
+ folder_c_id => {:name=>'c', :parent => folder_b_id, :path => '/b/c'},
+ folder_b_id => {:name=>'b', :parent => 0, :path => '/b'},
}
assert_equal hierarchy_expected, @rs.folders_hierarchy!
end
- should "delete orphans" do
+ should 'delete orphans' do
# Create folders
- folder_a_id = @rs.add_folder "/a"
+ folder_a_id = @rs.add_folder '/a'
assert_kind_of Integer, folder_a_id
assert_not_equal 0, folder_a_id
- folder_b_id = @rs.add_folder "/a/b"
+ folder_b_id = @rs.add_folder '/a/b'
assert_kind_of Integer, folder_b_id
assert_not_equal 0, folder_b_id
- folder_c_id = @rs.add_folder "/a/b/c"
+ folder_c_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_c_id
assert_not_equal 0, folder_c_id
@@ -331,30 +331,30 @@ def setup
assert_false @rs.orphan? folder_b_id
assert_false @rs.orphan? folder_c_id
- # Delete just folder "/a" to accomplish tree inconsistency
+ # Delete just folder '/a' to accomplish tree inconsistency
@rs.delrealfolder :realfolder => folder_a_id
@rs.reload! :validate => false
@rs.remove_orphans!
hierarchy_expected = {
- folder_c_id => {:name=>"c", :parent => folder_b_id, :path => "/b/c"},
- folder_b_id => {:name=>"b", :parent => 0, :path => "/b"},
+ folder_c_id => {:name=>'c', :parent => folder_b_id, :path => '/b/c'},
+ folder_b_id => {:name=>'b', :parent => 0, :path => '/b'},
}
assert_equal ({}), @rs.folders_hierarchy!
end
- should "work with invalid tree" do
+ should 'work with invalid tree' do
# Create folders
- folder_a_id = @rs.add_folder "/a"
+ folder_a_id = @rs.add_folder '/a'
assert_kind_of Integer, folder_a_id
assert_not_equal 0, folder_a_id
- folder_b_id = @rs.add_folder "/a/b"
+ folder_b_id = @rs.add_folder '/a/b'
assert_kind_of Integer, folder_b_id
assert_not_equal 0, folder_b_id
- folder_c_id = @rs.add_folder "/a/b/c"
+ folder_c_id = @rs.add_folder '/a/b/c'
assert_kind_of Integer, folder_c_id
assert_not_equal 0, folder_c_id
@@ -368,7 +368,7 @@ def setup
assert_false @rs.orphan? folder_b_id
assert_false @rs.orphan? folder_c_id
- # Delete just folder "/a" to accomplish tree inconsistency
+ # Delete just folder '/a' to accomplish tree inconsistency
@rs.delrealfolder :realfolder => folder_a_id
msg = "Directory tree consistency error. Parent folder ##{folder_a_id} for the folder \"/<undefined>/b\" [#{folder_b_id}] could not be found"
View
4 test/unit/rapidshare-ext_test.rb
@@ -1,8 +1,8 @@
require 'test_helper'
class RapidshareExtTest < Test::Unit::TestCase
- context "Interface" do
- should "Respond to certain methods" do
+ context 'Interface' do
+ should 'Respond to certain methods' do
assert_respond_to @rs, :add_folder
assert_respond_to @rs, :remove_folder
assert_respond_to @rs, :move_folder
Please sign in to comment.
Something went wrong with that request. Please try again.