deta 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -3
- data/lib/deta/client.rb +6 -5
- data/lib/deta/objects/drive.rb +4 -0
- data/lib/deta/resource.rb +7 -4
- data/lib/deta/resources/base.rb +36 -11
- data/lib/deta/resources/drive.rb +6 -0
- data/lib/deta/version.rb +1 -1
- data/lib/deta.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a8441ba038bdfc44abe26a8568bd445e8bf943420ba82c8572708b514158ba
|
4
|
+
data.tar.gz: 29e13de22bdb9900cf0510363c313dd0314a75be02fd3d3942130bc923ce0028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f7d384edbfad45567aacaf52bb53a5db5fbba052b51d3699b607bffc3a7eed31048f3846c75dfcab0b2b3b606b59dec57e1ee0bd4ad5636aad9d3be3e34187
|
7
|
+
data.tar.gz: d76a5846a163b896f58c17eec943207a064275e551d7715dfa89b551e5ae6698c31acc694f688d898c7daa3a7ff21120bc9ead937baf7406e88db8727648f04d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,11 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'deta'
|
11
11
|
```
|
12
12
|
|
13
|
+
or grab it from Github
|
14
|
+
```ruby
|
15
|
+
gem 'deta', github: "arubinofaux/deta-ruby"
|
16
|
+
```
|
17
|
+
|
13
18
|
And then execute:
|
14
19
|
|
15
20
|
$ bundle install
|
@@ -44,7 +49,7 @@ put = detabase.put({name: "Mike Jones", age: 31, hometown: "Denver"})
|
|
44
49
|
put.processed.items.first.key
|
45
50
|
|
46
51
|
# multi items
|
47
|
-
puts = detabase.put({name: "Mike Jones", age: 31, hometown: "Denver"}, {name: "Mike Dow", age: 25, hometown: "Miami"})
|
52
|
+
puts = detabase.put([{name: "Mike Jones", age: 31, hometown: "Denver"}, {name: "Mike Dow", age: 25, hometown: "Miami"}])
|
48
53
|
puts.processed
|
49
54
|
```
|
50
55
|
|
@@ -63,7 +68,10 @@ detabase.delete(key)
|
|
63
68
|
### Insert Item
|
64
69
|
|
65
70
|
```ruby
|
66
|
-
|
71
|
+
detabase.insert(name: "Mike Jones", age: 31, hometown: "Denver")
|
72
|
+
|
73
|
+
# specify the key
|
74
|
+
detabase.insert(key: "ab5tsstc9bh8", name: "Mike Jones", age: 31, hometown: "Denver")
|
67
75
|
```
|
68
76
|
|
69
77
|
### Update Item
|
@@ -75,7 +83,10 @@ detabase.update(key, set: {hometown: "Miami"})
|
|
75
83
|
### Query Items
|
76
84
|
|
77
85
|
```ruby
|
78
|
-
|
86
|
+
detabase.fetch(query: {hometown: "Denver"})
|
87
|
+
detabase.fetch(query: [{hometown: "Boulder"}, {"age?lt": 33}])
|
88
|
+
|
89
|
+
detabase.fetch(query: [{hometown: "Boulder"}], limit: 1, last: "8523bdyxlqww")
|
79
90
|
```
|
80
91
|
|
81
92
|
## Drive
|
data/lib/deta/client.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Deta
|
2
2
|
class Client
|
3
|
-
BASE_URL = "https://database.deta.sh/v1/"
|
4
|
-
|
5
3
|
attr_reader :project_id, :project_key, :adapter
|
6
4
|
|
7
5
|
def initialize(project_key:, adapter: Faraday.default_adapter)
|
@@ -10,13 +8,16 @@ module Deta
|
|
10
8
|
@adapter = adapter
|
11
9
|
end
|
12
10
|
|
13
|
-
def base(
|
14
|
-
BaseResource.new(self,
|
11
|
+
def base(base_name = nil)
|
12
|
+
BaseResource.new(self, base_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def drive(drive_name = nil)
|
16
|
+
DriveResource.new(self, drive_name)
|
15
17
|
end
|
16
18
|
|
17
19
|
def connection
|
18
20
|
@connection ||= Faraday.new do |conn|
|
19
|
-
conn.url_prefix = BASE_URL
|
20
21
|
conn.headers['X-API-Key'] = project_key
|
21
22
|
conn.request :json
|
22
23
|
conn.response :json, content_type: "application/json"
|
data/lib/deta/resource.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Deta
|
2
2
|
class Resource
|
3
|
-
attr_reader :client, :
|
3
|
+
attr_reader :client, :resource_name
|
4
4
|
|
5
|
-
def initialize(client,
|
5
|
+
def initialize(client, resource_name)
|
6
6
|
@client = client
|
7
|
-
@
|
7
|
+
@resource_name = resource_name
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
@@ -21,6 +21,10 @@ module Deta
|
|
21
21
|
handle_response client.connection.patch(url, body, headers)
|
22
22
|
end
|
23
23
|
|
24
|
+
def post_request(url, body:, headers: {})
|
25
|
+
handle_response client.connection.post(url, body, headers)
|
26
|
+
end
|
27
|
+
|
24
28
|
def delete_request(url, params: {}, headers: {})
|
25
29
|
handle_response client.connection.delete(url, params, headers)
|
26
30
|
end
|
@@ -40,7 +44,6 @@ module Deta
|
|
40
44
|
when 500
|
41
45
|
raise Error, "We were unable to perform the request due to server-side problems. #{response.body["errors"]}"
|
42
46
|
end
|
43
|
-
|
44
47
|
response
|
45
48
|
end
|
46
49
|
end
|
data/lib/deta/resources/base.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
module Deta
|
2
2
|
class BaseResource < Resource
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
@@api_url = "https://database.deta.sh/v1"
|
4
|
+
|
5
|
+
def put(attributes)
|
6
|
+
items = {}
|
7
|
+
if attributes.is_a?(Array)
|
8
|
+
items["items"] = attributes
|
9
|
+
else
|
10
|
+
items["items"] = [attributes]
|
11
|
+
end
|
12
|
+
|
13
|
+
BaseObject.new put_request([@@api_url, client.project_id, resource_name, "items"].join("/"), body: items).body
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(key = nil)
|
17
|
+
BaseObject.new get_request([@@api_url, client.project_id, resource_name, "items", key].join("/")).body
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(key = nil)
|
21
|
+
BaseObject.new delete_request([@@api_url, client.project_id, resource_name, "items", key].join("/")).body
|
22
|
+
end
|
23
|
+
|
24
|
+
def insert(**attributes)
|
25
|
+
item = {item: attributes}
|
26
|
+
BaseObject.new post_request([@@api_url, client.project_id, resource_name, "items"].join("/"), body: item).body
|
7
27
|
end
|
8
28
|
|
9
29
|
def update(key = nil, set: nil, increment: nil, append: nil, prepend: nil, delete: nil)
|
@@ -13,16 +33,21 @@ module Deta
|
|
13
33
|
request[:append] = append if append
|
14
34
|
request[:prepend] = prepend if prepend
|
15
35
|
request[:delete] = delete if delete
|
16
|
-
|
17
|
-
BaseObject.new patch_request(
|
36
|
+
|
37
|
+
BaseObject.new patch_request([@@api_url, client.project_id, resource_name, "items", key].join("/"), body: request).body
|
18
38
|
end
|
19
39
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
40
|
+
def fetch(query: nil, limit: nil, last: nil)
|
41
|
+
request = {}
|
42
|
+
request[:limit] = limit
|
43
|
+
request[:last] = last
|
44
|
+
if query.is_a?(Array)
|
45
|
+
request[:query] = query
|
46
|
+
else
|
47
|
+
request[:query] = [query]
|
48
|
+
end
|
23
49
|
|
24
|
-
|
25
|
-
BaseObject.new delete_request("#{client.project_id}/#{base_db}/items/#{key}").body
|
50
|
+
BaseObject.new post_request([@@api_url, client.project_id, resource_name, "query"].join("/"), body: request).body
|
26
51
|
end
|
27
52
|
end
|
28
53
|
end
|
data/lib/deta/version.rb
CHANGED
data/lib/deta.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dainel Vera
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -46,8 +46,10 @@ files:
|
|
46
46
|
- lib/deta/error.rb
|
47
47
|
- lib/deta/object.rb
|
48
48
|
- lib/deta/objects/base.rb
|
49
|
+
- lib/deta/objects/drive.rb
|
49
50
|
- lib/deta/resource.rb
|
50
51
|
- lib/deta/resources/base.rb
|
52
|
+
- lib/deta/resources/drive.rb
|
51
53
|
- lib/deta/version.rb
|
52
54
|
homepage: https://github.com/arubinofaux/deta-ruby
|
53
55
|
licenses:
|