kloudless 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: aadd0e43b6426a49c8172bbc0e5f5dcae993744c
4
- data.tar.gz: 69dde9fd66257fa64f3a05e87ab8fa7c88596695
3
+ metadata.gz: 87e04e539ed7a1b806e462f1e156ad3fa60241d4
4
+ data.tar.gz: 5d2b394818e6db3824ef1287b39bcad1284081ef
5
5
  SHA512:
6
- metadata.gz: 4c61c7453b87e8e0b8e333d91ecfb8dd1783433a183882764ec13287f9c5e409f30cb06cbcdae9836ff10cf3da786ccf5a00ffc8fdc7ce50cb738b31a9f76b96
7
- data.tar.gz: c487c4ce1952757c2c84e332c3d6294b6a17f84b51df1b343fba952b329a4b68dc0add13763c45783c097d1200e8ec0beb907b57a6ffcc7b429a044a40cb87a7
6
+ metadata.gz: 66a884a58eb3ccb6722facf07cb3096b4379c02e857c79693193dc0faf5d80783aa7b950e545316bed6e80d317ce518e68988fb6e9cd016f7567a0a82b6903b8
7
+ data.tar.gz: 3d42f44a173284b6204333bf1a47dc060d33c8b53d8da17aeb8a96fc5725e6a88bb30e79bf0ddf466ab0f143b079d13055d1fd51e9de6caa55283e9227b98151
@@ -0,0 +1,13 @@
1
+ # upcoming
2
+
3
+ # 0.2.0
4
+
5
+ - Query parameters for POST/PUT/PATCH requests.
6
+ - Bearer Tokens instead of Account Keys.
7
+ - Better/fixed file upload and download methods.
8
+ - Fixed gemspec warnings
9
+ - Fixed gemspec homepage. @tyrust
10
+
11
+ # 0.1.0
12
+
13
+ Initial release
data/Rakefile CHANGED
@@ -8,3 +8,7 @@ Rake::TestTask.new do |t|
8
8
  end
9
9
 
10
10
  task :default => :test
11
+
12
+ task :console do
13
+ exec "irb -r byebug -r kloudless -I ./lib"
14
+ end
@@ -8,8 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Kloudless::VERSION
9
9
  spec.authors = ["Jerry Cheung"]
10
10
  spec.email = ["jollyjerry@gmail.com"]
11
- spec.summary = %q{Kloudless API client}
12
- spec.homepage = "https://github.com/jch/kloudless"
11
+ spec.summary = %q{Ruby Kloudless API client. The last cloud storage API you’ll ever need.}
12
+ spec.description = %q{Ruby Kloudless API client}
13
+ spec.homepage = "https://github.com/jch/kloudless-ruby"
13
14
  spec.license = "MIT"
14
15
  spec.required_ruby_version = ">= 2.1"
15
16
 
@@ -19,7 +20,7 @@ Gem::Specification.new do |spec|
19
20
  spec.require_paths = ["lib"]
20
21
 
21
22
  spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "byebug"
24
- spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency "rake", "~> 10"
24
+ spec.add_development_dependency "byebug", "~> 3"
25
+ spec.add_development_dependency "minitest", "~> 5"
25
26
  end
@@ -3,7 +3,6 @@ require_relative "kloudless/error"
3
3
  require_relative "kloudless/http"
4
4
  require_relative "kloudless/model"
5
5
  require_relative "kloudless/account"
6
- require_relative "kloudless/account_key"
7
6
  require_relative "kloudless/team"
8
7
  require_relative "kloudless/file"
9
8
  require_relative "kloudless/multipart_upload"
@@ -18,20 +17,20 @@ module Kloudless
18
17
  API_VERSION = "v0".freeze
19
18
  API_URL = "https://api.kloudless.com/#{API_VERSION}".freeze
20
19
 
21
- # Public: Authorize with API Key or Account Key. Returns nothing.
20
+ # Public: Authorize with API Key or Bearer Token. Returns nothing.
22
21
  #
23
22
  # Options:
24
23
  # :api_key
25
- # :account_key
24
+ # :token
26
25
  #
27
26
  # https://developers.kloudless.com/docs#authorization
28
27
  def self.authorize(options = {})
29
28
  Kloudless::HTTP.headers["Authorization"] = if options[:api_key]
30
29
  "ApiKey #{options[:api_key]}"
31
- elsif options[:account_key]
32
- "AccountKey #{options[:account_key]}"
30
+ elsif options[:token]
31
+ "Bearer #{options[:token]}"
33
32
  else
34
- raise ArgumentError.new(":api_key or :account_key required")
33
+ raise ArgumentError.new(":api_key or :token required")
35
34
  end
36
35
  end
37
36
 
@@ -5,7 +5,7 @@ module Kloudless
5
5
  # https://developers.kloudless.com/docs#accounts
6
6
  class Account < Model
7
7
  # Public: Returns Kloudless::Collection. Raises Kloudless::Error.
8
- def self.list(params = {})
8
+ def self.list(**params)
9
9
  Kloudless::Collection.new(self, http.get("/accounts", params: params))
10
10
  end
11
11
 
@@ -13,8 +13,8 @@ module Kloudless
13
13
  new(http.get("/accounts/#{account_id}", params: params))
14
14
  end
15
15
 
16
- def self.update(account_id:, **params)
17
- new(http.patch("/accounts/#{account_id}", params: params))
16
+ def self.update(account_id:, params: {}, **data)
17
+ new(http.patch("/accounts/#{account_id}", params: params, data: data))
18
18
  end
19
19
 
20
20
  def self.delete(account_id:)
@@ -22,8 +22,8 @@ module Kloudless
22
22
  end
23
23
 
24
24
  # Public: TODO: Returns ???. Raises Kloudless::Error.
25
- def self.import(params = {})
26
- http.post("/accounts", params: params)
25
+ def self.import(params: {}, **data)
26
+ http.post("/accounts", params: params, data: data)
27
27
  end
28
28
 
29
29
  class << self
@@ -153,8 +153,6 @@ module Kloudless
153
153
  forbidden: ForbiddenError,
154
154
  service_forbidden: ServiceForbiddenError,
155
155
  not_found: NotFoundError,
156
- method_not_allowed: MethodNotAllowedError,
157
- not_acceptable: NotAcceptableError,
158
156
  naming_conflict: NamingConflictError,
159
157
  too_many_requests: TooManyRequestsError,
160
158
  too_many_service_requests: TooManyServiceRequestsError,
@@ -167,6 +165,7 @@ module Kloudless
167
165
  bad_gateway: BadGatewayError,
168
166
  service_not_available: ServiceNotAvailableError,
169
167
  gateway_timeout: GatewayTimeoutError,
170
- insufficient_storage: InsufficientStorageError }
168
+ insufficient_storage: InsufficientStorageError
169
+ }
171
170
  end
172
171
  end
@@ -1,35 +1,48 @@
1
+ require 'json'
2
+
1
3
  module Kloudless
2
4
  # https://developers.kloudless.com/docs#files
3
5
  class File < Model
4
- def self.upload(account_id:, **params)
6
+ def self.upload(account_id:, data:, parent_id:, file_name:, **params)
7
+ headers = {
8
+ 'X-Kloudless-Metadata' => {parent_id: parent_id, name: file_name}.to_json,
9
+ 'Content-Type' => 'application/octet-stream'
10
+ }
5
11
  path = "/accounts/#{account_id}/files"
6
- new(http.post(path, params: params))
12
+ new(http.post(path, params: params, data: data, headers: headers,
13
+ parse_request: false))
7
14
  end
8
15
 
9
- def self.metadata(account_id:, file_id:)
16
+ def self.upload_from_url(account_id:, params: {}, **data)
17
+ path = "/accounts/#{account_id}/files"
18
+ new(http.post(path, params: params, data: data))
19
+ end
20
+
21
+ def self.metadata(account_id:, file_id:, **params)
10
22
  path = "/accounts/#{account_id}/files/#{file_id}"
11
- new(http.get(path))
23
+ new(http.get(path, params: params))
12
24
  end
13
25
 
14
- def self.rename(account_id:, file_id:, **params)
26
+ def self.rename(account_id:, file_id:, params: {}, **data)
15
27
  path = "/accounts/#{account_id}/files/#{file_id}"
16
- new(http.patch(path, params: params))
28
+ new(http.patch(path, params: params, data: data))
17
29
  end
18
30
 
19
- # TODO: unclear how to post binary data over net-http
20
- def self.update
21
- raise NotImplementedError
31
+ def self.update(account_id:, file_id:, data:)
32
+ path = "/accounts/#{account_id}/files/#{file_id}"
33
+ new(http.put(path, data: data, parse_request: false,
34
+ headers: {'Content-Type' => 'application/octet-stream'}))
22
35
  end
23
36
 
24
- def self.download(account_id:, file_id:)
37
+ def self.download(account_id:, file_id:, **params)
25
38
  path = "/accounts/#{account_id}/files/#{file_id}/contents"
26
- http.get_raw(path)
39
+ http.get(path, params: params, parse_response: false)
27
40
  end
28
41
 
29
- def self.copy(account_id:, file_id:, parent_id:, **params)
42
+ def self.copy(account_id:, file_id:, parent_id:, params: {}, **data)
30
43
  path = "/accounts/#{account_id}/files/#{file_id}/copy"
31
- params[:parent_id] = parent_id
32
- new(http.post(path, params: params))
44
+ data[:parent_id] = parent_id
45
+ new(http.post(path, params: params, data: data))
33
46
  end
34
47
 
35
48
  def self.delete(account_id:, file_id:, **params)
@@ -2,15 +2,15 @@ module Kloudless
2
2
  # https://developers.kloudless.com/docs#folders
3
3
  class Folder < Model
4
4
  # https://developers.kloudless.com/docs#folders-create-a-folder
5
- def self.create(account_id:, **params)
5
+ def self.create(account_id:, params: {}, **data)
6
6
  path = "/accounts/#{account_id}/folders"
7
- new(http.post(path, params: params))
7
+ new(http.post(path, params: params, data: data))
8
8
  end
9
9
 
10
10
  # https://developers.kloudless.com/docs#folders-retrieve-folder-metadata
11
- def self.metadata(account_id:, folder_id:)
11
+ def self.metadata(account_id:, folder_id:, **params)
12
12
  path = "/accounts/#{account_id}/folders/#{folder_id}"
13
- new(http.get(path))
13
+ new(http.get(path, params: params))
14
14
  end
15
15
 
16
16
  # https://developers.kloudless.com/docs#folders-retrieve-folder-contents
@@ -20,16 +20,16 @@ module Kloudless
20
20
  end
21
21
 
22
22
  # https://developers.kloudless.com/docs#folders-rename/move-a-folder
23
- def self.rename(account_id:, folder_id:, **params)
23
+ def self.rename(account_id:, folder_id:, params: {}, **data)
24
24
  path = "/accounts/#{account_id}/folders/#{folder_id}"
25
- new(http.patch(path, params: params))
25
+ new(http.patch(path, params: params, data: data))
26
26
  end
27
27
 
28
28
  # https://developers.kloudless.com/docs#folders-copy-a-folder
29
- def self.copy(account_id:, folder_id:, parent_id:, **params)
30
- params[:parent_id] = parent_id
29
+ def self.copy(account_id:, folder_id:, parent_id:, params: {}, **data)
31
30
  path = "/accounts/#{account_id}/folders/#{folder_id}/copy"
32
- new(http.post(path, params: params))
31
+ data[:parent_id] = parent_id
32
+ new(http.post(path, params: params, data: data))
33
33
  end
34
34
 
35
35
  # https://developers.kloudless.com/docs#folders-delete-a-folder
@@ -1,4 +1,5 @@
1
1
  require "net/http"
2
+ require "json"
2
3
 
3
4
  module Kloudless
4
5
  # Net::HTTP wrapper
@@ -8,60 +9,50 @@ module Kloudless
8
9
  @headers ||= {}
9
10
  end
10
11
 
11
- def self.get(path, params: {}, headers: {})
12
+ def self.request(method, path, params: {}, data: {}, headers: {},
13
+ parse_request: true, parse_response: true)
12
14
  uri = URI.parse(Kloudless::API_URL + path)
13
15
  uri.query = URI.encode_www_form(params) if !params.empty?
14
16
 
15
- request = Net::HTTP::Get.new(uri)
16
- request.initialize_http_header(headers)
17
-
18
- execute(request)
19
- end
17
+ if ['post', 'put', 'patch'].member?(method)
18
+ headers["Content-Type"] ||= "application/json"
19
+ end
20
20
 
21
- # TODO: decouple Kloudless::HTTP methods from #execute. Have methods return
22
- # request object, defaults to json parsing, but allow the option for raw
23
- def self.get_raw(path)
24
- uri = URI.parse(Kloudless::API_URL + path)
25
- request = Net::HTTP::Get.new(uri)
21
+ request = Net::HTTP.const_get(method.capitalize).new(uri)
26
22
  request.initialize_http_header(headers)
27
23
 
28
- execute(request, parse_json: false)
29
- end
30
-
31
-
32
- def self.post(path, params: {}, headers: {})
33
- uri = URI.parse(Kloudless::API_URL + path)
34
- headers["Content-Type"] = "application/json"
35
-
36
- request = Net::HTTP::Post.new(uri)
37
- request.initialize_http_header(headers)
38
- request.set_form_data(params) if !params.empty?
24
+ if !data.empty?
25
+ data = data.to_json if parse_request
26
+ request.body = data
27
+ end
39
28
 
40
- execute(request)
29
+ execute(request, parse_response: parse_response)
41
30
  end
42
31
 
43
- def self.patch(path, params: {}, headers: {})
44
- uri = URI.parse(Kloudless::API_URL + path)
45
- headers["Content-Type"] = "application/json"
46
-
47
- request = Net::HTTP::Post.new(uri)
48
- request.initialize_http_header(headers)
49
- request.set_form_data(params) if !params.empty?
32
+ def self.get(path, **kwargs)
33
+ self.request('get', path, **kwargs)
34
+ end
50
35
 
51
- execute(request)
36
+ def self.post(path, params: {}, data: {}, headers: {}, **kwargs)
37
+ self.request('post', path, params: params, data: data,
38
+ headers: headers, **kwargs)
52
39
  end
53
40
 
54
- def self.delete(path, params: {}, headers: {})
55
- uri = URI.parse(Kloudless::API_URL + path)
56
- uri.query = URI.encode_www_form(params) if !params.empty?
41
+ def self.put(path, params: {}, data: {}, headers: {}, **kwargs)
42
+ self.request('put', path, params: params, data: data,
43
+ headers: headers, **kwargs)
44
+ end
57
45
 
58
- request = Net::HTTP::Delete.new(uri)
59
- request.initialize_http_header(headers)
46
+ def self.patch(path, params: {}, data: {}, headers: {}, **kwargs)
47
+ self.request('patch', path, params: params, data: data,
48
+ headers: headers, **kwargs)
49
+ end
60
50
 
61
- execute(request)
51
+ def self.delete(path, params: {}, headers: {}, **kwargs)
52
+ self.request('delete', path, params: params, headers: headers, **kwargs)
62
53
  end
63
54
 
64
- def self.execute(request, parse_json: true)
55
+ def self.execute(request, parse_response: true)
65
56
  uri = request.uri
66
57
  @last_request = request
67
58
  headers.each {|k,v| request[k] = v}
@@ -70,12 +61,12 @@ module Kloudless
70
61
  http.request(request)
71
62
  }
72
63
 
73
- if parse_json
64
+ if parse_response
74
65
  json = JSON.parse(response.body)
75
66
  raise Kloudless::Error.from_json(json) if json["error_code"]
76
67
  json
77
68
  else
78
- response
69
+ response.body
79
70
  end
80
71
  end
81
72
 
@@ -7,10 +7,10 @@ module Kloudless
7
7
  end
8
8
 
9
9
  # https://developers.kloudless.com/docs#links-create-a-link
10
- def self.create(account_id:, file_id:, **params)
11
- params[:file_id] = file_id
10
+ def self.create(account_id:, file_id:, params: {}, **data)
11
+ data[:file_id] = file_id
12
12
  path = "/accounts/#{account_id}/links"
13
- new(http.post(path, params: params))
13
+ new(http.post(path, params: params, data: data))
14
14
  end
15
15
 
16
16
  # https://developers.kloudless.com/docs#links-retrieve-a-link
@@ -20,15 +20,15 @@ module Kloudless
20
20
  end
21
21
 
22
22
  # https://developers.kloudless.com/docs#links-update-a-link
23
- def self.update(account_id:, link_id:, **params)
23
+ def self.update(account_id:, link_id:, params: {}, **data)
24
24
  path = "/accounts/#{account_id}/links/#{link_id}"
25
- new(http.patch(path, params: params))
25
+ new(http.patch(path, params: params, data: data))
26
26
  end
27
27
 
28
28
  # https://developers.kloudless.com/docs#links-delete-a-link
29
- def self.delete(account_id:, link_id:)
29
+ def self.delete(account_id:, link_id:, **params)
30
30
  path = "/accounts/#{account_id}/links/#{link_id}"
31
- new(http.delete(path))
31
+ new(http.delete(path, params: params))
32
32
  end
33
33
  end
34
34
  end
@@ -1,9 +1,9 @@
1
1
  module Kloudless
2
2
  # https://developers.kloudless.com/docs#multipart-upload
3
3
  class MultipartUpload < Model
4
- def self.init(account_id:, **params)
4
+ def self.init(account_id:, params: {}, **data)
5
5
  path = "/accounts/#{account_id}/multipart"
6
- new(http.post(path, params: params))
6
+ new(http.post(path, params: params, data: data))
7
7
  end
8
8
 
9
9
  def self.retrieve(account_id:, multipart_id:)
@@ -12,25 +12,28 @@ module Kloudless
12
12
  end
13
13
 
14
14
  # https://developers.kloudless.com/docs#multipart-upload-upload-part
15
- def self.upload(account_id:, multipart_id:, part_number:, **params)
15
+ def self.upload(account_id:, multipart_id:, data:, part_number:, **params)
16
16
  path = "/accounts/#{account_id}/multipart/#{multipart_id}"
17
17
  params[:part_number] = part_number
18
- new(http.put(path, params: params))
18
+ headers = {'Content-Type' => 'application/octet-stream'}
19
+ new(http.put(path, params: params, data: data, headers: headers,
20
+ parse_request: false))
19
21
  end
20
22
 
21
23
  # https://developers.kloudless.com/docs#multipart-upload-finalize-multipart-session
22
- def self.finalize(account_id:, multipart_id:)
24
+ def self.finalize(account_id:, multipart_id:, params: {}, **data)
23
25
  path = "/accounts/#{account_id}/multipart/#{multipart_id}/complete"
24
- new(http.post(path))
26
+ new(http.post(path, params: params, data: data))
25
27
  end
26
28
 
27
29
  # https://developers.kloudless.com/docs#multipart-upload-abort-multipart-session
28
- def self.abort(account_id:, multipart_id:)
30
+ def self.abort(account_id:, multipart_id:, **params)
29
31
  path = "/accounts/#{account_id}/multipart/#{multipart_id}"
30
- new(http.delete(path))
32
+ new(http.delete(path, params: params))
31
33
  end
32
34
 
33
35
  class << self
36
+ alias_method :create, :init
34
37
  alias_method :delete, :abort
35
38
  end
36
39
  end
@@ -1,3 +1,3 @@
1
1
  module Kloudless
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -50,8 +50,8 @@ class Kloudless::AccountTest < Minitest::Test
50
50
  token: "foo",
51
51
  token_secret: "bar"
52
52
  }
53
- Kloudless.http.expect(:post, args: ["/accounts", {params: attributes}]) do
54
- Kloudless::Account.import(attributes)
53
+ Kloudless.http.expect(:post, args: ["/accounts", {params: {}, data: attributes}]) do
54
+ Kloudless::Account.import(**attributes)
55
55
  end
56
56
  end
57
57
 
@@ -63,7 +63,7 @@ class Kloudless::AccountTest < Minitest::Test
63
63
  end
64
64
 
65
65
  def test_update_account
66
- Kloudless.http.expect(:patch, args: ["/accounts/1", {params: {active: true}}]) do
66
+ Kloudless.http.expect(:patch, args: ["/accounts/1", {params: {}, data: {active: true}}]) do
67
67
  account = Kloudless::Account.update(account_id: 1, active: true)
68
68
  assert_kind_of Kloudless::Account, account
69
69
  end
@@ -2,35 +2,51 @@ require_relative "../test_helper"
2
2
 
3
3
  class Kloudless::FileTest < Minitest::Test
4
4
  def test_upload_file
5
- Kloudless.http.expect(:post, returns: {"id" => "foo"}, args: ["/accounts/1/files", params: {}]) do
6
- file = Kloudless::File.upload(account_id: 1)
5
+ metadata = {parent_id: "parent", name: "foo.txt"}
6
+ Kloudless.http.expect(:post, returns: {"id" => "foo"}, args: [
7
+ "/accounts/1/files", data: "FILE CONTENTS",
8
+ headers: {'X-Kloudless-Metadata' => metadata.to_json,
9
+ "Content-Type" => 'application/octet-stream'},
10
+ params: {}, parse_request: false]) do
11
+ file = Kloudless::File.upload(account_id: 1, data: "FILE CONTENTS",
12
+ parent_id: metadata[:parent_id],
13
+ file_name: metadata[:name])
7
14
  assert_kind_of Kloudless::File, file
8
15
  end
9
16
  end
10
17
 
11
18
  def test_retrieve_file_metadata
12
- Kloudless.http.expect(:get, returns: {"id" => "foo"}, args:["/accounts/1/files/2"]) do
19
+ Kloudless.http.expect(:get, returns: {"id" => "foo"}, args:["/accounts/1/files/2", params: {}]) do
13
20
  metadata = Kloudless::File.metadata(account_id: 1, file_id: 2)
14
21
  assert_kind_of Kloudless::File, metadata # TODO: not really a type
15
22
  end
16
23
  end
17
24
 
18
25
  def test_rename_file
19
- Kloudless.http.expect(:patch, returns: {"id" => "foo"}, args:["/accounts/1/files/2", params: {name: "new-name.txt"}]) do
26
+ Kloudless.http.expect(:patch, returns: {"id" => "foo"}, args:["/accounts/1/files/2", params: {}, data: {name: "new-name.txt"}]) do
20
27
  file = Kloudless::File.rename(account_id: 1, file_id: 2, name: "new-name.txt")
21
28
  assert_kind_of Kloudless::File, file
22
29
  end
23
30
  end
24
31
 
32
+ def test_update
33
+ Kloudless.http.expect(:put, returns: {"id" => "foo"}, args: [
34
+ "/accounts/1/files/2", data: "FILE CONTENTS", parse_request: false,
35
+ headers: {'Content-Type' => 'application/octet-stream'}]) do
36
+ file = Kloudless::File.update(account_id: 1, file_id: 2, data: "FILE CONTENTS")
37
+ assert_kind_of Kloudless::File, file
38
+ end
39
+ end
40
+
25
41
  def test_download
26
- Kloudless.http.expect(:get_raw, returns: "FILE CONTENTS", args:["/accounts/1/files/2/contents"]) do
42
+ Kloudless.http.expect(:get, returns: "FILE CONTENTS", args:["/accounts/1/files/2/contents", params: {}, parse_response: false]) do
27
43
  contents = Kloudless::File.download(account_id: 1, file_id: 2)
28
44
  assert_equal "FILE CONTENTS", contents
29
45
  end
30
46
  end
31
47
 
32
48
  def test_copy
33
- Kloudless.http.expect(:post, returns: {"id" => "foo"}, args:["/accounts/1/files/2/copy", params: {parent_id: "parent-id"}]) do
49
+ Kloudless.http.expect(:post, returns: {"id" => "foo"}, args:["/accounts/1/files/2/copy", params: {}, data: {parent_id: "parent-id"}]) do
34
50
  file = Kloudless::File.copy(account_id: 1, file_id: 2, parent_id: "parent-id")
35
51
  assert_kind_of Kloudless::File, file
36
52
  end
@@ -2,14 +2,14 @@ require_relative "../test_helper"
2
2
 
3
3
  class Kloudless::FolderTest < Minitest::Test
4
4
  def test_create
5
- Kloudless.http.expect(:post, args: ["/accounts/1/folders", params: {}]) do
6
- folder = Kloudless::Folder.create(account_id: 1)
5
+ Kloudless.http.expect(:post, args: ["/accounts/1/folders", params: {}, data: {name: "foo"}]) do
6
+ folder = Kloudless::Folder.create(account_id: 1, name: "foo")
7
7
  assert_kind_of Kloudless::Folder, folder
8
8
  end
9
9
  end
10
10
 
11
11
  def test_metadata
12
- Kloudless.http.expect(:get, args: ["/accounts/1/folders/2"]) do
12
+ Kloudless.http.expect(:get, args: ["/accounts/1/folders/2", params: {}]) do
13
13
  folder = Kloudless::Folder.metadata(account_id: 1, folder_id: 2)
14
14
  assert_kind_of Kloudless::Folder, folder
15
15
  end
@@ -25,14 +25,14 @@ class Kloudless::FolderTest < Minitest::Test
25
25
  end
26
26
 
27
27
  def test_rename
28
- Kloudless.http.expect(:patch, args: ["/accounts/1/folders/2", params: {name: "foo.md"}]) do
28
+ Kloudless.http.expect(:patch, args: ["/accounts/1/folders/2", params: {}, data: {name: "foo.md"}]) do
29
29
  folder = Kloudless::Folder.rename(account_id: 1, folder_id: 2, name: "foo.md")
30
30
  assert_kind_of Kloudless::Folder, folder
31
31
  end
32
32
  end
33
33
 
34
34
  def test_copy
35
- Kloudless.http.expect(:post, args: ["/accounts/1/folders/2/copy", params: {parent_id: "parent-id"}]) do
35
+ Kloudless.http.expect(:post, args: ["/accounts/1/folders/2/copy", params: {}, data: {parent_id: "parent-id"}]) do
36
36
  folder = Kloudless::Folder.copy(account_id: 1, folder_id: 2, parent_id: "parent-id")
37
37
  assert_kind_of Kloudless::Folder, folder
38
38
  end
@@ -11,7 +11,7 @@ class Kloudless::LinkTest < Minitest::Test
11
11
  end
12
12
 
13
13
  def test_create_link
14
- Kloudless.http.expect(:post, args: ["/accounts/1/links", params: {file_id: "file-id"}]) do
14
+ Kloudless.http.expect(:post, args: ["/accounts/1/links", params: {}, data: {file_id: "file-id"}]) do
15
15
  link = Kloudless::Link.create(account_id: 1, file_id: "file-id")
16
16
  assert_kind_of Kloudless::Link, link
17
17
  end
@@ -25,14 +25,14 @@ class Kloudless::LinkTest < Minitest::Test
25
25
  end
26
26
 
27
27
  def test_update_link
28
- Kloudless.http.expect(:patch, args: ["/accounts/1/links/2", params: {password: "foo"}]) do
28
+ Kloudless.http.expect(:patch, args: ["/accounts/1/links/2", params: {}, data: {password: "foo"}]) do
29
29
  link = Kloudless::Link.update(account_id: 1, link_id: 2, password: "foo")
30
30
  assert_kind_of Kloudless::Link, link
31
31
  end
32
32
  end
33
33
 
34
34
  def test_delete_link
35
- Kloudless.http.expect(:delete, args: ["/accounts/1/links/2"]) do
35
+ Kloudless.http.expect(:delete, args: ["/accounts/1/links/2", params: {}]) do
36
36
  link = Kloudless::Link.delete(account_id: 1, link_id: 2)
37
37
  assert_kind_of Kloudless::Link, link
38
38
  end
@@ -2,8 +2,9 @@ require_relative "../test_helper"
2
2
 
3
3
  class Kloudless::MultipartUploadTest < Minitest::Test
4
4
  def test_init_multipart_upload
5
- Kloudless.http.expect(:post, returns: {"id" => "foo"}, args:["/accounts/1/multipart", params: {overwrite: true}]) do
6
- upload = Kloudless::MultipartUpload.init(account_id: 1, overwrite: true)
5
+ Kloudless.http.expect(:post, returns: {"id" => "foo"}, args:[
6
+ "/accounts/1/multipart", params: {overwrite: true}, data: {parent_id: "foo"}]) do
7
+ upload = Kloudless::MultipartUpload.create(account_id: 1, params: {overwrite: true}, parent_id: "foo")
7
8
  assert_kind_of Kloudless::MultipartUpload, upload
8
9
  end
9
10
  end
@@ -16,21 +17,25 @@ class Kloudless::MultipartUploadTest < Minitest::Test
16
17
  end
17
18
 
18
19
  def test_upload_multipart_upload
19
- Kloudless.http.expect(:put, args: ["/accounts/1/multipart/2", params: {part_number: 1}]) do
20
- upload = Kloudless::MultipartUpload.upload(account_id: 1, multipart_id: 2, part_number: 1)
20
+ Kloudless.http.expect(:put, args: ["/accounts/1/multipart/2", data: "FILE CONTENTS",
21
+ headers: {'Content-Type' => 'application/octet-stream'},
22
+ params: {part_number: 1},
23
+ parse_request: false]) do
24
+ upload = Kloudless::MultipartUpload.upload(account_id: 1, multipart_id: 2,
25
+ data: "FILE CONTENTS", part_number: 1)
21
26
  assert_kind_of Kloudless::MultipartUpload, upload
22
27
  end
23
28
  end
24
29
 
25
30
  def test_finalize_multipart_upload
26
- Kloudless.http.expect(:post, args: ["/accounts/1/multipart/2/complete"]) do
31
+ Kloudless.http.expect(:post, args: ["/accounts/1/multipart/2/complete", params: {}, data: {}]) do
27
32
  upload = Kloudless::MultipartUpload.finalize(account_id: 1, multipart_id: 2)
28
33
  assert_kind_of Kloudless::MultipartUpload, upload
29
34
  end
30
35
  end
31
36
 
32
37
  def test_abort_multipart_upload
33
- Kloudless.http.expect(:delete, args: ["/accounts/1/multipart/2"]) do
38
+ Kloudless.http.expect(:delete, args: ["/accounts/1/multipart/2", params: {}]) do
34
39
  upload = Kloudless::MultipartUpload.abort(account_id: 1, multipart_id: 2)
35
40
  assert_kind_of Kloudless::MultipartUpload, upload
36
41
  end
@@ -15,11 +15,11 @@ class KloudlessTest < Minitest::Test
15
15
  end
16
16
  end
17
17
 
18
- def test_authorize_account_key
19
- Kloudless.authorize(account_key: "ACCOUNT_KEY")
18
+ def test_authorize_bearer_token
19
+ Kloudless.authorize(token: "BEARER_TOKEN")
20
20
  Kloudless.http.mock_response(Struct.new(:body).new('{}')) do
21
21
  Kloudless::Account.list
22
- assert_equal "AccountKey ACCOUNT_KEY", Kloudless::HTTP.last_request["Authorization"]
22
+ assert_equal "Bearer BEARER_TOKEN", Kloudless::HTTP.last_request["Authorization"]
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kloudless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Cheung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-13 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,45 +28,45 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3'
48
48
  type: :development
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: '0'
54
+ version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description:
68
+ version: '5'
69
+ description: Ruby Kloudless API client
70
70
  email:
71
71
  - jollyjerry@gmail.com
72
72
  executables: []
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
+ - CHANGELOG.md
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
@@ -82,7 +83,6 @@ files:
82
83
  - kloudless.gemspec
83
84
  - lib/kloudless.rb
84
85
  - lib/kloudless/account.rb
85
- - lib/kloudless/account_key.rb
86
86
  - lib/kloudless/collection.rb
87
87
  - lib/kloudless/error.rb
88
88
  - lib/kloudless/event.rb
@@ -97,7 +97,6 @@ files:
97
97
  - script/changelog
98
98
  - script/package
99
99
  - script/release
100
- - test/kloudless/account_key_test.rb
101
100
  - test/kloudless/account_test.rb
102
101
  - test/kloudless/collection_test.rb
103
102
  - test/kloudless/error_test.rb
@@ -110,7 +109,7 @@ files:
110
109
  - test/kloudless/team_test.rb
111
110
  - test/kloudless_test.rb
112
111
  - test/test_helper.rb
113
- homepage: https://github.com/jch/kloudless
112
+ homepage: https://github.com/jch/kloudless-ruby
114
113
  licenses:
115
114
  - MIT
116
115
  metadata: {}
@@ -130,12 +129,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
129
  version: '0'
131
130
  requirements: []
132
131
  rubyforge_project:
133
- rubygems_version: 2.2.2
132
+ rubygems_version: 2.4.6
134
133
  signing_key:
135
134
  specification_version: 4
136
- summary: Kloudless API client
135
+ summary: Ruby Kloudless API client. The last cloud storage API you’ll ever need.
137
136
  test_files:
138
- - test/kloudless/account_key_test.rb
139
137
  - test/kloudless/account_test.rb
140
138
  - test/kloudless/collection_test.rb
141
139
  - test/kloudless/error_test.rb
@@ -1,26 +0,0 @@
1
- module Kloudless
2
- # Account Keys can be used instead of API Keys to restrict access to a
3
- # specific account’s data. This is most useful for client-side requests.
4
- #
5
- # https://developers.kloudless.com/docs#account-keys
6
- class AccountKey < Model
7
- # Public: Returns Kloudless::Collection of AccountKey. Raises
8
- # Kloudless::Error.
9
- #
10
- # :account_ids - Array of account_ids to fetch keys for
11
- def self.list(account_ids:, **params)
12
- path = "/accounts/#{account_ids.join(',')}/keys"
13
- Kloudless::Collection.new(self, http.get(path, params: params))
14
- end
15
-
16
- def self.retrieve(account_id:, key_id:, **params)
17
- path = "/accounts/#{account_id}/keys/#{key_id}"
18
- new(http.get(path, params: params))
19
- end
20
-
21
- def self.delete(account_id:, key_id:)
22
- path = "/accounts/#{account_id}/keys/#{key_id}"
23
- new(http.delete(path))
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- require_relative "../test_helper"
2
- require 'minitest'
3
-
4
- class Kloudless::AccountKeyTest < Minitest::Test
5
- def test_list_account_keys
6
- Kloudless.http.expect(:get, returns: {"objects" => [{}]}, args: ["/accounts/1,2/keys", params: {}]) do
7
- account_keys = Kloudless::AccountKey.list(account_ids: [1,2])
8
- assert_kind_of Kloudless::Collection, account_keys
9
- assert_kind_of Kloudless::AccountKey, account_keys.first
10
- end
11
- end
12
-
13
- def test_retrieve_account_key
14
- Kloudless.http.expect(:get, args: ["/accounts/1/keys/2", params: {}]) do
15
- account_key = Kloudless::AccountKey.retrieve(account_id: 1, key_id: 2)
16
- assert_kind_of Kloudless::AccountKey, account_key
17
- end
18
- end
19
-
20
- def test_delete_account_key
21
- Kloudless.http.expect(:delete, args: ["/accounts/1/keys/2"]) do
22
- account_key = Kloudless::AccountKey.delete(account_id: 1, key_id: 2)
23
- assert_kind_of Kloudless::AccountKey, account_key
24
- end
25
- end
26
- end