pcloud 0.1.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb75c427f836b4d247ec4fcf9274d241602f56b42b9db36f4b2933b032f65c9e
4
- data.tar.gz: 8ac6d05ace840e3e97da605b639f1a1aba3d8f47d8fb3d2e015334b2c6fd2ade
3
+ metadata.gz: f947200228e5097393b62dfec894cb23446ab98aa6a5cae771df06f7aa857157
4
+ data.tar.gz: a112e53a402bf4ff3712d97c4ebf6bab0a1d45344c3cec64c7166c530cec2d4d
5
5
  SHA512:
6
- metadata.gz: 0c5817e6034dbcb5f68c92c5d075c610ee37dbcb57cc7a38c79ece949634d3d8f56065ba1b906af9950e56943729964ca99697c30abbf5d6136a18d18bcc29dc
7
- data.tar.gz: 9ca0c32931e65cc3a52bd0e64ba8767481599b357a91ca69f789162f875641101b225c8f581f125d548ece41fe888b010da53eccec5d274bd59db2353685e7f0
6
+ metadata.gz: f9268db7b79edd81d07ab7e4e6f927749dd862ec4de3ebb1abcaf32198c2dcf1844e28a6b3c884ccf0776df3e2cd2024ae0593a093bd9c92b2f296d8e08886ab
7
+ data.tar.gz: e21f80afd09d7e397835c2ab2d6e88bb76f30999b5e2da60f53ed942bf11976bba044554b2c74c97659803b5a8e7215302d2f4d0290940678d934c5cb64749eb
data/CHANGELOG.md CHANGED
@@ -1,14 +1,73 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0 (2021-08-19)
3
+ ### [0.3.1](https://www.github.com/7urkm3n/pcloud/compare/v0.3.0...v0.3.1) (2021-09-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * version update ([9bf5268](https://www.github.com/7urkm3n/pcloud/commit/9bf52681a94e6b17ec721778bfaeee39c1750a36))
9
+
10
+ ## [0.3.0](https://www.github.com/7urkm3n/pcloud/compare/v0.2.0...v0.3.0) (2021-09-04)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
4
14
 
15
+ * initialization
16
+
17
+ ### Bug Fixes
18
+
19
+ * initialization ([6dc7735](https://www.github.com/7urkm3n/pcloud/commit/6dc77359c4bd3003ad05ed54705bfa70a6a95e62))
20
+
21
+ ## [0.2.0](https://www.github.com/7urkm3n/pcloud/compare/v0.1.0...v0.2.0) (2021-09-04)
22
+
23
+
24
+ ### ⚠ BREAKING CHANGES
25
+
26
+ * major update
5
27
 
6
28
  ### Features
7
29
 
8
- * version 0.1.0 ([bafbe4b](https://www.github.com/7urkm3n/pcloud/commit/bafbe4b1d0301eb99446c703176eb35d6dc41336))
30
+ * major update ([3c1a191](https://www.github.com/7urkm3n/pcloud/commit/3c1a1914606391739f08e29c264528ba3d02d112))
9
31
 
32
+ ## 0.1.0 (2021-08-19)
33
+
34
+ ### Features
35
+
36
+ - version 0.1.0 ([bafbe4b](https://www.github.com/7urkm3n/pcloud/commit/bafbe4b1d0301eb99446c703176eb35d6dc41336))
10
37
 
11
38
  ### Bug Fixes
12
39
 
13
- * fixing workflow ([858cab4](https://www.github.com/7urkm3n/pcloud/commit/858cab495be548013c3e61756e626ce17cd38db3))
14
- * workflows works, testing version auto bump ([9de8276](https://www.github.com/7urkm3n/pcloud/commit/9de82767c31c1ae003e268910b23108bba4f2e8c))
40
+ - fixing workflow ([858cab4](https://www.github.com/7urkm3n/pcloud/commit/858cab495be548013c3e61756e626ce17cd38db3))
41
+ - workflows works, testing version auto bump ([9de8276](https://www.github.com/7urkm3n/pcloud/commit/9de82767c31c1ae003e268910b23108bba4f2e8c))
42
+
43
+ #### v0.0.4
44
+
45
+ ##### Updates
46
+
47
+ - Minor changes
48
+ - Upload and Download added and avilable now
49
+ - Post method is avilable now.
50
+ - Upload/Download async version is on work.
51
+
52
+ #### v0.0.3
53
+
54
+ ##### Updates
55
+
56
+ - Minor updates
57
+ - Upload and Download added - needs maintain
58
+ - Post method fixed and added back
59
+
60
+ #### v0.0.2
61
+
62
+ ##### Updates
63
+
64
+ - Minor updates
65
+ - Test files added
66
+ - Removed `Post` method temporarily
67
+
68
+ #### v0.0.1
69
+
70
+ ##### Publish
71
+
72
+ - Available get Method
73
+ - Incoming {Upload|Download} files
data/README.md CHANGED
@@ -2,25 +2,28 @@
2
2
 
3
3
  This Gem provides a Ruby interface to [Pcloud.com](https://docs.pcloud.com).
4
4
 
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)
5
+ [![Build Status](https://github.com/7urkm3n/pcloud/workflows/release/badge.svg?branch=main)](https://github.com/7urkm3n/pcloud/actions?query=workflow%3Arelease) [![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
 
7
7
  <!-- [![Gem Version](https://badgen.net/rubygems/v/pcloud)](https://rubygems.org/gems/pcloud) -->
8
8
 
9
+ ##### Want to contribute? [Doc Link](https://github.com/7urkm3n/pcloud/CONTRIBUTE.md)
10
+
9
11
  ## Installation and Configuration
10
12
 
11
13
  Add `pcloud` to your Gemfile, and then run `bundle install`
12
14
 
13
- ``` ruby
15
+ ```ruby
14
16
  gem 'pcloud'
15
17
  ```
16
18
 
17
19
  or install via gem
18
20
 
19
- ``` bash
21
+ ```bash
20
22
  gem install pcloud
21
23
  ```
22
24
 
23
25
  ###### Rails
26
+
24
27
  to generate `Rails` initializer file
25
28
 
26
29
  ```bash
@@ -35,87 +38,109 @@ config/initializers/pcloud.rb
35
38
 
36
39
  ### Instantiating a client
37
40
 
38
- ``` ruby
41
+ ```ruby
39
42
  require 'pcloud'
40
43
 
41
44
  pcloud = Pcloud::Client.new(
42
45
  username: 'email',
43
46
  password: 'password',
44
- )
45
- ```
47
+ ).authenticate
46
48
 
49
+ pcloud.get("listfolder", folderid: 0)
50
+ ```
47
51
 
48
52
  ### Global configuration
49
53
 
50
54
  The library can also be configured globally on the `Pcloud` class.
51
55
 
52
- ``` ruby
56
+ ```ruby
53
57
  Pcloud.username = 'email'
54
58
  Pcloud.password = 'password'
59
+ Pcloud.authenticate
60
+
61
+ Pcloud.get("listfolder", folderid: 0)
55
62
  ```
56
63
 
57
- <!-- ### Logging
64
+ ### Logging
58
65
 
59
66
  By default errors are logged in STDOUT level, also `Rails.logger` available.
60
67
 
61
- ``` ruby
68
+ ```ruby
62
69
  Pcloud.logger = Rails.logger
63
- ``` -->
70
+ ```
71
+
72
+ ### Working with methods
64
73
 
65
- ## Working with methods
74
+ Available methods:
66
75
 
67
- Currently, only available custom Get method.
76
+ - <b> Get </b>
77
+ - <b> Post </b>
78
+ - <b> File handling </b>
68
79
 
69
- File Upload and Download methods are coming soon.
80
+ ###### addition!
70
81
 
82
+ > Some apis need to be `raw` format, just add `raw` in params. `params: {fileid: ..987, raw: true}`
83
+ > For example `gettextfile` https://docs.pcloud.com/methods/streaming/gettextfile.html
71
84
 
72
- #### Get methods
85
+ #### Get method
73
86
 
74
- ``` ruby
87
+ ```ruby
75
88
  Pcloud.get("getip")
76
89
  Pcloud.get("getdigest")
77
90
 
78
91
  # with params
79
- Pcloud.get("listfolder", folderid: 0)
92
+ params = {folderid: 0}
93
+ Pcloud.get("listfolder", params)
80
94
  ```
81
- <!-- Pcloud.get("createfolder", folderid: 0, name: "new folder name", ...) -->
82
-
83
- #### Post methods
84
95
 
85
- ``` ruby
86
- # if any of pcloud endpoints requires payload on POST request, please create an issue.
96
+ #### Post method
87
97
 
88
- # with params
89
- Pcloud.post("createfolder", folderid: 0, name: "new folder name")
98
+ ```ruby
99
+ payload = {}
100
+ params = {folderid: 0, name: "new folder name"}
101
+ Pcloud.post("createfolder", payload, params)
90
102
  ```
91
103
 
92
- #### [Files](https://docs.pcloud.com/methods/file/)
104
+ ### [File methods](https://docs.pcloud.com/methods/file/)
105
+
93
106
  ##### [Download File](https://docs.pcloud.com/methods/file/downloadfile.html)
94
107
 
95
- ``` ruby
96
- #obtain filelink from: https://docs.pcloud.com/methods/streaming/getfilelink.html
108
+ ```ruby
109
+ # optional params: filename, destination
110
+ # destination by default current_path
111
+ Pcloud.file.download({fileid: 987532135})
97
112
 
98
113
  Pcloud.file.download(
99
- url: filelink, #required
100
- destination: "#{Dir.pwd}/Downloads", #required
101
- filename: "hehe.txt" #optional
114
+ fileid: 987532135, #required
115
+ destination: "#{Dir.pwd}/Downloads", #optional
116
+ filename: "hehe.txt" #optional
102
117
  )
103
118
  ```
104
119
 
105
- ##### [Upload File](https://docs.pcloud.com/methods/file/uploadfile.html)
120
+ ##### [Download Folder](#)
106
121
 
107
- ``` ruby
108
- # still in BETA! -
109
- # only supports single file upload
122
+ ```ruby
123
+ # optional params: filename, destination
124
+ # destination by default current_path
125
+ Pcloud.file.download_folder({folderid: 123456789})
126
+ ```
127
+
128
+ ##### [Upload File](https://docs.pcloud.com/methods/file/uploadfile.html)
110
129
 
111
- file = File.open("/Users/7urkm3n/Downloads/anything.file")
130
+ ```ruby
112
131
  params = {
113
- folderid: 0, #required
114
- filename: "anything.txt" #required
132
+ folderid: 0, #required
133
+ nopartial: 1,
115
134
  }
116
- payload = {file: file}
135
+ # multiple uploads
136
+ file1 = File.open("./Rakefile")
137
+ file2 = File.open("./README.md")
138
+ file3 = File.open("./Gemfile")
139
+ payload = { files: [file1,file2,file3] }
140
+
117
141
  Pcloud.file.upload(params, payload)
118
142
  ```
119
143
 
120
144
  ### Supported Ruby versions
145
+
121
146
  2.2+
data/lib/pcloud/client.rb CHANGED
@@ -1,51 +1,64 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
+ require_relative './request'
4
+ require_relative "./files/file_handler"
3
5
 
4
6
  module Pcloud
5
7
  class Client
6
8
  attr_writer :username, :password
9
+ attr_accessor :auth_token
7
10
 
8
11
  def initialize(options = {})
9
12
  @username, @password = options.values_at(:username, :password)
13
+ @auth_token = options[:auth_token]
10
14
  end
11
15
 
12
- def get(path, params = {})
13
- resource(path).get(params)
16
+ def get(path, params={})
17
+ request(:get, path, params)
14
18
  end
15
19
 
16
- def post(path, params = {})
17
- resource(path).post(params)
20
+ def post(path, payload={}, params={})
21
+ request(:post, path, params, payload)
18
22
  end
19
23
 
20
24
  def file
21
- Resource.new(self).file()
25
+ @file ||= FileHandler.new(self)
22
26
  end
23
27
 
24
28
  def http_client
25
- @client ||= RestClient::Resource.new(BASE_URL)
29
+ @http_client ||= RestClient::Resource.new(BASE_URL)
26
30
  end
27
31
 
28
- def auth
29
- @auth ||= begin
30
- raise ConfigurationError, :username unless @username
31
- raise ConfigurationError, :password unless @password
32
- digest = JSON.parse(RestClient.get("#{BASE_URL}/getdigest"))['digest']
33
- passworddigest = digest_data(@password + digest_data( @username.downcase ) + digest)
34
- JSON.parse(
35
- RestClient.get("#{BASE_URL}/userinfo?getauth=1&logout=1",
36
- {params: {username: @username, digest: digest, passworddigest: passworddigest}})
37
- )['auth']
38
- end
32
+ def authenticate(options = {})
33
+ @auth_token = authorize(options)['auth']
34
+ self
39
35
  end
40
36
 
41
- private
37
+ private
42
38
 
43
- def resource(path)
44
- Resource.new(self, path)
39
+ def request(verb, path, params, payload = {})
40
+ Pcloud::Request.call(self, verb, path, params, payload)
41
+ end
42
+
43
+ def authorize(options)
44
+ raise ConfigurationError, :username unless @username
45
+ raise ConfigurationError, :password unless @password
46
+ digest = JSON.parse(RestClient.get("#{BASE_URL}/getdigest"))['digest']
47
+ passworddigest = digest_data(@password + digest_data( @username.downcase ) + digest)
48
+ [:username, :digest, :passworddigest, :password].each { |k| options.delete(k) }
49
+ params = {params: {
50
+ username: @username,
51
+ digest: digest,
52
+ passworddigest: passworddigest,
53
+ device: "pcloud-ruby",
54
+ getauth: 1
55
+ }.merge!(options)}
56
+ JSON.parse(RestClient.get("#{BASE_URL}/userinfo", params)) #['auth']
45
57
  end
46
58
 
47
59
  def digest_data text
48
60
  Digest::SHA1.hexdigest(text)
49
61
  end
62
+
50
63
  end
51
64
  end
@@ -1,35 +1,51 @@
1
- require 'rest-client'
1
+ require 'open-uri'
2
+ require 'zip'
2
3
 
3
4
  module Pcloud
4
5
  class FileHandler
6
+
5
7
  def initialize(client)
6
8
  @client = client
7
9
  end
8
10
 
9
11
  def upload(params, payload)
10
- create_request(:post, 'uploadfile', params, payload).call
12
+ request(:post, 'uploadfile', params, payload)
11
13
  end
12
14
 
13
15
  def download(params)
14
- url = params[:url]
15
- begin
16
- res = RestClient.get(url)
17
- rescue => e
18
- raise HTTPError.new(:HTTPError, e.message)
16
+ # destination = params[:destination] ? params[:destination] : '.'
17
+ # data = request(:get, "getfilelink", {fileid: params[:fileid], forcedownload: 1})
18
+ # url = "https://#{data[:hosts][0]+data[:path]}"
19
+ # IO.copy_stream(URI.open(url), "#{destination}/#{url.split("/").last}")
20
+ # File.write("#{destination}/#{url.split("/").last}", URI.open(url).read)
21
+
22
+ destination = params[:destination] || '.'
23
+ filename = params[:filename] || nil
24
+ if !filename
25
+ stat = request(:get, "stat", {fileid: params[:fileid]})
26
+ filename = stat[:metadata][:name]
19
27
  end
20
-
21
- filename = params[:filename] ? params[:filename] : url.split("/").last
22
- File.open("#{params[:destination]}/#{filename}", 'wb' ) do |f|
23
- f.write res
28
+ File.write("#{destination}/#{filename}", request(:get, "gettextfile", {fileid: params[:fileid], raw: true}))
29
+ end
30
+
31
+ def download_folder(params)
32
+ data = request(:get, "listfolder", {folderid: params[:folderid]})
33
+ destination = params[:destination] || '.'
34
+ folder_name = params[:filename] || data[:metadata][:name] << ".zip"
35
+ stringio = Zip::OutputStream::write_buffer do |zio|
36
+ data[:metadata][:contents].each do |content|
37
+ zio.put_next_entry(content[:name])
38
+ zio.write(request(:get, "gettextfile", {fileid: content[:fileid], raw: true}))
39
+ end
24
40
  end
25
- res.code
41
+ stringio.rewind #reposition buffer pointer to the beginning
42
+ File.new("#{destination}/#{folder_name}","wb").write(stringio.sysread) #write buffer to zipfile
26
43
  end
27
44
 
28
- private
45
+ private
29
46
 
30
- def create_request(verb, path, params, payload = {})
31
- Request.new(@client, verb, path, params, payload)
47
+ def request(verb, path, params, payload = {})
48
+ Pcloud::Request.call(@client, verb, path, params, payload)
32
49
  end
33
-
34
50
  end
35
51
  end
@@ -1,46 +1,43 @@
1
1
  module Pcloud
2
- class Request
3
- def initialize(client, verb, path, params, payload)
4
- @client, @verb, @path, @params, @payload = client, verb, path, params, payload
5
- end
6
-
7
- def call
8
- params = {params: {}}
9
- params[:params].merge!(@params, {auth: @client.auth})
10
- http = @client.http_client
11
- res = case @verb
12
- when :get
13
- begin
14
- http[@path].get(params)
15
- rescue => e
16
- handle_response(e.http_code, e.message)
17
- end
18
- when :post
19
- begin
20
- http[@path].post(@payload, params)
21
- rescue => e
22
- handle_response(e.http_code, e.message)
2
+ module Request
3
+ class << self
4
+ def call(client, verb, path, params, payload={})
5
+ params = {params: {}.merge!(params, {auth: client.auth_token})}
6
+ http = client.http_client
7
+ res = case verb
8
+ when :get
9
+ begin
10
+ http[path].get(params)
11
+ rescue => e
12
+ handle_response(e.http_code, e.message)
13
+ end
14
+ when :post
15
+ begin
16
+ http[path].post(payload, params)
17
+ rescue => e
18
+ handle_response(e.http_code, e.message)
19
+ end
20
+ else
21
+ raise "Unsupported verb (get and post available): #{verb}"
23
22
  end
24
- else
25
- raise "Unsupported verb: #{@verb}"
26
- end
27
- JSON.parse(res.body, { symbolize_names: true })
28
- end
23
+ return res.body if params[:params][:raw]
24
+ JSON.parse(res.body, { symbolize_names: true })
25
+ end
29
26
 
30
27
  private
31
28
 
32
- def handle_response(status_code, body)
33
- case status_code
34
- when 400
35
- raise HTTPError.new(:HTTPError, body)
36
- when 401
37
- raise AuthenticationError, body
38
- when 404
39
- raise HTTPError.new(:HTTPError, body)
40
- else
41
- raise Error, "Unknown error (status code #{status_code}): #{body}"
29
+ def handle_response(status_code, body)
30
+ case status_code
31
+ when 400
32
+ raise HTTPError.new(:HTTPError, body)
33
+ when 401
34
+ raise AuthenticationError, body
35
+ when 404
36
+ raise HTTPError.new(:HTTPError, body)
37
+ else
38
+ raise Error, "Unknown error (status code #{status_code}): #{body}"
39
+ end
42
40
  end
43
41
  end
44
-
45
42
  end
46
43
  end
@@ -1,3 +1,3 @@
1
1
  module Pcloud
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/pcloud.rb CHANGED
@@ -1,18 +1,21 @@
1
1
  autoload 'Logger', 'logger'
2
2
  require 'forwardable'
3
- require 'pcloud/client'
3
+ require_relative 'pcloud/client'
4
4
 
5
5
  module Pcloud
6
6
  BASE_URL = 'https://api.pcloud.com'.freeze
7
7
 
8
8
  class << self
9
9
  extend Forwardable
10
- def_delegators :default_client, :username=, :password=
11
- def_delegators :default_client, :get, :post
12
- def_delegators :default_client, :file
10
+ def_delegators :client, :auth_token=, :username=, :password=
11
+ def_delegators :client, :get, :post, :file, :authenticate
13
12
 
14
13
  attr_writer :logger
15
14
 
15
+ def client
16
+ @client ||= Pcloud::Client.new
17
+ end
18
+
16
19
  def logger
17
20
  @logger ||= begin
18
21
  log = Logger.new($stdout)
@@ -21,13 +24,8 @@ module Pcloud
21
24
  end
22
25
  end
23
26
 
24
- def default_client
25
- @default_client ||= Pcloud::Client.new
26
- end
27
27
  end
28
28
  end
29
29
 
30
- require 'pcloud/version'
31
- require 'pcloud/request'
32
- require 'pcloud/resource'
33
- require 'pcloud/exceptions'
30
+ require_relative './pcloud/version'
31
+ require_relative './pcloud/exceptions'
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rovshen Gurdov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-19 00:00:00.000000000 Z
11
+ date: 2021-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.2.0
47
+ version: 1.3.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.2.0
54
+ version: 1.3.2
55
55
  description: Pcloud is cloud storage upload/download/share from pcloud.com. Please,
56
56
  check available methods in Github Doc...
57
57
  email:
@@ -70,7 +70,6 @@ files:
70
70
  - lib/pcloud/exceptions.rb
71
71
  - lib/pcloud/files/file_handler.rb
72
72
  - lib/pcloud/request.rb
73
- - lib/pcloud/resource.rb
74
73
  - lib/pcloud/version.rb
75
74
  homepage: https://github.com/7urkm3n/pcloud
76
75
  licenses:
@@ -1,29 +0,0 @@
1
- require "pcloud/files/file_handler"
2
-
3
- module Pcloud
4
- class Resource
5
-
6
- def initialize(client, path = "")
7
- @client, @path = client, path
8
- end
9
-
10
- def get(params)
11
- create_request(:get, params).call
12
- end
13
-
14
- def post(params, payload = {})
15
- create_request(:post, params, payload).call
16
- end
17
-
18
- def file
19
- @file ||= FileHandler.new(@client)
20
- end
21
-
22
- private
23
-
24
- def create_request(verb, params, payload = {})
25
- Request.new(@client, verb, @path, params, payload)
26
- end
27
-
28
- end
29
- end