pcloud_api 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -8
- data/lib/pcloud/file.rb +11 -13
- data/lib/pcloud/folder.rb +9 -11
- data/lib/pcloud/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d2d4a15b64f7b12aeb37ea79a46d0fb0a24c05237e233a3a8d58318e1cb9668
|
4
|
+
data.tar.gz: 8e99af1069835bf83aec4d57f4a3bc62f9a0d26378758ea3a4d22c4ceb06af9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d382dece8651dc09d5838db291ae1006dccb525c61ac41b031875ff1d5a10d14484078b0e6cb4602c31ee2c2fffcff2fb8b44846c4bd2b0b116f7b90c7d8b6
|
7
|
+
data.tar.gz: dfe07a834b0ca71fb469acb6b017a83352e6519db2b436aee3dd5217385ac8885fc579ef5baab0b85b9c535e3a49b211a42aff1e4114238cc9c06514f0dedde5
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
-
## 0.2.
|
1
|
+
## 0.2.1 2021-10-07
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
* The `.find_by` method on `Pcloud::Folder` and `Pcloud::File` can now be called with either `:id` or `:path`. NOTE: pCloud treats `:id` with precedence, so an error will be raised if the method is called with both parameters at once. _(Allowing precedence in a method like this would likely feel like unexpected behavior, so my intention was to make it immediately obvious to the end user.)_
|
3
|
+
**Changes**
|
4
|
+
1. Simplifying and cleaning up the errors returned from `Pcloud::Folder` and `Pcloud::File`
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
## 0.2.0 2021-10-07
|
7
|
+
|
8
|
+
**New**
|
9
|
+
1. An `.exists?` method has been added to `Pcloud::Folder` and `Pcloud::File`
|
10
|
+
2. The `.find_by` method on `Pcloud::Folder` and `Pcloud::File` can now be called with either `:id` or `:path` parameters.
|
11
|
+
* NOTE: pCloud treats `:id` with precedence, so an error will be raised if the method is called with both parameters at once. _(Allowing precedence in a method like this would likely feel like unexpected behavior, so my intention was to make it immediately obvious to the end user.)_
|
12
|
+
|
13
|
+
**Changes**
|
14
|
+
1. The `created_at` and `modified_at` timestamps on `Pcloud::Folder` and `Pcloud::File` are now returned as Ruby `Time` objects _(specifically [`TZInfo::TimeWithOffset`](https://www.rubydoc.info/gems/tzinfo/TZInfo/TimeWithOffset))_.
|
15
|
+
* NOTE: if you were previously parsing the string timestamps out into time objects, you may see errors like `no implicit conversion of TZInfo::TimeWithOffset into String`
|
16
|
+
2. Some error class names and messages have been cleaned up for additional clarity and consistency.
|
10
17
|
|
11
18
|
## 0.1.0 2021-09-26
|
12
19
|
|
13
|
-
Initial release
|
20
|
+
**Initial release** 🍰 🎉
|
data/lib/pcloud/file.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Pcloud
|
2
2
|
class File
|
3
|
-
class ManformedUpdateParams < StandardError; end
|
4
3
|
class InvalidParameter < StandardError; end
|
5
4
|
class InvalidParameters < StandardError; end
|
6
5
|
class MissingParameter < StandardError; end
|
@@ -10,6 +9,7 @@ module Pcloud
|
|
10
9
|
include Pcloud::TimeHelper
|
11
10
|
|
12
11
|
SUPPORTED_UPDATE_PARAMS = [:name, :parent_folder_id, :path].freeze
|
12
|
+
SUPPORTED_FIND_BY_PARAMS = [:id, :path].freeze
|
13
13
|
FILE_CATAGORIES = {
|
14
14
|
"0" => "uncategorized",
|
15
15
|
"1" => "image",
|
@@ -39,8 +39,8 @@ module Pcloud
|
|
39
39
|
unless (params.keys - SUPPORTED_UPDATE_PARAMS).empty?
|
40
40
|
raise InvalidParameters.new("Must be one of #{SUPPORTED_UPDATE_PARAMS}")
|
41
41
|
end
|
42
|
-
if params[:path] &&
|
43
|
-
raise
|
42
|
+
if params[:path] && is_invalid_path_update_param?(params[:path])
|
43
|
+
raise InvalidParameter.new(":path param must start and end with `/`")
|
44
44
|
end
|
45
45
|
query = {
|
46
46
|
fileid: id,
|
@@ -75,8 +75,8 @@ module Pcloud
|
|
75
75
|
|
76
76
|
private
|
77
77
|
|
78
|
-
def
|
79
|
-
# Path params have to start and end with `/`
|
78
|
+
def is_invalid_path_update_param?(path_param)
|
79
|
+
# Path params have to start and end with `/` when used with .update
|
80
80
|
[path_param[0], path_param[-1]] != ["/", "/"]
|
81
81
|
end
|
82
82
|
|
@@ -94,14 +94,12 @@ module Pcloud
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def find_by(params)
|
97
|
-
|
97
|
+
unless (params.keys - SUPPORTED_FIND_BY_PARAMS).empty?
|
98
|
+
raise InvalidParameters.new("Must be one of #{SUPPORTED_FIND_BY_PARAMS}")
|
99
|
+
end
|
98
100
|
raise InvalidParameters.new(":id takes precedent over :path, please only use one or the other") if params[:path] && params[:id]
|
99
|
-
|
100
|
-
|
101
|
-
"stat",
|
102
|
-
query: { path: params[:path], fileid: params[:id] }.compact
|
103
|
-
)
|
104
|
-
)
|
101
|
+
query = { path: params[:path], fileid: params[:id] }.compact
|
102
|
+
parse_one(Client.execute("stat", query: query))
|
105
103
|
end
|
106
104
|
|
107
105
|
def upload(params)
|
@@ -116,7 +114,7 @@ module Pcloud
|
|
116
114
|
|
117
115
|
def process_upload(params)
|
118
116
|
file = params.fetch(:file)
|
119
|
-
raise InvalidParameter.new("The
|
117
|
+
raise InvalidParameter.new("The :file parameter must be an instance of Ruby `File`") unless file.is_a?(::File)
|
120
118
|
|
121
119
|
# === pCloud API behavior notes: ===
|
122
120
|
# 1. If neither `path` nor `folder_id` is provided, the file will be
|
data/lib/pcloud/folder.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Pcloud
|
2
2
|
class Folder
|
3
|
-
class
|
4
|
-
class ManformedUpdateParams < StandardError; end
|
3
|
+
class InvalidParameter < StandardError; end
|
5
4
|
class InvalidParameters < StandardError; end
|
6
5
|
class MissingParameter < StandardError; end
|
7
6
|
|
@@ -9,6 +8,7 @@ module Pcloud
|
|
9
8
|
include Pcloud::TimeHelper
|
10
9
|
|
11
10
|
SUPPORTED_UPDATE_PARAMS = [:name, :parent_folder_id, :path].freeze
|
11
|
+
SUPPORTED_FIND_BY_PARAMS = [:id, :path].freeze
|
12
12
|
|
13
13
|
attr_reader :id, :path, :name, :parent_folder_id, :is_deleted, :created_at,
|
14
14
|
:modified_at
|
@@ -32,10 +32,10 @@ module Pcloud
|
|
32
32
|
|
33
33
|
def update(params)
|
34
34
|
unless (params.keys - SUPPORTED_UPDATE_PARAMS).empty?
|
35
|
-
raise
|
35
|
+
raise InvalidParameters.new("Must be one of #{SUPPORTED_UPDATE_PARAMS}")
|
36
36
|
end
|
37
37
|
if params[:path] && is_invalid_path_param?(params[:path])
|
38
|
-
raise
|
38
|
+
raise InvalidParameter.new(":path parameter must start and end with `/`")
|
39
39
|
end
|
40
40
|
query = {
|
41
41
|
folderid: id,
|
@@ -103,14 +103,12 @@ module Pcloud
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def find_by(params)
|
106
|
-
|
106
|
+
unless (params.keys - SUPPORTED_FIND_BY_PARAMS).empty?
|
107
|
+
raise InvalidParameters.new("Must be one of #{SUPPORTED_FIND_BY_PARAMS}")
|
108
|
+
end
|
107
109
|
raise InvalidParameters.new(":id takes precedent over :path, please only use one or the other") if params[:path] && params[:id]
|
108
|
-
|
109
|
-
|
110
|
-
"listfolder",
|
111
|
-
query: { path: params[:path], folderid: params[:id] }.compact
|
112
|
-
)
|
113
|
-
)
|
110
|
+
query = { path: params[:path], folderid: params[:id] }.compact
|
111
|
+
parse_one(Client.execute("listfolder", query: query))
|
114
112
|
end
|
115
113
|
end
|
116
114
|
end
|
data/lib/pcloud/version.rb
CHANGED