deta 0.1.1 → 0.1.2

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: 76a8441ba038bdfc44abe26a8568bd445e8bf943420ba82c8572708b514158ba
4
- data.tar.gz: 29e13de22bdb9900cf0510363c313dd0314a75be02fd3d3942130bc923ce0028
3
+ metadata.gz: f05ca2927027937bee800ea25cc34d867dc8099a9962120cfdb82f7282ee2107
4
+ data.tar.gz: 8033e175e38944a8b9533ba5e15ea5a5dd19f6e68e5bb6596c91df84be052125
5
5
  SHA512:
6
- metadata.gz: e7f7d384edbfad45567aacaf52bb53a5db5fbba052b51d3699b607bffc3a7eed31048f3846c75dfcab0b2b3b606b59dec57e1ee0bd4ad5636aad9d3be3e34187
7
- data.tar.gz: d76a5846a163b896f58c17eec943207a064275e551d7715dfa89b551e5ae6698c31acc694f688d898c7daa3a7ff21120bc9ead937baf7406e88db8727648f04d
6
+ metadata.gz: '091ea79e1bfbdb3b32a41ac7f7feb76f5b0b75584d8fe2340e6946ca8d87ce26aa7de9cbaad176d314239bdedadbdc1e16911a6d3b0f1dc0195e01b1e0e46178'
7
+ data.tar.gz: 2159e4b1f940e5de4a72f47187db05d80d4ea4add6a2aedb7929a2499ee21f10add8359d47a07ad1fe61a190186d433176872a28d5e137ea3d32cbc1278736a4
data/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## [Unreleased]
1
+ ## [0.1.2] - 2022-01-29
2
+
3
+ - Deta Drive put file
4
+ - Deta Drive list files
5
+ - Deta Drive get file
6
+ - Deta Drive delete files
7
+
8
+ ## [0.1.1] - 2022-01-29
9
+
10
+ - Cover Deta Base endpoints
2
11
 
3
12
  ## [0.1.0] - 2022-01-28
4
13
 
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deta (0.1.1)
4
+ deta (0.1.2)
5
5
  faraday (~> 2.1.0)
6
+ faraday-multipart (~> 1.0.3)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -10,7 +11,10 @@ GEM
10
11
  faraday (2.1.0)
11
12
  faraday-net_http (~> 2.0)
12
13
  ruby2_keywords (>= 0.0.4)
14
+ faraday-multipart (1.0.3)
15
+ multipart-post (>= 1.2, < 3)
13
16
  faraday-net_http (2.0.1)
17
+ multipart-post (2.1.1)
14
18
  rake (13.0.6)
15
19
  ruby2_keywords (0.0.5)
16
20
 
data/README.md CHANGED
@@ -91,7 +91,41 @@ detabase.fetch(query: [{hometown: "Boulder"}], limit: 1, last: "8523bdyxlqww")
91
91
 
92
92
  ## Drive
93
93
 
94
- `TODO:`
94
+ ```ruby
95
+ detadrive = client.drive("drive_name")
96
+ ```
97
+
98
+ ### Put File
99
+
100
+ ```ruby
101
+ detadrive.put("test.jpg", path: "./test.jpg", content_type: "image/jpeg")
102
+
103
+ detadrive.put("test.txt", data: "hello")
104
+
105
+ detadrive.put("test.json", data: {a: 1}.to_json)
106
+ ```
107
+
108
+ ### List Files
109
+
110
+ ```ruby
111
+ detadrive.list(limit: 1, prefix: "avatar")
112
+ ```
113
+
114
+ ### Get File
115
+
116
+ ```ruby
117
+ detadrive.get("image0.jpg")
118
+ ```
119
+
120
+ ### Delete Files
121
+
122
+ ```ruby
123
+ # single delete
124
+ detadrive.delete("image0.jpg")
125
+
126
+ # multi delete
127
+ detadrive.delete(["image1.jpg", "image2.jpg"])
128
+ ```
95
129
 
96
130
  ## Development
97
131
 
data/deta.gemspec CHANGED
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  # For more information and examples about making a new gem, check out our
38
38
  # guide at: https://bundler.io/guides/creating_gem.html
39
39
  spec.add_dependency "faraday", "~> 2.1.0"
40
+ spec.add_dependency "faraday-multipart", "~> 1.0.3"
40
41
  end
data/lib/deta/resource.rb CHANGED
@@ -29,6 +29,10 @@ module Deta
29
29
  handle_response client.connection.delete(url, params, headers)
30
30
  end
31
31
 
32
+ def delete_request_with_body(url, body:, headers: {})
33
+ handle_response client.connection.run_request(:delete, url, body, headers)
34
+ end
35
+
32
36
  def handle_response(response)
33
37
  case response.status
34
38
  when 400
@@ -2,5 +2,48 @@ module Deta
2
2
  class DriveResource < Resource
3
3
  @@api_url = "https://drive.deta.sh/v1"
4
4
 
5
+ def put(name = nil, path: nil, data: nil, content_type: "application/octet-stream")
6
+ payload = nil
7
+ headers = {"Content-Type": content_type}
8
+
9
+ if path
10
+ payload = Faraday::Multipart::FilePart.new(path, content_type, name)
11
+ headers["Content-Length"] = payload.size.to_s
12
+ end
13
+
14
+ if data
15
+ headers["Content-Length"] = data.size.to_s
16
+ payload = data
17
+ end
18
+
19
+ DriveObject.new post_request([@@api_url, client.project_id, resource_name, "files?name=#{name}"].join("/"), body: payload, headers: headers).body
20
+ end
21
+
22
+ def get(name = nil)
23
+ params = {}
24
+ params[:name] = name if name
25
+
26
+ get_request([@@api_url, client.project_id, resource_name, "files", "download"].join("/"), params: params).body
27
+ end
28
+
29
+ def list(limit: nil, prefix: nil, last: nil)
30
+ params = {}
31
+ params[:limit] = limit if limit
32
+ params[:prefix] = prefix if prefix
33
+ params[:last] = last if last
34
+
35
+ DriveObject.new get_request([@@api_url, client.project_id, resource_name, "files"].join("/"), params: params).body
36
+ end
37
+
38
+ def delete(attributes)
39
+ params = {}
40
+ if attributes.is_a?(Array)
41
+ params[:names] = attributes
42
+ else
43
+ params[:names] = [attributes]
44
+ end
45
+
46
+ DriveObject.new delete_request_with_body([@@api_url, client.project_id, resource_name, "files"].join("/"), body: params).body
47
+ end
5
48
  end
6
49
  end
data/lib/deta/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deta
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/deta.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "faraday"
4
+ require "faraday/multipart"
4
5
 
5
6
  require_relative "deta/version"
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dainel Vera
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.3
27
41
  description: 'Ruby bindings for deta.sh. deta APIs can be found here: https://docs.deta.sh/docs/home'
28
42
  email:
29
43
  - arubinofaux@gmail.com