https://github.com/7urkm3n/pcloud
pCloud's Ruby SDK
https://github.com/7urkm3n/pcloud
pcloud pcloud-api rails ruby
Last synced: about 1 year ago
JSON representation
pCloud's Ruby SDK
- Host: GitHub
- URL: https://github.com/7urkm3n/pcloud
- Owner: 7urkm3n
- License: mit
- Created: 2020-08-30T23:03:43.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-03-03T18:38:44.000Z (over 2 years ago)
- Last Synced: 2025-03-24T00:11:47.333Z (over 1 year ago)
- Topics: pcloud, pcloud-api, rails, ruby
- Language: Ruby
- Homepage: https://docs.pcloud.com
- Size: 81.1 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Gem for Pcloud cloud storage
This Gem provides a Ruby interface to [Pcloud.com](https://docs.pcloud.com).
[](https://github.com/7urkm3n/pcloud/actions?query=workflow%3Arelease) [](https://rubygems.org/gems/pcloud) [](https://badge.fury.io/rb/pcloud)
##### Want to contribute? [Doc Link](CONTRIBUTE.md)
## Installation and Configuration
Supported Ruby versions: 2.3+
Add `pcloud` to your Gemfile, and then run `bundle install`
```ruby
gem 'pcloud'
```
or install via gem
```bash
gem install pcloud
```
###### Rails
to generate `Rails` initializer file
```bash
rails generate pcloud
```
or add it manually into following path
```bash
config/initializers/pcloud.rb
```
### Instantiating a client
```ruby
require 'pcloud'
pcloud = Pcloud::Client.new(
username: 'email',
password: 'password',
).authenticate
pcloud.get("listfolder", folderid: 0)
```
Note that, [as per official API docs](https://docs.pcloud.com/):
>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.:
```ruby
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.
```ruby
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.
```ruby
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
```ruby
Pcloud.get("getip")
Pcloud.get("getdigest")
# with params
params = {folderid: 0}
Pcloud.get("listfolder", params)
```
#### Post method
```ruby
payload = {}
params = {folderid: 0, name: "new folder name"}
Pcloud.post("createfolder", payload, params)
```
### [File methods](https://docs.pcloud.com/methods/file/)
##### [Download File](https://docs.pcloud.com/methods/file/downloadfile.html)
```ruby
# 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](#)
```ruby
# optional params: filename, destination
# destination by default current_path
Pcloud.file.download_folder({folderid: 123456789})
```
##### [Upload File](https://docs.pcloud.com/methods/file/uploadfile.html)
```ruby
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](https://opensource.org/licenses/MIT).