pcloud_api 0.2.2 → 0.2.3

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: 9fc8c976ed07fce0322907df07ed86d464b5924e6fb465aaa2bc5154b5fe95e8
4
- data.tar.gz: e86aaee5ef4453da35281d3d3840078dfc639552c8913de6f4389a571e862256
3
+ metadata.gz: fcef0e50f4deec3483d2ce4f23882a453ed3cea1fac57ef507ee1523824aba33
4
+ data.tar.gz: 287a6037d5f81652a936d611a69cd2b40dd4ce5cdfbde03093242e0bcc7e061a
5
5
  SHA512:
6
- metadata.gz: a75daa528c2c263b4f5e1e2f57e81090a440c391860ef5bfc714967156cfe5b289c1b3d644428f5213e13c60fabca6745263d7cc6c7ba77c800d6177d8e1a888
7
- data.tar.gz: 520875db136cfb2961b8bdee6f9948af3701aaef3eb318860ec7b7b018fd7ac500edc27ea0581765ce5e63e948dea842bd7a94a85ba3279323ec14fa21d91915
6
+ metadata.gz: b9cc930698584cfebe1fbb501798cb15ccb8116e8d231f632c30813f37bc0912550cee1d3bcdfee66fd21add00e8d2874b8471173ca4c77b67a544b7efe2740a
7
+ data.tar.gz: ecdc92c74476eaed41515b5206d5c428f17fcddf870cd28f162fd382ba97abd11d095ef36ded8f155a188a36fe7a32afc4703df7275a779ec37628281de3da58
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.3 2021-12-14
2
+
3
+ **Changes**
4
+ 1. `Pcloud::File`'s `upload` method no longer requires a `:filename` param, since pCloud just reads it off of the file object and ignores the param anyway
5
+ 2. Both `Pcloud::File` and `Pcloud::Folder`'s `update` and `update!` methods now allow either partial paths _(starting and ending with slashes)_ or full paths. This is a little more dangerous if you specify a full path and you meant partial, but it's a reasonable use case to support.
6
+
1
7
  ## 0.2.2 2021-10-09
2
8
 
3
9
  **Changes**
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # pCloud API
2
2
 
3
3
  [![CI](https://github.com/jhunschejones/pcloud_api/actions/workflows/ci.yml/badge.svg)](https://github.com/jhunschejones/pcloud_api/actions/workflows/ci.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/pcloud_api.svg)](https://badge.fury.io/rb/pcloud_api)
5
+ [![Gem Downloads](https://badgen.net/rubygems/dt/pcloud_api)](https://rubygems.org/gems/pcloud_api)
4
6
 
5
7
  The `pcloud_api` gem provides an intuitive Ruby interface for interacting with the [pCloud API](https://docs.pcloud.com/) using OAuth2. This gem does not attempt to replicate the entire functionality of the pCloud API but rather to provide quick and easy access for its most basic and common functionality. If you are looking for a lower-level pCloud API wrapper, [`pcloud`](https://github.com/7urkm3n/pcloud) might be a better fit for you.
6
8
 
@@ -9,7 +11,7 @@ The `pcloud_api` gem provides an intuitive Ruby interface for interacting with t
9
11
  Add this line to your application's Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'pcloud_api'
14
+ gem "pcloud_api"
13
15
  ```
14
16
 
15
17
  And then execute:
@@ -28,6 +30,10 @@ Or install it yourself as:
28
30
 
29
31
  ## Usage
30
32
 
33
+ ### Generating an access token
34
+
35
+ To use the `pcloud_api` client, you will need to first generate an access token. You may do this by cloning and running the script in [`./bin/generate_access_token`](https://github.com/jhunschejones/pcloud_api/blob/master/bin/generate_access_token). It will take you through the process of setting up a pCloud app and completing the OAuth2 flow in the browser.
36
+
31
37
  ### Configuration
32
38
 
33
39
  The `Pcloud::Client` can be configured by directly calling the `Pcloud::Client.configure` method in an initializer or somewhere else in your code at startup:
@@ -46,43 +52,50 @@ There are two main objects represented in the library, `Pcloud::File` and `Pclou
46
52
 
47
53
  The `Pcloud::File` API includes:
48
54
  ```ruby
49
- # Find files by file id or path:
55
+ # Find files by file :id or :path:
50
56
  Pcloud::File.find(1)
51
57
  Pcloud::File.find_by(path: "/images/jack_the_cat.jpg")
52
- # NOTE: find_by can also be used with :id, though this will take precedence
58
+ # NOTE: `find_by` can also be used with :id, though this will take precedence
53
59
  # over :path so just pick one or the other
54
60
 
55
- # Check if a file exists by id
61
+ # Check if a file exists by :id
56
62
  Pcloud::File.exists?(1)
57
63
 
58
64
  # Upload a new file, rename if one already exists with this name:
59
65
  Pcloud::File.upload(
60
- folder_id: 1,
61
- filename: "jack_goes_swimming.mp4",
66
+ path: "/Jack",
62
67
  file: File.open("/Users/joshua/Downloads/jack_goes_swimming.mp4")
63
68
  )
64
- # NOTE: the upload method will allow you to specify the :path or the :folder_id
65
- # or you can choose to pass neither paramenter and your files will be placed
66
- # in your root pCloud directory.
67
69
 
68
- # Upload a file, force overwrite of existing file:
70
+ # Upload a file, force overwrite if a file already exists with this name:
69
71
  Pcloud::File.upload!(
70
- folder_id: 1,
71
- filename: "jack_goes_swimming.mp4",
72
+ path: "/Jack",
72
73
  file: File.open("/Users/joshua/Downloads/jack_goes_swimming.mp4")
73
74
  )
74
75
 
76
+ # NOTE:
77
+ # The `upload` and `upload!` methods will allow you to specify either the :path
78
+ # or the :folder_id of the target parent directory, or you can choose to pass
79
+ # neither paramenter and your files will be placed in your root pCloud
80
+ # directory by default.
81
+
75
82
  # Rename a file:
76
83
  jack_goes_swimming.update(name: "That's one wet cat.mp4")
77
84
 
78
- # Move a file by updating the parent_folder_id or path:
85
+ # Move a file by updating the :parent_folder_id:
79
86
  jack_goes_swimming.update(parent_folder_id: 9000)
80
87
 
88
+ # Move a file by specifying the parent folder part of the path:
89
+ jack_goes_swimming.update(path: "/photos/") # NOTE: needs to start and end with slashes
90
+
91
+ # Move a file by specifying the entire new file path:
92
+ jack_goes_swimming.update(path: "/photos/jack_goes_swimming.mp4")
93
+
81
94
  # Delete a file:
82
95
  jack_goes_swimming.delete
83
96
 
84
97
  # Get a link to download a file:
85
- jack_goes_swimming.download_link
98
+ jack_goes_swimming.download_url
86
99
 
87
100
  # Access the parent folder of a file:
88
101
  jack_goes_swimming.parent_folder
@@ -90,27 +103,37 @@ jack_goes_swimming.parent_folder
90
103
 
91
104
  The `Pcloud::Folder` API is very similar:
92
105
  ```ruby
93
- # Find folders by folder id or path:
106
+ # Find folders by folder :id or :path:
94
107
  Pcloud::Folder.find(1)
95
108
  Pcloud::Folder.find_by(path: "/images")
96
- # NOTE: find_by can also be used with :id, though this will take precedence
109
+ # NOTE: `find_by` can also be used with :id, though this will take precedence
97
110
  # over :path so just pick one or the other
98
111
 
99
112
  # Check if a folder exists by id
100
113
  Pcloud::Folder.exists?(1)
101
114
 
102
- # Create a new folder by parent_folder_id and name:
115
+ # Create a new folder by :parent_folder_id and :name:
103
116
  Pcloud::Folder.first_or_create(parent_folder_id: 9000, name: "jack")
104
117
 
105
- # Create a new folder by path:
118
+ # Create a new folder by :path (parent directory must already exist):
106
119
  Pcloud::Folder.first_or_create(path: "/images/jack")
107
120
 
108
121
  # Rename a folder:
109
122
  jack_images.update(name: "Jack's Photo Library")
110
123
 
111
- # Move a folder by updating the parent_folder_id or path:
124
+ # Move a folder by updating the :parent_folder_id:
112
125
  jack_images.update(parent_folder_id: 9000)
113
126
 
127
+ # Move a folder by specifying the parent folder part of the path:
128
+ jack_images.update(path: "/photos/")
129
+ # NOTES:
130
+ # - Partial paths must start and end with slashes
131
+ # - All refrenced parent directories in the path must already exist
132
+
133
+ # Move a folder by specifying the entire new file path:
134
+ jack_images.update(path: "/photos/images/jack")
135
+ # NOTE: All refrenced parent directories in the path must already exist
136
+
114
137
  # Delete an empty folder:
115
138
  jack_images.delete
116
139
 
@@ -137,10 +160,6 @@ Pcloud::Client.execute("listrevisions", query: { fileid: 90000 })
137
160
  ```
138
161
  _(There are a few methods on the raw pCloud API that require manual login, which this gem does not yet support. If you find that you need access to these methods you may wish to look at using the [`pcloud`](https://github.com/7urkm3n/pcloud) gem instead.)_
139
162
 
140
- ### Generating an access token
141
-
142
- To use the `pcloud_api` client, you will need to first generate an access token. You may do this by cloning and running the script in `./bin/generate_access_token`. It will take you through the process of setting up a pCloud app and completing the OAuth2 flow in the browser.
143
-
144
163
  ## Development
145
164
 
146
165
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/lib/pcloud/client.rb CHANGED
@@ -24,8 +24,8 @@ module Pcloud
24
24
  headers: { "Authorization" => "Bearer #{access_token}" },
25
25
  timeout: TIMEOUT_SECONDS # this sets both the open and read timeouts to the same value
26
26
  }
27
- options.merge!({ query: query }) unless query.empty?
28
- options.merge!({ body: body }) unless body.empty?
27
+ options[:query] = query unless query.empty?
28
+ options[:body] = body unless body.empty?
29
29
  response = HTTParty.public_send(verb, "https://#{closest_server}/#{method}", options)
30
30
  json_response = JSON.parse(response.body)
31
31
  raise ErrorResponse.new(json_response["error"]) if json_response["error"]
@@ -44,7 +44,7 @@ module Pcloud
44
44
  def access_token
45
45
  @@access_token ||= ENV["PCLOUD_API_ACCESS_TOKEN"]
46
46
  return @@access_token unless @@access_token.nil?
47
- raise ConfigurationError.new("Missing bearer token")
47
+ raise ConfigurationError.new("Missing pCloud API access token")
48
48
  end
49
49
 
50
50
  # You can manually hit "https://<default_server_for_your_region>/getapiserver"
data/lib/pcloud/file.rb CHANGED
@@ -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_update_param?(params[:path])
43
- raise InvalidParameter.new(":path param must start and end with `/`")
42
+ if params[:path] && params[:path][0] != "/"
43
+ raise InvalidParameter.new(":path param must start with `/`")
44
44
  end
45
45
  query = {
46
46
  fileid: id,
@@ -73,13 +73,6 @@ module Pcloud
73
73
  "#{@download_url}/#{URI.encode_www_form_component(name)}"
74
74
  end
75
75
 
76
- private
77
-
78
- def is_invalid_path_update_param?(path_param)
79
- # Path params have to start and end with `/` when used with .update
80
- [path_param[0], path_param[-1]] != ["/", "/"]
81
- end
82
-
83
76
  class << self
84
77
  def exists?(id)
85
78
  find(id)
@@ -127,7 +120,7 @@ module Pcloud
127
120
  renameifexists: params[:overwrite] ? 0 : 1,
128
121
  path: params[:path],
129
122
  folderid: params[:folder_id],
130
- filename: params.fetch(:filename),
123
+ filename: params[:filename],
131
124
  file: file,
132
125
  }.compact,
133
126
  )
@@ -136,7 +129,7 @@ module Pcloud
136
129
  # so we return just one file out of this method.
137
130
  uploaded_file = parse_many(response).first
138
131
  raise UploadFailed if uploaded_file.nil?
139
- return uploaded_file
132
+ uploaded_file
140
133
  rescue KeyError => e
141
134
  missing_param = e.message.gsub("key not found: ", "")
142
135
  raise MissingParameter.new("#{missing_param} is required")
data/lib/pcloud/folder.rb CHANGED
@@ -34,8 +34,8 @@ module Pcloud
34
34
  unless (params.keys - SUPPORTED_UPDATE_PARAMS).empty?
35
35
  raise InvalidParameters.new("Must be one of #{SUPPORTED_UPDATE_PARAMS}")
36
36
  end
37
- if params[:path] && is_invalid_path_param?(params[:path])
38
- raise InvalidParameter.new(":path parameter must start and end with `/`")
37
+ if params[:path] && params[:path][0] != "/"
38
+ raise InvalidParameter.new(":path parameter must start with `/`")
39
39
  end
40
40
  query = {
41
41
  folderid: id,
@@ -72,13 +72,6 @@ module Pcloud
72
72
  @contents
73
73
  end
74
74
 
75
- private
76
-
77
- def is_invalid_path_param?(path_param)
78
- # Path params have to start and end with `/`
79
- [path_param[0], path_param[-1]] != ["/", "/"]
80
- end
81
-
82
75
  class << self
83
76
  def first_or_create(params)
84
77
  if params[:parent_folder_id] && params[:name]
@@ -1,3 +1,3 @@
1
1
  module Pcloud
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcloud_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hunsche Jones
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-09 00:00:00.000000000 Z
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,7 +100,7 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
- description:
103
+ description:
104
104
  email:
105
105
  - joshua@hunschejones.com
106
106
  executables: []
@@ -134,7 +134,7 @@ metadata:
134
134
  homepage_uri: https://github.com/jhunschejones/pcloud_api
135
135
  source_code_uri: https://github.com/jhunschejones/pcloud_api
136
136
  changelog_uri: https://github.com/jhunschejones/pcloud_api/blob/master/CHANGELOG.md
137
- post_install_message:
137
+ post_install_message:
138
138
  rdoc_options: []
139
139
  require_paths:
140
140
  - lib
@@ -149,8 +149,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  - !ruby/object:Gem::Version
150
150
  version: '0'
151
151
  requirements: []
152
- rubygems_version: 3.2.28
153
- signing_key:
152
+ rubygems_version: 3.2.22
153
+ signing_key:
154
154
  specification_version: 4
155
155
  summary: A Ruby library for interacting with the pCloud API
156
156
  test_files: []