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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bc6a66525cb7bfd47085851a95dbc1656759f92960611d1d66e5f466025c800
4
- data.tar.gz: 3eb54b53ab7c2c97ece4db9a074cbf75d6aa602ba727c917a6f88dbc97997c92
3
+ metadata.gz: 6d2d4a15b64f7b12aeb37ea79a46d0fb0a24c05237e233a3a8d58318e1cb9668
4
+ data.tar.gz: 8e99af1069835bf83aec4d57f4a3bc62f9a0d26378758ea3a4d22c4ceb06af9e
5
5
  SHA512:
6
- metadata.gz: 0ce986fc8cdedaed9773209c26afbaf08091d4285abbb40126a0fcc0fcac99d77bd1ce1250bed6cdce4dd79e445076ca49469f6ce0c2e3ccfb597a36bf41f79f
7
- data.tar.gz: 5aa4fb9d5dd96227b61c18c2bc537ad4b73338509e8a0e6b710cc06415228c41f67efb7719258ae954eb0fe9f36fae55d9151622021fb1f4d8116767aae1cad8
6
+ metadata.gz: c2d382dece8651dc09d5838db291ae1006dccb525c61ac41b031875ff1d5a10d14484078b0e6cb4602c31ee2c2fffcff2fb8b44846c4bd2b0b116f7b90c7d8b6
7
+ data.tar.gz: dfe07a834b0ca71fb469acb6b017a83352e6519db2b436aee3dd5217385ac8885fc579ef5baab0b85b9c535e3a49b211a42aff1e4114238cc9c06514f0dedde5
data/CHANGELOG.md CHANGED
@@ -1,13 +1,20 @@
1
- ## 0.2.0 2021-09-26
1
+ ## 0.2.1 2021-10-07
2
2
 
3
- New
4
- * An `.exists?` method has been added to `Pcloud::Folder` and `Pcloud::File`
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
- Change
8
- * `Pcloud::Folder` and `Pcloud::File` `created_at` and `modified_at` timestamps are now returned as Ruby `Time` objects
9
- * Some error class names and messages have been cleaned up for additional clarity and consistency.
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] && is_invalid_path_param?(params[:path])
43
- raise ManformedUpdateParams.new(":path param must start and end with `/`")
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 is_invalid_path_param?(path_param)
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
- raise MissingParameter.new(":path or :id is required") unless params[:path] || params[:id]
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
- parse_one(
100
- Client.execute(
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 `file` parameter must be an instance of Ruby `File`") unless file.is_a?(::File)
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 UnsuportedUpdateParams < StandardError; end
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 UnsuportedUpdateParams.new("Must be one of #{SUPPORTED_UPDATE_PARAMS}")
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 ManformedUpdateParams.new(":path param must start and end with `/`")
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
- raise MissingParameter.new(":path or :id is required") unless params[:path] || params[:id]
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
- parse_one(
109
- Client.execute(
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
@@ -1,3 +1,3 @@
1
1
  module Pcloud
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcloud_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hunsche Jones