sanity-ruby 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +50 -20
- data/lib/sanity/attributable.rb +1 -1
- data/lib/sanity/configuration.rb +5 -0
- data/lib/sanity/http/mutation.rb +2 -2
- data/lib/sanity/http/query.rb +2 -2
- data/lib/sanity/mutatable.rb +1 -1
- data/lib/sanity/version.rb +1 -1
- data/lib/sanity-ruby.rb +3 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99698b9c87c062e3b1ba260579a51d00913b28690bba2eef557c5ab3ffe43a61
|
4
|
+
data.tar.gz: 0cc88772721d519604f1ffb3fecd38d456c4fcff8b5de036dbf7f932b537d13f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2f9cf2fd8dece545f5ac80878fa99910b440b9ac78dc318b26f619da6103f9940c477a4431b7129626fd1c157b31a2ee6679fe32092e7be0add78d926a93f52
|
7
|
+
data.tar.gz: 7bda92a9734b5415abb245067dc1971b6a2239bdcd66b6710b14e5cb10fada6e4bb73c71e47a0fd4e65500c5bb7406b3e8274c4648c5cdde47ced1904d72cf09
|
data/README.md
CHANGED
@@ -3,23 +3,25 @@
|
|
3
3
|

|
4
4
|
<a href="https://codeclimate.com/github/morning-brew/sanity-ruby/maintainability"><img src="https://api.codeclimate.com/v1/badges/1984ee6eb0bce46a2469/maintainability" /></a>
|
5
5
|
|
6
|
-
The Sanity Ruby library provides convenient access to the Sanity API from applications written in Ruby. It includes a pre-defined set of classes for API resources
|
6
|
+
The Sanity Ruby library provides convenient access to the Sanity API from applications written in Ruby. It includes a pre-defined set of classes for API resources.
|
7
7
|
|
8
|
-
The library also provides other features
|
8
|
+
The library also provides other features, like:
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
- Easy configuration for fast setup and use.
|
11
|
+
- A pre-defined class to help make any PORO a "sanity resource"
|
12
|
+
- Extensibility in overriding the wrapper of your API response results
|
13
|
+
- A small DSL around GROQ queries
|
14
14
|
|
15
15
|
## Contents
|
16
16
|
|
17
|
-
- [
|
18
|
-
- [
|
19
|
-
- [
|
20
|
-
- [
|
21
|
-
- [
|
22
|
-
- [
|
17
|
+
- [Sanity](#sanity)
|
18
|
+
- [Contents](#contents)
|
19
|
+
- [Getting Started](#getting-started)
|
20
|
+
- [Mutating](#mutating)
|
21
|
+
- [Querying](#querying)
|
22
|
+
- [Development](#development)
|
23
|
+
- [Contributing](#contributing)
|
24
|
+
- [License](#license)
|
23
25
|
|
24
26
|
## Getting Started
|
25
27
|
|
@@ -29,12 +31,33 @@ Add this line to your application's Gemfile:
|
|
29
31
|
gem 'sanity-ruby'
|
30
32
|
```
|
31
33
|
|
34
|
+
Setup your configuration. If using in Rails, consider setting this in an initializer:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Sanity.configure do |s|
|
38
|
+
s.token = "yoursupersecrettoken"
|
39
|
+
s.api_version = "v2021-03-25"
|
40
|
+
s.project_id = "1234"
|
41
|
+
s.dataset = "development"
|
42
|
+
s.use_cdn = false
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
32
46
|
To create a new document:
|
33
47
|
|
34
48
|
```ruby
|
35
49
|
Sanity::Document.create(params: {_type: "user", first_name: "Carl", last_name: "Sagan"})
|
36
50
|
```
|
37
51
|
|
52
|
+
You can also return the created document ID.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
res = Sanity::Document.create(params: {_type: "user", first_name: "Carl", last_name: "Sagan"}, options: {return_ids: true})
|
56
|
+
|
57
|
+
# JSON.parse(res.body)["results"]
|
58
|
+
# > [{"id"=>"1fc471c6434fdc654ba447", "operation"=>"create"}]
|
59
|
+
```
|
60
|
+
|
38
61
|
To create a new asset:
|
39
62
|
|
40
63
|
```ruby
|
@@ -119,10 +142,6 @@ Sanity::Document.find(_id: "1234-321")
|
|
119
142
|
|
120
143
|
To find documents based on certain fields:
|
121
144
|
|
122
|
-
```ruby
|
123
|
-
Sanity::Document.where(_id: "1234-321", slug: "foobar")
|
124
|
-
```
|
125
|
-
|
126
145
|
[Where](https://www.sanity.io/docs/query-cheat-sheet#3949cadc7524)
|
127
146
|
|
128
147
|
_majority supported_
|
@@ -178,26 +197,37 @@ select: [:_id, :slug, :title, :name]
|
|
178
197
|
```ruby
|
179
198
|
Sanity::Document.where(_type: "user", select: %i[first_name last_name])
|
180
199
|
```
|
181
|
-
|
200
|
+
|
182
201
|
Should you need more advanced querying that isn't handled in this gem's DSL you can pass a raw groq query
|
183
202
|
|
184
203
|
[Query Cheat Sheet](https://www.sanity.io/docs/query-cheat-sheet)
|
185
204
|
|
186
205
|
```ruby
|
187
|
-
|
206
|
+
groq_query = <<-GROQ
|
207
|
+
*[ _type =='movie' && name == $name] {
|
208
|
+
title,
|
209
|
+
poster {
|
210
|
+
asset-> {
|
211
|
+
path,
|
212
|
+
url
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
GROQ
|
217
|
+
|
218
|
+
Sanity::Document.where(groq: groq_query, variables: {name: "Monsters, Inc."})
|
188
219
|
```
|
189
220
|
|
190
221
|
## Development
|
191
222
|
|
192
223
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
193
224
|
|
194
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
225
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
195
226
|
|
196
227
|
## Contributing
|
197
228
|
|
198
229
|
Bug reports and pull requests are welcome on GitHub at https://github.com/morning-brew/sanity-ruby.
|
199
230
|
|
200
|
-
|
201
231
|
## License
|
202
232
|
|
203
233
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/sanity/attributable.rb
CHANGED
data/lib/sanity/configuration.rb
CHANGED
data/lib/sanity/http/mutation.rb
CHANGED
@@ -10,7 +10,7 @@ module Sanity
|
|
10
10
|
def included(base)
|
11
11
|
base.extend(ClassMethods)
|
12
12
|
base.extend(Forwardable)
|
13
|
-
base.delegate(%i[project_id api_version dataset token] => :"Sanity.config")
|
13
|
+
base.delegate(%i[project_id api_version dataset token api_subdomain] => :"Sanity.config")
|
14
14
|
base.delegate(mutatable_api_endpoint: :resource_klass)
|
15
15
|
end
|
16
16
|
end
|
@@ -66,7 +66,7 @@ module Sanity
|
|
66
66
|
private
|
67
67
|
|
68
68
|
def base_url
|
69
|
-
"https://#{project_id}.
|
69
|
+
"https://#{project_id}.#{api_subdomain}.sanity.io/#{api_version}/#{mutatable_api_endpoint}/#{dataset}"
|
70
70
|
end
|
71
71
|
|
72
72
|
def body
|
data/lib/sanity/http/query.rb
CHANGED
@@ -11,7 +11,7 @@ module Sanity
|
|
11
11
|
def included(base)
|
12
12
|
base.extend(ClassMethods)
|
13
13
|
base.extend(Forwardable)
|
14
|
-
base.delegate(%i[project_id api_version dataset token] => :"Sanity.config")
|
14
|
+
base.delegate(%i[project_id api_version dataset token api_subdomain] => :"Sanity.config")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -56,7 +56,7 @@ module Sanity
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def base_url
|
59
|
-
"https://#{project_id}.
|
59
|
+
"https://#{project_id}.#{api_subdomain}.sanity.io/#{api_version}/#{api_endpoint}/#{dataset}"
|
60
60
|
end
|
61
61
|
|
62
62
|
def headers
|
data/lib/sanity/mutatable.rb
CHANGED
data/lib/sanity/version.rb
CHANGED
data/lib/sanity-ruby.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanity-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morning Brew
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email: tech@morningbrew.com
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- bin/console
|
27
27
|
- bin/setup
|
28
28
|
- bin/standardrb
|
29
|
+
- lib/sanity-ruby.rb
|
29
30
|
- lib/sanity.rb
|
30
31
|
- lib/sanity/attributable.rb
|
31
32
|
- lib/sanity/configuration.rb
|
@@ -64,7 +65,7 @@ metadata:
|
|
64
65
|
homepage_uri: https://github.com/morning-brew/sanity-ruby
|
65
66
|
source_code_uri: https://github.com/morning-brew/sanity-ruby
|
66
67
|
changelog_uri: https://github.com/morning-brew/sanity-ruby
|
67
|
-
post_install_message:
|
68
|
+
post_install_message:
|
68
69
|
rdoc_options: []
|
69
70
|
require_paths:
|
70
71
|
- lib
|
@@ -79,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
82
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
83
|
+
rubygems_version: 3.1.4
|
84
|
+
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: Ruby bindings for the Sanity API
|
86
87
|
test_files: []
|