pcloud 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +89 -0
- data/lib/generators/pcloud.rb +5 -0
- data/lib/generators/pcloud_generator.rb +15 -0
- data/lib/pcloud.rb +36 -0
- data/lib/pcloud/client.rb +51 -0
- data/lib/pcloud/exceptions.rb +15 -0
- data/lib/pcloud/request.rb +48 -0
- data/lib/pcloud/resource.rb +23 -0
- data/lib/pcloud/version.rb +3 -0
- data/spec/client_spec.rb +58 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f97c89c839b96efc44d932f46539daf32ea0899e9000f87f239cc48388d129d6
|
4
|
+
data.tar.gz: 657cadf62da0db6811c321bc098ba5487134045da018e50fd8769fd24df5aadd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e165e640064b7d76585127949f9946be4799bcd573058de13b05ba3d614c78d6fd334e0ef250405fa00326c9a6377b21bf32eb4ce7a351ada2166a97019f42c
|
7
|
+
data.tar.gz: 72d0872e3502b942383f57dc8f3cd54e95cab10b57c4b71357a033f00c12629b747146e85da9ab49ef23adf60d7e93af2f3bf3ca543f9c803d33706100758d4a
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Russell
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Gem for Pcloud cloud storage
|
2
|
+
|
3
|
+
This Gem provides a Ruby interface to [Pcloud.com](https://pcloud.com).
|
4
|
+
|
5
|
+
[]() [](https://rubygems.org/gems/pcloud)
|
6
|
+
|
7
|
+
## Installation and Configuration
|
8
|
+
|
9
|
+
Add `pcloud` to your Gemfile, and then run `bundle install`
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem 'pcloud'
|
13
|
+
```
|
14
|
+
|
15
|
+
or install via gem
|
16
|
+
|
17
|
+
``` bash
|
18
|
+
gem install pcloud
|
19
|
+
```
|
20
|
+
|
21
|
+
###### Rails
|
22
|
+
to generate `Rails` initializer file
|
23
|
+
|
24
|
+
```bash
|
25
|
+
rails generate pcloud
|
26
|
+
```
|
27
|
+
|
28
|
+
or add it manually into following path
|
29
|
+
|
30
|
+
```bash
|
31
|
+
config/initializers/pcloud.rb
|
32
|
+
```
|
33
|
+
|
34
|
+
### Instantiating a client
|
35
|
+
|
36
|
+
``` ruby
|
37
|
+
require 'pcloud'
|
38
|
+
|
39
|
+
pcloud = Pcloud::Client.new(
|
40
|
+
username: 'email',
|
41
|
+
password: 'password',
|
42
|
+
)
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
### Global configuration
|
47
|
+
|
48
|
+
The library can also be configured globally on the `Pcloud` class.
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
Pcloud.username = 'email'
|
52
|
+
Pcloud.password = 'password'
|
53
|
+
```
|
54
|
+
|
55
|
+
### Logging
|
56
|
+
|
57
|
+
By default errors are logged in STDOUT level, also `Rails.logger` available.
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
Pcloud.logger = Rails.logger
|
61
|
+
```
|
62
|
+
|
63
|
+
## Working with methods
|
64
|
+
|
65
|
+
Currently, only available custom Get method.
|
66
|
+
|
67
|
+
File upload and Download methods are coming soon.
|
68
|
+
|
69
|
+
|
70
|
+
#### Get methods
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
pcloud.get("getip")
|
74
|
+
pcloud.get("getdigest")
|
75
|
+
|
76
|
+
# with params
|
77
|
+
pcloud.get("listfolder", folderid: 0)
|
78
|
+
pcloud.get("createfolder", folderid: 0, name: "new folder name")
|
79
|
+
```
|
80
|
+
|
81
|
+
<!-- #### Post methods
|
82
|
+
|
83
|
+
``` ruby
|
84
|
+
# with params
|
85
|
+
pcloud.get("createfolder", folderid: 0, name: "new folder name")
|
86
|
+
``` -->
|
87
|
+
|
88
|
+
### Supported Ruby versions
|
89
|
+
2.0+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Pcloud
|
4
|
+
module Generators
|
5
|
+
class PcloudGenerator < ::Rails::Generators::Base
|
6
|
+
desc 'Generates a pcloud initializer file.'
|
7
|
+
|
8
|
+
source_root File.expand_path("..", __FILE__)
|
9
|
+
|
10
|
+
def copy_initializer_file
|
11
|
+
copy_file "pcloud.rb", "config/initializers/pcloud.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/pcloud.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
autoload 'Logger', 'logger'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'pcloud/client'
|
4
|
+
require 'pcloud/version'
|
5
|
+
require 'pcloud/request'
|
6
|
+
require 'pcloud/resource'
|
7
|
+
|
8
|
+
module Pcloud
|
9
|
+
BASE_URL = 'https://api.pcloud.com'.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
extend Forwardable
|
13
|
+
def_delegators :default_client, :username=, :password=
|
14
|
+
def_delegators :default_client, :get, :post
|
15
|
+
|
16
|
+
attr_writer :logger
|
17
|
+
|
18
|
+
def logger
|
19
|
+
@logger ||= begin
|
20
|
+
log = Logger.new($stdout)
|
21
|
+
log.level = Logger::INFO
|
22
|
+
log
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_client
|
27
|
+
@default_client ||= begin
|
28
|
+
Pcloud::Client.new
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'pcloud/exceptions'
|
4
|
+
|
5
|
+
module Pcloud
|
6
|
+
class Client
|
7
|
+
attr_writer :username, :password
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@username, @password = options.values_at(:username, :password)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(path, params = {})
|
14
|
+
resource(path).get(params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, params = {})
|
18
|
+
resource(path).post(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def http_client
|
22
|
+
@client ||= begin
|
23
|
+
RestClient::Resource.new(BASE_URL)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def auth
|
28
|
+
@auth ||= begin
|
29
|
+
raise ConfigurationError, :username unless @username
|
30
|
+
raise ConfigurationError, :password unless @password
|
31
|
+
digest = JSON.parse(RestClient.get("#{BASE_URL}/getdigest"))['digest']
|
32
|
+
passworddigest = Digest::SHA1.hexdigest( @password + Digest::SHA1.hexdigest( @username.downcase ) + digest)
|
33
|
+
params = {params:
|
34
|
+
{
|
35
|
+
username: @username,
|
36
|
+
digest: digest,
|
37
|
+
passworddigest: passworddigest
|
38
|
+
}
|
39
|
+
}
|
40
|
+
JSON.parse(RestClient.get("#{BASE_URL}/userinfo?getauth=1&logout=1", params))['auth']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def resource(path)
|
47
|
+
Resource.new(self, path)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Pcloud
|
2
|
+
|
3
|
+
class Error < RuntimeError; end
|
4
|
+
class ConfigurationError < Error
|
5
|
+
def initialize(key)
|
6
|
+
super "missing key `#{key}' in the client configuration"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
class HTTPError < Error
|
10
|
+
def initialize(key, message)
|
11
|
+
super "Error status `#{key}': #{message}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Pcloud
|
2
|
+
class Request
|
3
|
+
def initialize(client, verb, path, params)
|
4
|
+
@client, @verb , @path, @params = client, verb, path, params
|
5
|
+
end
|
6
|
+
|
7
|
+
def call
|
8
|
+
params = {params: {}}
|
9
|
+
params[:params].merge!(@params, {auth: @client.auth})
|
10
|
+
|
11
|
+
http = @client.http_client
|
12
|
+
res = case @verb
|
13
|
+
when :get
|
14
|
+
http[@path].get( params )
|
15
|
+
when :post
|
16
|
+
http[@path].post( params )
|
17
|
+
else
|
18
|
+
raise "Unsupported verb"
|
19
|
+
end
|
20
|
+
body = res.body ? res.body.chomp : nil
|
21
|
+
handle_response(res.code.to_i, body)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def handle_response(status_code, body)
|
27
|
+
case status_code
|
28
|
+
when 200
|
29
|
+
return JSON.parse(body, { symbolize_names: true })
|
30
|
+
when 202
|
31
|
+
return body.empty? ? true : JSON.parse(body, { symbolize_names: true })
|
32
|
+
when 400
|
33
|
+
raise Error, "Bad request: #{body}"
|
34
|
+
when 401
|
35
|
+
raise AuthenticationError, body
|
36
|
+
when 404
|
37
|
+
raise Error, "404 Not found (#{@uri})"
|
38
|
+
when 407
|
39
|
+
raise Error, "Proxy Authentication Required"
|
40
|
+
when 413
|
41
|
+
raise Error, "Payload Too Large > 10KB"
|
42
|
+
else
|
43
|
+
raise Error, "Unknown error (status code #{status_code}): #{body}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pcloud
|
2
|
+
class Resource
|
3
|
+
|
4
|
+
def initialize(client, path)
|
5
|
+
@client, @path = client, path
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(params)
|
9
|
+
create_request(:get, params).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(params)
|
13
|
+
create_request(:post, params).call
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create_request(verb, params)
|
19
|
+
Request.new(@client, verb, @path, params)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
describe Pcloud do
|
2
|
+
[lambda { Pcloud }, lambda { Pcloud::Client.new }].each do |client_gen|
|
3
|
+
before :each do
|
4
|
+
@client = client_gen.call
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'default configuration' do
|
8
|
+
it 'should be preconfigured for api host' do
|
9
|
+
expect(@client.host).to eq('api.pusherapp.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be preconfigured for port 80' do
|
13
|
+
expect(@client.port).to eq(80)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should use standard logger if no other logger if defined' do
|
17
|
+
Pusher.logger.debug('foo')
|
18
|
+
expect(Pusher.logger).to be_kind_of(Logger)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'logging configuration' do
|
23
|
+
it "can be configured to use any logger" do
|
24
|
+
logger = double("ALogger")
|
25
|
+
expect(logger).to receive(:debug).with('foo')
|
26
|
+
Pusher.logger = logger
|
27
|
+
Pusher.logger.debug('foo')
|
28
|
+
Pusher.logger = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "configuration using url" do
|
33
|
+
it "should be possible to configure everything by setting the url" do
|
34
|
+
@client.url = "test://somekey:somesecret@api.staging.pusherapp.com:8080/apps/87"
|
35
|
+
|
36
|
+
expect(@client.scheme).to eq('test')
|
37
|
+
expect(@client.host).to eq('api.staging.pusherapp.com')
|
38
|
+
expect(@client.port).to eq(8080)
|
39
|
+
expect(@client.key).to eq('somekey')
|
40
|
+
expect(@client.secret).to eq('somesecret')
|
41
|
+
expect(@client.app_id).to eq('87')
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
it "should fail on bad urls" do
|
47
|
+
expect { @client.url = "gopher/somekey:somesecret@://api.staging.pusherapp.co://m:8080\apps\87" }.to raise_error(URI::InvalidURIError)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should raise exception if app_id is not configured" do
|
51
|
+
@client.app_id = nil
|
52
|
+
expect {
|
53
|
+
@client.url
|
54
|
+
}.to raise_error(Pusher::ConfigurationError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rovshen Gurdov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: forwardable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.4.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.4.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.6.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.4
|
97
|
+
description: Pcloud is online storage upload/download/share from pcloud.com. Currently
|
98
|
+
not supports all API URLs. Please, check available methods in Github Doc...
|
99
|
+
email:
|
100
|
+
- rovshen@gurdov.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- LICENSE
|
106
|
+
- README.md
|
107
|
+
- lib/generators/pcloud.rb
|
108
|
+
- lib/generators/pcloud_generator.rb
|
109
|
+
- lib/pcloud.rb
|
110
|
+
- lib/pcloud/client.rb
|
111
|
+
- lib/pcloud/exceptions.rb
|
112
|
+
- lib/pcloud/request.rb
|
113
|
+
- lib/pcloud/resource.rb
|
114
|
+
- lib/pcloud/version.rb
|
115
|
+
- spec/client_spec.rb
|
116
|
+
homepage: https://rubygems.org/gems/pcloud
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 2.0.0
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubygems_version: 3.0.3
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Secure and simple to use cloud storage for your datas...
|
139
|
+
test_files:
|
140
|
+
- spec/client_spec.rb
|