Gem for Pcloud cloud storage

This Gem provides a Ruby interface to Pcloud.com.

Build Status Gem Downloads Gem Version

Installation and Configuration

Add pcloud to your Gemfile, and then run bundle install

gem 'pcloud'

or install via gem

gem install pcloud
Rails

to generate Rails initializer file

rails generate pcloud

or add it manually into following path

config/initializers/pcloud.rb

Instantiating a client

require 'pcloud'

pcloud = Pcloud::Client.new(
  username: 'email',
  password: 'password',
).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.logger

Working with methods

Available methods:

  • Get
  • Post
  • File handling
addition!

Some apis need to be raw format, just add raw in params. params: {fileid: ..987, raw: true} For example gettextfile https://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)

File methods

Download File
# 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})
Upload File
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)

Supported Ruby versions

2.3+