pcloud 0.0.2 → 0.1.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: f149800e09ac0b4f7e8f73604197bfb8a471e35f5402a03f7e238c34791b412c
4
- data.tar.gz: cb22e032de376f1fe61ea06dad968c7cf0c61f52d9c9c7d35b55c2e1802bbae0
3
+ metadata.gz: bb75c427f836b4d247ec4fcf9274d241602f56b42b9db36f4b2933b032f65c9e
4
+ data.tar.gz: 8ac6d05ace840e3e97da605b639f1a1aba3d8f47d8fb3d2e015334b2c6fd2ade
5
5
  SHA512:
6
- metadata.gz: a8312ecf45d3d0d5c43414d994fa5014152664820e22e7d175cc29a5d4d5dd57d080dd462d97de5e95c9545330f6906a0193d9af2b4c7d261fe8227afbef374a
7
- data.tar.gz: b04c21315cfccc22e6e68bfb39b00d40e900348de038ed61958cba2f4bd1f8e5537818e8b8bad84f6b270ed26815abbdefaf395a7adfed8c0c2b039e3f6fb9a1
6
+ metadata.gz: 0c5817e6034dbcb5f68c92c5d075c610ee37dbcb57cc7a38c79ece949634d3d8f56065ba1b906af9950e56943729964ca99697c30abbf5d6136a18d18bcc29dc
7
+ data.tar.gz: 9ca0c32931e65cc3a52bd0e64ba8767481599b357a91ca69f789162f875641101b225c8f581f125d548ece41fe888b010da53eccec5d274bd59db2353685e7f0
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2021-08-19)
4
+
5
+
6
+ ### Features
7
+
8
+ * version 0.1.0 ([bafbe4b](https://www.github.com/7urkm3n/pcloud/commit/bafbe4b1d0301eb99446c703176eb35d6dc41336))
9
+
10
+
11
+ ### Bug Fixes
12
+
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))
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
 
@@ -77,15 +77,45 @@ Pcloud.get("getdigest")
77
77
 
78
78
  # with params
79
79
  Pcloud.get("listfolder", folderid: 0)
80
- Pcloud.get("createfolder", folderid: 0, name: "new folder name", ...)
81
80
  ```
81
+ <!-- Pcloud.get("createfolder", folderid: 0, name: "new folder name", ...) -->
82
82
 
83
- <!-- #### Post methods
83
+ #### Post methods
84
84
 
85
85
  ``` ruby
86
+ # if any of pcloud endpoints requires payload on POST request, please create an issue.
87
+
86
88
  # with params
87
- pcloud.get("createfolder", folderid: 0, name: "new folder name")
88
- ``` -->
89
+ Pcloud.post("createfolder", folderid: 0, name: "new folder name")
90
+ ```
91
+
92
+ #### [Files](https://docs.pcloud.com/methods/file/)
93
+ ##### [Download File](https://docs.pcloud.com/methods/file/downloadfile.html)
94
+
95
+ ``` ruby
96
+ #obtain filelink from: https://docs.pcloud.com/methods/streaming/getfilelink.html
97
+
98
+ Pcloud.file.download(
99
+ url: filelink, #required
100
+ destination: "#{Dir.pwd}/Downloads", #required
101
+ filename: "hehe.txt" #optional
102
+ )
103
+ ```
104
+
105
+ ##### [Upload File](https://docs.pcloud.com/methods/file/uploadfile.html)
106
+
107
+ ``` ruby
108
+ # still in BETA! -
109
+ # only supports single file upload
110
+
111
+ file = File.open("/Users/7urkm3n/Downloads/anything.file")
112
+ params = {
113
+ folderid: 0, #required
114
+ filename: "anything.txt" #required
115
+ }
116
+ payload = {file: file}
117
+ Pcloud.file.upload(params, payload)
118
+ ```
89
119
 
90
120
  ### Supported Ruby versions
91
121
  2.2+
@@ -1,5 +1,3 @@
1
-
2
- #Global set
3
1
  Pcloud.username = "username" # ENV['PCLOUD_USERNAME']
4
2
  Pcloud.password = "password" # ENV['PCLOUD_PASSWORD']
5
3
  #Pcloud.logger = Rails.logger
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
@@ -11,7 +8,8 @@ module Pcloud
11
8
  class << self
12
9
  extend Forwardable
13
10
  def_delegators :default_client, :username=, :password=
14
- def_delegators :default_client, :get
11
+ def_delegators :default_client, :get, :post
12
+ def_delegators :default_client, :file
15
13
 
16
14
  attr_writer :logger
17
15
 
@@ -24,9 +22,12 @@ module Pcloud
24
22
  end
25
23
 
26
24
  def default_client
27
- @default_client ||= begin
28
- Pcloud::Client.new
29
- end
25
+ @default_client ||= Pcloud::Client.new
30
26
  end
31
27
  end
32
28
  end
29
+
30
+ require 'pcloud/version'
31
+ require 'pcloud/request'
32
+ require 'pcloud/resource'
33
+ require 'pcloud/exceptions'
data/lib/pcloud/client.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'json'
2
2
  require 'rest-client'
3
- require 'pcloud/exceptions'
4
3
 
5
4
  module Pcloud
6
5
  class Client
@@ -17,11 +16,13 @@ module Pcloud
17
16
  def post(path, params = {})
18
17
  resource(path).post(params)
19
18
  end
20
-
19
+
20
+ def file
21
+ Resource.new(self).file()
22
+ end
23
+
21
24
  def http_client
22
- @client ||= begin
23
- RestClient::Resource.new(BASE_URL)
24
- end
25
+ @client ||= RestClient::Resource.new(BASE_URL)
25
26
  end
26
27
 
27
28
  def auth
@@ -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 "Error status `#{key}': #{message}"
11
+ super "#{key} Bad request: #{message}"
12
12
  end
13
13
  end
14
-
15
14
  end
@@ -0,0 +1,35 @@
1
+ require 'rest-client'
2
+
3
+ module Pcloud
4
+ class FileHandler
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def upload(params, payload)
10
+ create_request(:post, 'uploadfile', params, payload).call
11
+ end
12
+
13
+ def download(params)
14
+ url = params[:url]
15
+ begin
16
+ res = RestClient.get(url)
17
+ rescue => e
18
+ raise HTTPError.new(:HTTPError, e.message)
19
+ end
20
+
21
+ filename = params[:filename] ? params[:filename] : url.split("/").last
22
+ File.open("#{params[:destination]}/#{filename}", 'wb' ) do |f|
23
+ f.write res
24
+ end
25
+ res.code
26
+ end
27
+
28
+ private
29
+
30
+ def create_request(verb, path, params, payload = {})
31
+ Request.new(@client, verb, path, params, payload)
32
+ end
33
+
34
+ end
35
+ end
@@ -1,44 +1,42 @@
1
1
  module Pcloud
2
2
  class Request
3
- def initialize(client, verb, path, params)
4
- @client, @verb , @path, @params = client, verb, path, params
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
- http[@path].get( params )
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
- http[@path].post( params )
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
- body = res.body ? res.body.chomp : nil
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 Error, "Bad request: #{body}"
35
+ raise HTTPError.new(:HTTPError, body)
34
36
  when 401
35
37
  raise AuthenticationError, body
36
38
  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"
39
+ raise HTTPError.new(:HTTPError, body)
42
40
  else
43
41
  raise Error, "Unknown error (status code #{status_code}): #{body}"
44
42
  end
@@ -1,7 +1,9 @@
1
+ require "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
+ @file ||= 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
@@ -1,3 +1,3 @@
1
1
  module Pcloud
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
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.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rovshen Gurdov
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-31 00:00:00.000000000 Z
11
+ date: 2021-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -60,7 +60,7 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - Changelog.md
63
+ - CHANGELOG.md
64
64
  - LICENSE
65
65
  - README.md
66
66
  - lib/generators/pcloud.rb
@@ -68,15 +68,16 @@ 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
71
72
  - lib/pcloud/request.rb
72
73
  - lib/pcloud/resource.rb
73
74
  - lib/pcloud/version.rb
74
- homepage: https://github.com/7urkm3n/pcloud/
75
+ homepage: https://github.com/7urkm3n/pcloud
75
76
  licenses:
76
77
  - MIT
77
78
  metadata:
78
79
  bug_tracker_uri: https://github.com/7urkm3n/pcloud/issues
79
- changelog_uri: https://github.com/7urkm3n/pcloud/blob/v0.0.2/Changelog.md
80
+ changelog_uri: https://github.com/7urkm3n/pcloud/blob/master/CHANGELOG.md
80
81
  documentation_uri: https://github.com/7urkm3n/pcloud
81
82
  source_code_uri: https://github.com/7urkm3n/pcloud
82
83
  post_install_message:
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubygems_version: 3.0.3
98
+ rubygems_version: 3.2.3
98
99
  signing_key:
99
100
  specification_version: 4
100
101
  summary: Secure and simple to use cloud storage for your datas...
data/Changelog.md DELETED
@@ -1,13 +0,0 @@
1
- #### v0.0.1
2
-
3
- ##### Publish
4
-
5
- * Available get Method
6
- * Incoming {Upload|Download} files
7
-
8
-
9
-
10
- <!-- === 0.0.2 / 2020-09-...
11
- ==== Updates | Enhancements
12
- * Added to {Upload|Download} files.
13
- -->