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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c4121d2a2289a431f6f938b61f275a3d06daebcf8821e02530cfe79b0c00979
4
- data.tar.gz: 350cd01bf81655b2c46d60255055a47979b388803f5f83efbc1590e2bc908266
3
+ metadata.gz: 99698b9c87c062e3b1ba260579a51d00913b28690bba2eef557c5ab3ffe43a61
4
+ data.tar.gz: 0cc88772721d519604f1ffb3fecd38d456c4fcff8b5de036dbf7f932b537d13f
5
5
  SHA512:
6
- metadata.gz: 95e189e52382c065a9f70123f1fe789c8bdb81e62399e6da73e3f4a4ec30f07f3d8d95239774421aa786edfac4ed4cfd44b5edb093abc37b9a7064f844d666b2
7
- data.tar.gz: 6b2d7c915b3350d01374ae53425b108b156f97c4633575a79e4094553756fe16a17038398096f5801fbe8cd866decb040f571ce5580026d02fd399a053d5ce3a
6
+ metadata.gz: b2f9cf2fd8dece545f5ac80878fa99910b440b9ac78dc318b26f619da6103f9940c477a4431b7129626fd1c157b31a2ee6679fe32092e7be0add78d926a93f52
7
+ data.tar.gz: 7bda92a9734b5415abb245067dc1971b6a2239bdcd66b6710b14e5cb10fada6e4bb73c71e47a0fd4e65500c5bb7406b3e8274c4648c5cdde47ced1904d72cf09
data/README.md CHANGED
@@ -3,23 +3,25 @@
3
3
  ![](https://github.com/morning-brew/sanity-ruby/actions/workflows/ci.yml/badge.svg)
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 that initialize themselves dynamically from API responses when applicable.
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. For example:
8
+ The library also provides other features, like:
9
9
 
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
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
- - [Getting Started](#getting-started)
18
- - [Mutating](#mutating)
19
- - [Querying](#querying)
20
- - [Development](#development)
21
- - [Contributing](#contributing)
22
- - [License](#license)
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
- Sanity::Document.where(groq: "*[_type=='movie']{title,poster{asset->{path,url}}}")
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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).
@@ -47,7 +47,7 @@ module Sanity
47
47
  define_singleton_method(key) { args[key] }
48
48
  end
49
49
 
50
- instance_variable_set("@attributes", attrs)
50
+ instance_variable_set(:@attributes, attrs)
51
51
  end
52
52
  end
53
53
 
@@ -24,6 +24,11 @@ module Sanity
24
24
  @token = ""
25
25
  @use_cdn = false
26
26
  end
27
+
28
+ # @return [String] Api subdomain based on use_cdn flag
29
+ def api_subdomain
30
+ use_cdn ? "apicdn" : "api"
31
+ end
27
32
  end
28
33
 
29
34
  def self.configuration
@@ -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}.api.sanity.io/#{api_version}/#{mutatable_api_endpoint}/#{dataset}"
69
+ "https://#{project_id}.#{api_subdomain}.sanity.io/#{api_version}/#{mutatable_api_endpoint}/#{dataset}"
70
70
  end
71
71
 
72
72
  def body
@@ -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}.api.sanity.io/#{api_version}/#{api_endpoint}/#{dataset}"
59
+ "https://#{project_id}.#{api_subdomain}.sanity.io/#{api_version}/#{api_endpoint}/#{dataset}"
60
60
  end
61
61
 
62
62
  def headers
@@ -49,7 +49,7 @@ module Sanity
49
49
  end
50
50
  end
51
51
 
52
- define_singleton_method("mutatable_api_endpoint") { options.fetch(:api_endpoint, "") }
52
+ define_singleton_method(:mutatable_api_endpoint) { options.fetch(:api_endpoint, "") }
53
53
  end
54
54
  end
55
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sanity
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sanity"
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.1.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: 2021-07-29 00:00:00.000000000 Z
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.0.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: []