README.md in rmega-0.0.6 vs README.md in rmega-0.1.0
- old
+ new
@@ -1,95 +1,148 @@
# Rmega
-A ruby library for the Mega.co.nz.
-Tested using ruby 1.9.3+ (OpenSSL 0.9.8r+)
-This work is the result of a reverse engineering of the Mega's Javascript code.
+A ruby library for MEGA ([https://mega.co.nz/](https://mega.co.nz/))
+Requirements: Ruby 1.9.3+ and OpenSSL 0.9.8r+
+
+This is the result of a reverse engineering of the MEGA javascript code.
+This is a work in progress, further functionality are coming.
+
+
+Supported features are:
+ * Login
+ * Searching and browsing
+ * Creating folders
+ * Download of files and folders (multi-thread)
+ * Download with public links (multi-thread)
+ * Upload of files (multi-thread)
+ * Deleting and trashing
+
+
## Installation
- Rmega is distributed via rubygems, so if you have ruby 1.9.3+ installed
- system wide, just type `gem install rmega`.
+ **Rmega** is distributed via [rubygems.org](https://rubygems.org/).
+ If you have ruby installed system wide, just type `gem install rmega`.
## Usage
- $ irb -r rmega
+```ruby
+require 'rmega'
+```
-### Login and retrive all the files and folders
+### Login
```ruby
-storage = Rmega.login 'your_email', 'your_password'
-
-# Fetch all the nodes (files, folders, ecc.)
-nodes = storage.nodes
+storage = Rmega.login('your@email.com', 'your_p4ssw0rd')
```
+### Browsing
-### Download a file or a folder
-
```ruby
-file = storage.nodes_by_name(/document1/i).first
-file.name # => "MyDocument1.pdf"
-file.download '~/Downloads'
+# Print the name of the files in the root folder
+storage.root.files.each { |file| puts file.name }
-folder = storage.nodes_by_name(/photos/i).first
-folder.download '~/Downloads/MyAlbums'
-```
+# Print the number of files in each folder
+storage.root.folders.each do |folder|
+ puts "Folder #{folder.name} contains #{folder.files.size} files."
+end
+# Print the name and the size of the files in the recyble bin
+storage.trash.files.each { |file| puts "#{file.name} of #{file.size} bytes" }
-### Download a file using a public url
+# Print the name of all the files (everywhere)
+storage.nodes.each do |node|
+ next unless node.type == :file
+ puts node.name
+end
-```ruby
-storage.download 'https://mega.co.nz/#!cER0GYbD!ZCHruEA08Xl4a_bUZYMI', '~/Downloads'
+# Print all the nodes (files, folders, etc.) within a spefic folder
+folder = storage.root.folders[12]
+folder.children.each do |node|
+ puts "Node #{node.name} (#{node.type})"
+end
```
+### Searching
-### Upload a file
-
```ruby
-# Upload a file (to the root folder)
-storage.upload '~/Downloads/my_file.zip'
+# Search for a file within a specific folder
+folder = storage.root.folders[2]
+folder.files.find { |file| file.name == "to_find.txt" }
-# Upload a file to a specific folder
-document_folder = storage.nodes_by_name(/photos/i).first
-storage.upload '~/Downloads/my_file.zip', document_folder
+# Search for a file everywhere
+storage.nodes.find { |node| node.type == :file and node.name =~ /my_file/i }
+
+# Note: A node can be of type :file, :folder, :root, :inbox and :trash
```
-### Other operations
+### Download
```ruby
-# Trash a file or a folder
-my_node.trash
+# Download a single file
+file = storage.root.files.first
+file.download("~/Downloads")
+# => Download in progress 15.0MB of 15.0MB (100.0%)
-# Gets the public url (the sharable one) of a file
-my_node.public_url
+# Download a folder and all its content recursively
+folder = storage.nodes.find do |node|
+ node.type == :folder and node.name == 'my_folder'
+end
+folder.download("~/Downloads/my_folder")
-# See the attributes of a node
-my_node.attributes
-
-# Create a folder
-parent_folder = storage.nodes_by_name(/photos/i).first
-folder_node = storage.create_folder parent_folder, "london"
+# Download a file by url
+publid_url = 'https://mega.co.nz/#!MAkg2Iab!bc9Y2U6d93IlRRKVYpcC9hLZjS4G278OPdH6nTFPDNQ'
+storage.download(public_url, '~/Downloads')
```
-## Todo
+### Upload
- * Handle connection errors during upload/download
+```ruby
+# Upload a file to a specific folder
+folder = storage.root.folders[3]
+folder.upload("~/Downloads/my_file.txt")
+# Upload a file to the root folder
+storage.root.upload("~/Downloads/my_other_file.txt")
+```
-## Installation
+### Creating a folder
-Add this line to your application's Gemfile:
+```ruby
+# Create a subfolder of the root folder
+new_folder = storage.root.create_folder("my_documents")
- gem 'rmega'
+# Create a subfolder of an existing folder
+folder = storage.nodes.find do |node|
+ node.type == :folder and node.name == 'my_folder'
+end
+folder.create_folder("my_documents")
+```
-And then execute:
+### Deleting
- $ bundle
+```ruby
+# Delete a folder
+folder = storage.root.folders[4]
+folder.delete
-Or install it yourself as:
+# Move a folder to the recyle bin
+folder = storage.root.folders[4]
+folder.trash
- $ gem install rmega
+# Delete a file
+file = storage.root.folders[3].files.find { |f| f.name =~ /document1/ }
+file.delete
+# Move a file to the recyle bin
+file = storage.root.files.last
+file.trash
+
+# Empty the trash
+unless storage.trash.empty?
+ storage.trash.empty!
+end
+```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)