Gem for Pcloud cloud storage
This Gem provides a Ruby interface to Pcloud.com.
Want to contribute? Doc Link
Installation and Configuration
Supported Ruby versions: 2.3+
Add pcloud to your Gemfile, and then run bundle install
gem 'pcloud'or install via gem
gem install pcloudRails
to generate Rails initializer file
rails generate pcloudor add it manually into following path
config/initializers/pcloud.rbInstantiating a client
require 'pcloud'
pcloud = Pcloud::Client.new(
username: 'email',
password: 'password',
).authenticate
pcloud.get("listfolder", folderid: 0)Note that, as per official API docs:
pCloud has two data centers. One in United States and one in Europe. As a consequence API calls have to be made to the correct API host name depending were the user has been registered – api.pcloud.com for United States and eapi.pcloud.com for Europe.
The default region used is https://api.pcloud.com (US). To use a different region, specify a different base_url parameter (EU region: https://eapi.pcloud.com) when instantiating a client, e.g.:
require 'pcloud'
pcloud = Pcloud::Client.new(
username: 'email',
password: 'password',
base_url: "https://eapi.pcloud.com",
).authenticate
pcloud.get("listfolder", folderid: 0)Global configuration
The library can also be configured globally on the Pcloud class.
Pcloud.username = 'email'
Pcloud.password = 'password'
Pcloud.authenticate
Pcloud.get("listfolder", folderid: 0)Logging
By default errors are logged in STDOUT level, also Rails.logger available.
Pcloud.logger = Rails.loggerWorking with methods
Available methods:
- Get
- Post
- File handling
addition!
Some apis need to be
rawformat, just addrawin params.params: {fileid: ..987, raw: true}For examplegettextfilehttps://docs.pcloud.com/methods/streaming/gettextfile.html
Get method
Pcloud.get("getip")
Pcloud.get("getdigest")
# with params
params = {folderid: 0}
Pcloud.get("listfolder", params)Post method
payload = {}
params = {folderid: 0, name: "new folder name"}
Pcloud.post("createfolder", payload, params)# optional params: filename, destination
# destination by default current_path
Pcloud.file.download({fileid: 987532135})
Pcloud.file.download(
fileid: 987532135, #required
destination: "#{Dir.pwd}/Downloads", #optional
filename: "hehe.txt" #optional
)Download Folder
# optional params: filename, destination
# destination by default current_path
Pcloud.file.download_folder({folderid: 123456789})params = {
folderid: 0, #required
nopartial: 1,
}
# multiple uploads
file1 = File.open("./Rakefile")
file2 = File.open("./README.md")
file3 = File.open("./Gemfile")
payload = { files: [file1,file2,file3] }
Pcloud.file.upload(params, payload)License
The gem is available as open source under the terms of the MIT License.