dato 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/lib/dato/account/repo/site.rb +1 -1
- data/lib/dato/local/field_type/color.rb +63 -0
- data/lib/dato/site/repo/item.rb +2 -1
- data/lib/dato/site/repo/item_type.rb +6 -4
- data/lib/dato/site/repo/site.rb +1 -1
- data/lib/dato/version.rb +1 -1
- metadata +3 -6
- data/docs/account-api-client.md +0 -53
- data/docs/dato-cli.md +0 -258
- data/docs/site-api-client.md +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e24fe309b4524001a9cd2695edc7eac3ff9d8aa5
|
4
|
+
data.tar.gz: 71adfb4d2b30fd530625ec8ee57ac8057d545fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89d511f0d7508c6efa433faf17a149178041f5f4d08cc8bd3bd7bd19fa839e605cdcd6d1ec86fde3358cb3eb63456b89bd421d16283f3251e420dca98f4b26d5
|
7
|
+
data.tar.gz: 144cf0e4b41872b5b927b2a4152547881c966a8394d582c1b340e11cac779b5dea696a22deb7f7b02f872d47569df5fcb60088d56b4d2fbd39f9608839f37275
|
data/README.md
CHANGED
@@ -2,22 +2,19 @@
|
|
2
2
|
|
3
3
|
[![Coverage Status](https://coveralls.io/repos/github/datocms/ruby-datocms-client/badge.svg?branch=master)](https://coveralls.io/github/datocms/ruby-datocms-client?branch=master) [![Build Status](https://travis-ci.org/datocms/ruby-datocms-client.svg?branch=master)](https://travis-ci.org/datocms/ruby-datocms-client) [![Gem Version](https://badge.fury.io/rb/dato.svg)](https://badge.fury.io/rb/dato)
|
4
4
|
|
5
|
-
|
5
|
+
CLI tool for DatoCMS (https://www.datocms.com).
|
6
6
|
|
7
|
-
|
7
|
+
## How to integrate DatoCMS with Jekyll
|
8
8
|
|
9
|
-
|
10
|
-
2. Let your clients publish new content independently;
|
11
|
-
3. Connect and build your site with any Continuous Deployment service (Netlify, Gitlab, CircleCI, etc.);
|
12
|
-
4. Host the site anywhere you like (Amazon S3, Netlify, Surge.sh, etc.)
|
9
|
+
Please head over the [Jekyll section of our documentation](https://docs.datocms.com/jekyll/overview.html) to learn everything you need to get started.
|
13
10
|
|
14
|
-
##
|
11
|
+
## How to integrate DatoCMS with Middleman
|
15
12
|
|
16
|
-
|
13
|
+
For Middleman we have created a nice Middleman extension called [middleman-dato](https://github.com/datocms/middleman-dato). Please visit the [Middleman section of our documentation](https://docs.datocms.com/middleman/overview.html) to learn everything you need to get started.
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
## API Client
|
16
|
+
|
17
|
+
This gem also exposes an API client, useful ie. to import existing content in your DatoCMS administrative area. Read our [documentation](https://docs.datocms.com/api-client/ruby.html) for detailed info.
|
21
18
|
|
22
19
|
## Development
|
23
20
|
|
@@ -16,7 +16,7 @@ module Dato
|
|
16
16
|
def create(resource_attributes)
|
17
17
|
body = JsonApiSerializer.new(
|
18
18
|
type: :site,
|
19
|
-
attributes: %i(domain internal_subdomain name notes template)
|
19
|
+
attributes: %i(domain internal_subdomain name notes ssg template)
|
20
20
|
).serialize(resource_attributes)
|
21
21
|
|
22
22
|
post_request '/sites', body
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
module Dato
|
4
|
+
module Local
|
5
|
+
module FieldType
|
6
|
+
class Color
|
7
|
+
attr_reader :red, :green, :blue, :alpha
|
8
|
+
|
9
|
+
def self.parse(value, _repo)
|
10
|
+
value && new(
|
11
|
+
value[:red],
|
12
|
+
value[:green],
|
13
|
+
value[:blue],
|
14
|
+
value[:alpha]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(red, green, blue, alpha)
|
19
|
+
@red = red
|
20
|
+
@green = green
|
21
|
+
@blue = blue
|
22
|
+
@alpha = alpha / 255.0
|
23
|
+
end
|
24
|
+
|
25
|
+
def rgb
|
26
|
+
if alpha == 1.0
|
27
|
+
"rgb(#{red}, #{green}, #{blue})"
|
28
|
+
else #
|
29
|
+
"rgba(#{red}, #{green}, #{blue}, #{alpha})"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def hex
|
34
|
+
r = red.to_s(16)
|
35
|
+
g = green.to_s(16)
|
36
|
+
b = blue.to_s(16)
|
37
|
+
a = (alpha * 255).to_i.to_s(16)
|
38
|
+
|
39
|
+
r = "0#{r}" if r.length == 1
|
40
|
+
g = "0#{g}" if g.length == 1
|
41
|
+
b = "0#{b}" if b.length == 1
|
42
|
+
a = "0#{a}" if a.length == 1
|
43
|
+
|
44
|
+
hex = '#' + r + g + b
|
45
|
+
|
46
|
+
hex += a if a != 'ff'
|
47
|
+
|
48
|
+
hex
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_hash(*_args)
|
52
|
+
{
|
53
|
+
red: red,
|
54
|
+
green: green,
|
55
|
+
blue: blue,
|
56
|
+
rgb: rgb,
|
57
|
+
hex: hex
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/dato/site/repo/item.rb
CHANGED
@@ -8,8 +8,9 @@ module Dato
|
|
8
8
|
def create(resource_attributes)
|
9
9
|
body = JsonApiSerializer.new(
|
10
10
|
type: :item_type,
|
11
|
-
attributes: %i(api_key name singleton sortable),
|
12
|
-
|
11
|
+
attributes: %i(api_key name ordering_direction singleton sortable),
|
12
|
+
relationships: { ordering_field: { collection: false, type: :field } },
|
13
|
+
required_attributes: %i(api_key name ordering_direction singleton sortable)
|
13
14
|
).serialize(resource_attributes)
|
14
15
|
|
15
16
|
post_request '/item-types', body
|
@@ -18,8 +19,9 @@ module Dato
|
|
18
19
|
def update(item_type_id, resource_attributes)
|
19
20
|
body = JsonApiSerializer.new(
|
20
21
|
type: :item_type,
|
21
|
-
attributes: %i(api_key name singleton sortable),
|
22
|
-
|
22
|
+
attributes: %i(api_key name ordering_direction singleton sortable),
|
23
|
+
relationships: { ordering_field: { collection: false, type: :field } },
|
24
|
+
required_attributes: %i(api_key name ordering_direction singleton sortable)
|
23
25
|
).serialize(resource_attributes, item_type_id)
|
24
26
|
|
25
27
|
put_request "/item-types/#{item_type_id}", body
|
data/lib/dato/site/repo/site.rb
CHANGED
@@ -12,7 +12,7 @@ module Dato
|
|
12
12
|
def update(resource_attributes)
|
13
13
|
body = JsonApiSerializer.new(
|
14
14
|
type: :site,
|
15
|
-
attributes: %i(deploy_adapter deploy_settings favicon global_seo locales name no_index ssg theme_hue timezone)
|
15
|
+
attributes: %i(deploy_adapter deploy_settings favicon frontend_url global_seo locales name no_index ssg theme_hue timezone)
|
16
16
|
).serialize(resource_attributes)
|
17
17
|
|
18
18
|
put_request '/site', body
|
data/lib/dato/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Verna
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -367,9 +367,6 @@ files:
|
|
367
367
|
- bin/console
|
368
368
|
- bin/setup
|
369
369
|
- dato.gemspec
|
370
|
-
- docs/account-api-client.md
|
371
|
-
- docs/dato-cli.md
|
372
|
-
- docs/site-api-client.md
|
373
370
|
- exe/dato
|
374
371
|
- lib/dato.rb
|
375
372
|
- lib/dato/account/client.rb
|
@@ -398,6 +395,7 @@ files:
|
|
398
395
|
- lib/dato/json_api_serializer.rb
|
399
396
|
- lib/dato/local/entities_repo.rb
|
400
397
|
- lib/dato/local/field_type/boolean.rb
|
398
|
+
- lib/dato/local/field_type/color.rb
|
401
399
|
- lib/dato/local/field_type/date.rb
|
402
400
|
- lib/dato/local/field_type/date_time.rb
|
403
401
|
- lib/dato/local/field_type/file.rb
|
@@ -474,4 +472,3 @@ signing_key:
|
|
474
472
|
specification_version: 4
|
475
473
|
summary: Ruby client for DatoCMS API
|
476
474
|
test_files: []
|
477
|
-
has_rdoc:
|
data/docs/account-api-client.md
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# Create/edit sites within a DatoCMS account
|
2
|
-
|
3
|
-
With this gem, you can easily create, edit and destroy DatoCMS sites, as well as editing your account settings.
|
4
|
-
|
5
|
-
# Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'dato'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install dato
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
require "dato"
|
25
|
-
|
26
|
-
# fetch existing sites
|
27
|
-
sites = client.sites.all
|
28
|
-
|
29
|
-
# create a new site
|
30
|
-
site = client.sites.create(name: 'Foobar')
|
31
|
-
|
32
|
-
# update an existing site
|
33
|
-
client.sites.update(site[:id], site.merge(name: 'Blog'))
|
34
|
-
|
35
|
-
# destroy an existing site
|
36
|
-
client.sites.destroy(new_site[:id])
|
37
|
-
```
|
38
|
-
|
39
|
-
## List of client methods
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
client.account.find
|
43
|
-
client.account.create(resource_attributes)
|
44
|
-
client.account.update(resource_attributes)
|
45
|
-
client.account.reset_password(resource_attributes)
|
46
|
-
|
47
|
-
client.sites.find(site_id)
|
48
|
-
client.sites.all
|
49
|
-
client.sites.create(resource_attributes)
|
50
|
-
client.sites.update(site_id, resource_attributes)
|
51
|
-
client.sites.destroy(site_id)
|
52
|
-
client.sites.duplicate(site_id, resource_attributes)
|
53
|
-
```
|
data/docs/dato-cli.md
DELETED
@@ -1,258 +0,0 @@
|
|
1
|
-
# Integrating DatoCMS with your static website generator
|
2
|
-
|
3
|
-
[DatoCMS](https://www.datocms.com) is working hard to provide the easiest way to enable non-technical editors to update a completely static website — without the intervention of a developer — from the comfort of a user-friendly web interface, just like they're used with Wordpress and such.
|
4
|
-
|
5
|
-
Middleman, Hugo, Jekyll, Hexo, Pelican, Octopress, GatsbyJS... the list of static site generators is [almost endless](https://www.staticgen.com/) and keeps on growing.
|
6
|
-
|
7
|
-
This gem provides an easy way to integrate content coming from a DatoCMS into virtually any static website generator.
|
8
|
-
|
9
|
-
# How it works
|
10
|
-
|
11
|
-
All the websites built with a static website generator are made of:
|
12
|
-
|
13
|
-
* Static files which represent the actual content of the pages (usually written in Markdown + [front matter](https://jekyllrb.com/docs/frontmatter/), YAML, JSON or Toml);
|
14
|
-
* Some HTML templates that use these files to generate the actual static HTML pages you will upload online.
|
15
|
-
|
16
|
-
That means that, up until now, even the most basic change to a static website could only be performed by a tech-savvy user, as too many things had to be known (Git, Markdown syntax, proper editing of YAML/JSON/Toml files).
|
17
|
-
|
18
|
-
DatoCMS works differently:
|
19
|
-
|
20
|
-
1. You create a web administrative interface for your editors that fits exactly the needs of your static website;
|
21
|
-
2. Editors can make changes to the content of the website from that CMS interface you prepared;
|
22
|
-
3. Using this gem, all the data stored in your DatoCMS administrative interface can be transformed into local Markdown/YAML/JSON/Toml files, so that can be "digested" by the static website generator just as they were written by hand.
|
23
|
-
|
24
|
-
The process of translating the data coming from the API into static files can be performed both on your machine during the development process of the website, and in your Continuous Deployment service anytime the editors request a new "build" pressing a "Publish" button on the web interface.
|
25
|
-
|
26
|
-
Now your static website isn't static anymore! Isn't this awesome?! :-)
|
27
|
-
|
28
|
-
## Installing the CLI tool
|
29
|
-
|
30
|
-
Once you have a working Ruby environment, you can use the CLI tool running these commands within your static website directory:
|
31
|
-
|
32
|
-
```
|
33
|
-
gem install bundler
|
34
|
-
bundle init
|
35
|
-
echo 'gem "dato"' >> Gemfile
|
36
|
-
bundle install
|
37
|
-
```
|
38
|
-
|
39
|
-
If everything worked correctly, you should now run `bundle exec dato` and see something like this:
|
40
|
-
|
41
|
-
```
|
42
|
-
$ bundle exec dato
|
43
|
-
DatoCMS commands:
|
44
|
-
dato dump --token=TOKEN # dumps DatoCMS content into local files
|
45
|
-
dato help [COMMAND] # Describe available commands or one specific command
|
46
|
-
```
|
47
|
-
|
48
|
-
Great! Now the easiest way to dump all the remote data into local files is to create a `dato.config.rb` file into your project root directory with the following content:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
# dato.config.rb
|
52
|
-
dato.available_locales.each do |locale|
|
53
|
-
directory "content/#{locale}" do
|
54
|
-
I18n.with_locale(locale) do
|
55
|
-
create_data_file "site.yml", :yaml, dato.site.to_hash
|
56
|
-
dato.item_types.each do |item_type|
|
57
|
-
create_data_file "#{item_type.api_key}.yml", :yaml,
|
58
|
-
dato.items_of_type(item_type).map(&:to_hash)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
```
|
64
|
-
|
65
|
-
And run the following command:
|
66
|
-
|
67
|
-
```
|
68
|
-
$ bundle exec dato dump --token=SITE_READONLY_TOKEN
|
69
|
-
```
|
70
|
-
|
71
|
-
Hurray! A new `content` directory should have been generated with a Yaml file for each item type and the site itself!
|
72
|
-
|
73
|
-
## Hugo step-by-step integration guide
|
74
|
-
|
75
|
-
That's just the beginning: it probably makes more sense if you generate local files following the precise guidelines of the static site generator you're using. You can easily configure the `dato.config.rb` file to achieve that.
|
76
|
-
|
77
|
-
Just to make things more down-to-heart, suppose we're working with a Hugo website with the following structure:
|
78
|
-
|
79
|
-
```
|
80
|
-
.
|
81
|
-
├── config.toml
|
82
|
-
├── content
|
83
|
-
| ├── post
|
84
|
-
| | ├── first-post.md
|
85
|
-
| | └── ...
|
86
|
-
| └── quote
|
87
|
-
| | ├── first-quote.md
|
88
|
-
| | └── ...
|
89
|
-
├── data
|
90
|
-
| └── author
|
91
|
-
| ├── mark.toml
|
92
|
-
| └── ...
|
93
|
-
├── layouts
|
94
|
-
| └── ...
|
95
|
-
└── static
|
96
|
-
└── ...
|
97
|
-
```
|
98
|
-
|
99
|
-
Our job is to generate the Markdown files in the `content` directory from the data contained in our DatoCMS site. The Toml files contained in the in the `data` directory need to be generated as well.
|
100
|
-
|
101
|
-
### Set up the site
|
102
|
-
|
103
|
-
Using the DatoCMS web interface, we first create the following Item types:
|
104
|
-
|
105
|
-
* post
|
106
|
-
- title (string, required)
|
107
|
-
- slug (slug, required)
|
108
|
-
- publication_date (date, required)
|
109
|
-
- body (text, required)
|
110
|
-
|
111
|
-
* author
|
112
|
-
- name (string, required, title)
|
113
|
-
- slug (slug, required)
|
114
|
-
- bio (text, required)
|
115
|
-
|
116
|
-
* quote
|
117
|
-
- content (text, required)
|
118
|
-
- author (link to author, required)
|
119
|
-
|
120
|
-
### Writing the config file
|
121
|
-
|
122
|
-
We then define how content stored in DatoCMS needs to be translated into local files inside the `dato.config.rb` config file. Let's start with posts:
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
directory "content/post" do
|
126
|
-
dato.posts.each do |item|
|
127
|
-
create_post "#{item.slug}.md" do
|
128
|
-
frontmatter :toml, {
|
129
|
-
title: item.title,
|
130
|
-
date: item.publication_date.to_s
|
131
|
-
}
|
132
|
-
|
133
|
-
content item.body
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
```
|
138
|
-
|
139
|
-
The DSL is quite terse! Basically we're declaring that:
|
140
|
-
|
141
|
-
1. we want to take possess of the directory `content/post` and manage it programmatically from now on;
|
142
|
-
2. we then iterate over each post stored in DatoCMS and...
|
143
|
-
3. for each post, we create a local markdown file:
|
144
|
-
- named after the slugified version of the post title;
|
145
|
-
- that contains the post body;
|
146
|
-
- decorated with a Toml front matter with a `title` and `date` keys;
|
147
|
-
|
148
|
-
Now we can run the following command:
|
149
|
-
|
150
|
-
```
|
151
|
-
$ bundle exec dato dump --token=SITE_READONLY_TOKEN
|
152
|
-
```
|
153
|
-
|
154
|
-
And see the `content/post` directory emptied from previous content and filled with new files:
|
155
|
-
|
156
|
-
```
|
157
|
-
.
|
158
|
-
└── content
|
159
|
-
└── post
|
160
|
-
├── lorem-ipsum.md
|
161
|
-
├── dolor-sit-amet.md
|
162
|
-
├── consectetur-adipisci.md
|
163
|
-
└── ...
|
164
|
-
```
|
165
|
-
|
166
|
-
Let's open one of those Markdown files:
|
167
|
-
|
168
|
-
```
|
169
|
-
+++
|
170
|
-
title = "Lorem ipsum"
|
171
|
-
date = "2001-02-03"
|
172
|
-
+++
|
173
|
-
|
174
|
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
175
|
-
|
176
|
-
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
|
177
|
-
```
|
178
|
-
|
179
|
-
Awesome!! We can now continue using Hugo just like we're used to.
|
180
|
-
|
181
|
-
### A more complete config file
|
182
|
-
|
183
|
-
The config file let us declare different kind of "operations":
|
184
|
-
|
185
|
-
| Command | Description |
|
186
|
-
| --- | --- |
|
187
|
-
| `create_post` | Generate Markdown + Frontmatter files |
|
188
|
-
| `create_data_file` | Generate plain Toml/YAML files |
|
189
|
-
| `add_to_data_file` | Add some keys to an existing Toml/YAML file |
|
190
|
-
|
191
|
-
In fact, this is a more complete version of our `dato.config.rb` file:
|
192
|
-
|
193
|
-
```ruby
|
194
|
-
directory "content/post" do
|
195
|
-
dato.posts.each do |item|
|
196
|
-
create_post "#{item.slug}.md" do
|
197
|
-
frontmatter :toml, {
|
198
|
-
title: item.title,
|
199
|
-
date: item.publication_date.to_s
|
200
|
-
}
|
201
|
-
|
202
|
-
content item.body
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
directory "content/quote" do
|
208
|
-
dato.quotes.each_with_index do |item, i|
|
209
|
-
create_post "#{item.id}.md" do
|
210
|
-
frontmatter :toml, {
|
211
|
-
title: "Quote number #{i}",
|
212
|
-
weight: i
|
213
|
-
}
|
214
|
-
|
215
|
-
content item.content
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
directory "data/authors" do
|
221
|
-
dato.authors.each do |item|
|
222
|
-
create_data_file "#{item.slug}.toml", :toml, {
|
223
|
-
name: item.name,
|
224
|
-
bio: item.bio
|
225
|
-
}
|
226
|
-
end
|
227
|
-
end
|
228
|
-
```
|
229
|
-
|
230
|
-
### How to fetch data from DatoCMS
|
231
|
-
|
232
|
-
Using the `dato` method you can access to any item stored in your site grouped by item type. That is, if your site has an Item Type with `post` as API identifier, you can get the complete array of items with `dato.posts` (the pluralized API identifier).
|
233
|
-
|
234
|
-
If a Item Type is marked as "single instance" (ie. `about_page`) you don't need to pluralize and a call to `dato.about_page` directly returns the item (or `nil`, if still hasn't been created within the CMS).
|
235
|
-
|
236
|
-
You can query an item's field value with a method called like the field API identifier.
|
237
|
-
|
238
|
-
Complex field types (ie. `image`, `file`, `video`, `seo`) implement specific methods you can use as well within the config file:
|
239
|
-
|
240
|
-
```
|
241
|
-
article = dato.articles.first
|
242
|
-
|
243
|
-
article.cover_image.url(w: 500, fit: 'crop')
|
244
|
-
article.video.iframe_embed(800, 600)
|
245
|
-
```
|
246
|
-
|
247
|
-
### Examples
|
248
|
-
|
249
|
-
To help you with your first integration, here's a list of sample websites integrated with DatoCMS we built:
|
250
|
-
|
251
|
-
* [Middleman](https://github.com/datocms/middleman-example)
|
252
|
-
* [Jekyll](https://github.com/datocms/jekyll-example)
|
253
|
-
* [Hugo](https://github.com/datocms/hugo-example)
|
254
|
-
|
255
|
-
### Need more help?
|
256
|
-
|
257
|
-
Just ask! Send us an email to [support@datocms.com](mailto:support@datocms.com) and we'll be happy to answer any question!
|
258
|
-
|
data/docs/site-api-client.md
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
# Edit the content of an existing DatoCMS site
|
2
|
-
|
3
|
-
With this gem, you can easily create, edit and destroy any object within a DatoCMS site:
|
4
|
-
|
5
|
-
* Item types
|
6
|
-
* Fields
|
7
|
-
* Items
|
8
|
-
* Menu items
|
9
|
-
* Users
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'dato'
|
17
|
-
```
|
18
|
-
|
19
|
-
And then execute:
|
20
|
-
|
21
|
-
$ bundle
|
22
|
-
|
23
|
-
Or install it yourself as:
|
24
|
-
|
25
|
-
$ gem install dato
|
26
|
-
|
27
|
-
## Usage
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
require "dato"
|
31
|
-
|
32
|
-
# create a DatoCMS client
|
33
|
-
client = Dato::Site::Client.new("YOUR_SITE_API_READWRITE_TOKEN")
|
34
|
-
|
35
|
-
# create a new Article item type
|
36
|
-
article_type = client.item_types.create(
|
37
|
-
name: "Article",
|
38
|
-
singleton: false,
|
39
|
-
sortable: false,
|
40
|
-
api_key: "article"
|
41
|
-
)
|
42
|
-
|
43
|
-
# add a Title field to the Article item type
|
44
|
-
client.fields.create(
|
45
|
-
article_type[:id],
|
46
|
-
api_key: "title",
|
47
|
-
field_type: "string",
|
48
|
-
appeareance: { type: "title" },
|
49
|
-
label: "Title",
|
50
|
-
localized: false,
|
51
|
-
position: 99,
|
52
|
-
hint: "",
|
53
|
-
validators: { required: {} },
|
54
|
-
)
|
55
|
-
|
56
|
-
# add an Image field to the Article item type
|
57
|
-
client.fields.create(
|
58
|
-
article_type[:id],
|
59
|
-
api_key: "image",
|
60
|
-
field_type: "image",
|
61
|
-
appeareance: nil,
|
62
|
-
label: "Image",
|
63
|
-
localized: false,
|
64
|
-
position: 99,
|
65
|
-
hint: "",
|
66
|
-
validators: { required: {} },
|
67
|
-
)
|
68
|
-
|
69
|
-
# create a new Article
|
70
|
-
client.items.create(
|
71
|
-
item_type: article_type[:id],
|
72
|
-
title: "My first article!",
|
73
|
-
image: client.upload_image("http://i.giphy.com/NXOF5rlaSXdAc.gif")
|
74
|
-
)
|
75
|
-
|
76
|
-
# fetch and edit an existing Article
|
77
|
-
article = client.items.find("1234")
|
78
|
-
client.items.update("1234", article.merge(title: "New title"))
|
79
|
-
|
80
|
-
# destroy an existing article
|
81
|
-
client.items.destroy("1234")
|
82
|
-
```
|
83
|
-
|
84
|
-
## List of client methods
|
85
|
-
|
86
|
-
```ruby
|
87
|
-
client.fields.create(item_type_id, resource_attributes)
|
88
|
-
client.fields.update(field_id, resource_attributes)
|
89
|
-
client.fields.all(item_type_id)
|
90
|
-
client.fields.find(field_id)
|
91
|
-
client.fields.destroy(field_id)
|
92
|
-
|
93
|
-
client.items.create(resource_attributes)
|
94
|
-
client.items.update(item_id, resource_attributes)
|
95
|
-
client.items.all(filters = {})
|
96
|
-
client.items.find(item_id)
|
97
|
-
client.items.destroy(item_id)
|
98
|
-
|
99
|
-
client.item_types.create(resource_attributes)
|
100
|
-
client.item_types.update(item_type_id, resource_attributes)
|
101
|
-
client.item_types.all
|
102
|
-
client.item_types.find(item_type_id)
|
103
|
-
client.item_types.destroy(item_type_id)
|
104
|
-
|
105
|
-
client.menu_items.create(resource_attributes)
|
106
|
-
client.menu_items.update(menu_item_id, resource_attributes)
|
107
|
-
client.menu_items.all
|
108
|
-
client.menu_items.find(menu_item_id)
|
109
|
-
client.menu_items.destroy(menu_item_id)
|
110
|
-
|
111
|
-
client.site.find
|
112
|
-
client.site.update(resource_attributes)
|
113
|
-
|
114
|
-
client.upload_image(path_or_url)
|
115
|
-
client.upload_file(path_or_url)
|
116
|
-
|
117
|
-
client.users.create(resource_attributes)
|
118
|
-
client.users.all
|
119
|
-
client.users.find(user_id)
|
120
|
-
client.users.destroy(user_id)
|
121
|
-
```
|