pcloud 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +14 -2
- data/README.md +3 -3
- data/lib/generators/pcloud.rb +0 -2
- data/lib/pcloud.rb +5 -3
- data/lib/pcloud/client.rb +8 -2
- data/lib/pcloud/exceptions.rb +2 -3
- data/lib/pcloud/files/file_handler.rb +36 -0
- data/lib/pcloud/files/upload.rb +19 -0
- data/lib/pcloud/request.rb +17 -19
- data/lib/pcloud/resource.rb +11 -5
- data/lib/pcloud/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2128c1a79983adf3f851afd99d033fe47558f3df24d1bbb335521698055dea6c
|
4
|
+
data.tar.gz: 2d96ae7c6dbff5ea628ba1f7511d3951a3651d0a2aceee2da0aa4ac874e114ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288b9668c7e3236f69b8575ba4834dab4a8f0aedc869d2261407ca02f0482deeb009e3df1e8c78100bf785ce804069d0d3ebf437d1a3bb03c01c81c12b533802
|
7
|
+
data.tar.gz: d873eb5aa61accd34734fb1ab2ee103fc9350ac30ca3fc834f8c03a199c4b2484aceba4f8998c73277f6538aaae4567eff3f30b6ee968afc0e895ab6712e5a8b
|
data/Changelog.md
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
-
|
1
|
+
### Changelogs:
|
2
2
|
|
3
|
-
|
3
|
+
#### v0.0.3
|
4
|
+
##### Updates
|
5
|
+
* Minor updates
|
6
|
+
* Upload and Download added - needs maintain
|
7
|
+
* Post method fixed and added back
|
8
|
+
|
9
|
+
#### v0.0.2
|
10
|
+
##### Updates
|
11
|
+
* Minor updates
|
12
|
+
* Test files added
|
13
|
+
* Removed `Post` method temporarily
|
4
14
|
|
15
|
+
#### v0.0.1
|
16
|
+
##### Publish
|
5
17
|
* Available get Method
|
6
18
|
* Incoming {Upload|Download} files
|
7
19
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Gem for Pcloud cloud storage
|
2
2
|
|
3
|
-
This Gem provides a Ruby interface to [Pcloud.com](https://pcloud.com).
|
3
|
+
This Gem provides a Ruby interface to [Pcloud.com](https://docs.pcloud.com).
|
4
4
|
|
5
5
|
[![Build Status](https://github.com/7urkm3n/pcloud/workflows/build/badge.svg?branch=master)](https://github.com/7urkm3n/pcloud/actions?query=workflow%3Abuild) [![Gem Downloads](https://badgen.net/rubygems/dt/pcloud)](https://rubygems.org/gems/pcloud) [![Gem Version](https://badge.fury.io/rb/pcloud.svg)](https://badge.fury.io/rb/pcloud)
|
6
6
|
|
@@ -54,13 +54,13 @@ Pcloud.username = 'email'
|
|
54
54
|
Pcloud.password = 'password'
|
55
55
|
```
|
56
56
|
|
57
|
-
### Logging
|
57
|
+
<!-- ### Logging
|
58
58
|
|
59
59
|
By default errors are logged in STDOUT level, also `Rails.logger` available.
|
60
60
|
|
61
61
|
``` ruby
|
62
62
|
Pcloud.logger = Rails.logger
|
63
|
-
```
|
63
|
+
``` -->
|
64
64
|
|
65
65
|
## Working with methods
|
66
66
|
|
data/lib/generators/pcloud.rb
CHANGED
data/lib/pcloud.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
autoload 'Logger', 'logger'
|
2
2
|
require 'forwardable'
|
3
3
|
require 'pcloud/client'
|
4
|
-
require 'pcloud/version'
|
5
|
-
require 'pcloud/request'
|
6
|
-
require 'pcloud/resource'
|
7
4
|
|
8
5
|
module Pcloud
|
9
6
|
BASE_URL = 'https://api.pcloud.com'.freeze
|
@@ -30,3 +27,8 @@ module Pcloud
|
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
30
|
+
|
31
|
+
require 'pcloud/version'
|
32
|
+
require 'pcloud/request'
|
33
|
+
require 'pcloud/resource'
|
34
|
+
require 'pcloud/exceptions'
|
data/lib/pcloud/client.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest-client'
|
3
|
-
require '
|
3
|
+
# require 'file/file'
|
4
|
+
# require "#{Dir.pwd}/lib/pcloud/files/file_handler"
|
5
|
+
|
4
6
|
|
5
7
|
module Pcloud
|
6
8
|
class Client
|
@@ -17,7 +19,11 @@ module Pcloud
|
|
17
19
|
def post(path, params = {})
|
18
20
|
resource(path).post(params)
|
19
21
|
end
|
20
|
-
|
22
|
+
|
23
|
+
def file
|
24
|
+
Resource.new(self).file()
|
25
|
+
end
|
26
|
+
|
21
27
|
def http_client
|
22
28
|
@client ||= begin
|
23
29
|
RestClient::Resource.new(BASE_URL)
|
data/lib/pcloud/exceptions.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Pcloud
|
2
|
-
|
3
2
|
class Error < RuntimeError; end
|
3
|
+
class AuthenticationError < Error; end
|
4
4
|
class ConfigurationError < Error
|
5
5
|
def initialize(key)
|
6
6
|
super "missing key `#{key}' in the client configuration"
|
@@ -8,8 +8,7 @@ module Pcloud
|
|
8
8
|
end
|
9
9
|
class HTTPError < Error
|
10
10
|
def initialize(key, message)
|
11
|
-
super "
|
11
|
+
super "#{key} Bad request: #{message}"
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
15
14
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/upload'
|
2
|
+
# puts "#{Dir.pwd}/lib/pcloud/request"
|
3
|
+
# require "#{Dir.pwd}/lib/pcloud/request"
|
4
|
+
|
5
|
+
module Pcloud
|
6
|
+
class FileHandler
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def upload(params, payload)
|
12
|
+
create_request(:post, 'uploadfile', params, payload).call
|
13
|
+
end
|
14
|
+
|
15
|
+
def download(params)
|
16
|
+
# create_request(:get, 'downloadfile', params).call
|
17
|
+
url = params[:url]
|
18
|
+
filename = params[:filename] ? params[:filename] : url.split("/").last
|
19
|
+
File.open("#{params[:destination]}/#{filename}", 'wb') {|f|
|
20
|
+
block = proc { |response|
|
21
|
+
response.read_body do |chunk|
|
22
|
+
f.write chunk
|
23
|
+
end
|
24
|
+
}
|
25
|
+
RestClient::Request.execute(method: :get,url: url,block_response: block)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def create_request(verb, path, params, payload = {})
|
32
|
+
Request.new(@client, verb, path, params, payload)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Upload
|
2
|
+
def self.call(auth, params)
|
3
|
+
puts "AUTH: #{auth}"
|
4
|
+
puts "PARAMS: #{params}"
|
5
|
+
pr = {params: {
|
6
|
+
folderid: 7025720177,
|
7
|
+
filename: "test.txt",
|
8
|
+
upload: {
|
9
|
+
file: File.open("/Users/7urkm3n/Downloads/gurdov.com.txt")
|
10
|
+
},
|
11
|
+
auth: auth
|
12
|
+
}}
|
13
|
+
return JSON.parse(RestClient.get("#{Pcloud::BASE_URL}/uploadfile", pr))
|
14
|
+
# fl = File.new("/Users/7urkm3n/Downloads/gurdov.com.txt", 'rb')
|
15
|
+
# File.open(Rails.root.join('app','assets', 'images', file.original_filename filename), 'wb') do |file|
|
16
|
+
# file.write(source_file.read)
|
17
|
+
# end
|
18
|
+
end
|
19
|
+
end
|
data/lib/pcloud/request.rb
CHANGED
@@ -1,44 +1,42 @@
|
|
1
1
|
module Pcloud
|
2
2
|
class Request
|
3
|
-
def initialize(client, verb, path, params)
|
4
|
-
@client, @verb
|
3
|
+
def initialize(client, verb, path, params, payload)
|
4
|
+
@client, @verb, @path, @params, @payload = client, verb, path, params, payload
|
5
5
|
end
|
6
6
|
|
7
7
|
def call
|
8
8
|
params = {params: {}}
|
9
9
|
params[:params].merge!(@params, {auth: @client.auth})
|
10
|
-
|
11
10
|
http = @client.http_client
|
12
11
|
res = case @verb
|
13
12
|
when :get
|
14
|
-
|
13
|
+
begin
|
14
|
+
http[@path].get(params)
|
15
|
+
rescue => e
|
16
|
+
handle_response(e.http_code, e.message)
|
17
|
+
end
|
15
18
|
when :post
|
16
|
-
|
19
|
+
begin
|
20
|
+
http[@path].post(@payload, params)
|
21
|
+
rescue => e
|
22
|
+
handle_response(e.http_code, e.message)
|
23
|
+
end
|
17
24
|
else
|
18
|
-
raise "Unsupported verb"
|
25
|
+
raise "Unsupported verb: #{@verb}"
|
19
26
|
end
|
20
|
-
|
21
|
-
handle_response(res.code.to_i, body)
|
27
|
+
JSON.parse(res.body, { symbolize_names: true })
|
22
28
|
end
|
23
|
-
|
29
|
+
|
24
30
|
private
|
25
31
|
|
26
32
|
def handle_response(status_code, body)
|
27
33
|
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
34
|
when 400
|
33
|
-
raise
|
35
|
+
raise HTTPError.new(:HTTPError, body)
|
34
36
|
when 401
|
35
37
|
raise AuthenticationError, body
|
36
38
|
when 404
|
37
|
-
raise
|
38
|
-
when 407
|
39
|
-
raise Error, "Proxy Authentication Required"
|
40
|
-
when 413
|
41
|
-
raise Error, "Payload Too Large > 10KB"
|
39
|
+
raise HTTPError.new(:HTTPError, body)
|
42
40
|
else
|
43
41
|
raise Error, "Unknown error (status code #{status_code}): #{body}"
|
44
42
|
end
|
data/lib/pcloud/resource.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require "#{Dir.pwd}/lib/pcloud/files/file_handler"
|
2
|
+
|
1
3
|
module Pcloud
|
2
4
|
class Resource
|
3
5
|
|
4
|
-
def initialize(client, path)
|
6
|
+
def initialize(client, path = "")
|
5
7
|
@client, @path = client, path
|
6
8
|
end
|
7
9
|
|
@@ -9,14 +11,18 @@ module Pcloud
|
|
9
11
|
create_request(:get, params).call
|
10
12
|
end
|
11
13
|
|
12
|
-
def post(params)
|
13
|
-
create_request(:post, params).call
|
14
|
+
def post(params, payload = {})
|
15
|
+
create_request(:post, params, payload).call
|
16
|
+
end
|
17
|
+
|
18
|
+
def file
|
19
|
+
FileHandler.new(@client)
|
14
20
|
end
|
15
21
|
|
16
22
|
private
|
17
23
|
|
18
|
-
def create_request(verb, params)
|
19
|
-
Request.new(@client, verb, @path, params)
|
24
|
+
def create_request(verb, params, payload = {})
|
25
|
+
Request.new(@client, verb, @path, params, payload)
|
20
26
|
end
|
21
27
|
|
22
28
|
end
|
data/lib/pcloud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rovshen Gurdov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -68,6 +68,8 @@ files:
|
|
68
68
|
- lib/pcloud.rb
|
69
69
|
- lib/pcloud/client.rb
|
70
70
|
- lib/pcloud/exceptions.rb
|
71
|
+
- lib/pcloud/files/file_handler.rb
|
72
|
+
- lib/pcloud/files/upload.rb
|
71
73
|
- lib/pcloud/request.rb
|
72
74
|
- lib/pcloud/resource.rb
|
73
75
|
- lib/pcloud/version.rb
|
@@ -76,7 +78,7 @@ licenses:
|
|
76
78
|
- MIT
|
77
79
|
metadata:
|
78
80
|
bug_tracker_uri: https://github.com/7urkm3n/pcloud/issues
|
79
|
-
changelog_uri: https://github.com/7urkm3n/pcloud/blob/
|
81
|
+
changelog_uri: https://github.com/7urkm3n/pcloud/blob/master/Changelog.md
|
80
82
|
documentation_uri: https://github.com/7urkm3n/pcloud
|
81
83
|
source_code_uri: https://github.com/7urkm3n/pcloud
|
82
84
|
post_install_message:
|