dato 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dato.gemspec +31 -0
- data/lib/dato.rb +6 -0
- data/lib/dato/client.rb +73 -0
- data/lib/dato/json_api_deserializer.rb +37 -0
- data/lib/dato/json_api_serializer.rb +78 -0
- data/lib/dato/repo/base.rb +24 -0
- data/lib/dato/repo/field.rb +40 -0
- data/lib/dato/repo/item.rb +44 -0
- data/lib/dato/repo/item_type.rb +41 -0
- data/lib/dato/repo/menu_item.rb +45 -0
- data/lib/dato/repo/site.rb +22 -0
- data/lib/dato/repo/upload_request.rb +18 -0
- data/lib/dato/repo/user.rb +50 -0
- data/lib/dato/version.rb +3 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9725b89b7642879ecbd50b392c0d303b7b48aeaf
|
4
|
+
data.tar.gz: 129f649b84707acc6540c9124ab1d3171d4448eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12ec3e6baccaa2447785c9b370ad34b19912f1d522cb550c3180502badfc0387dff649a9b48635d12828100bdb1675955c7c9f4d71a3f658d987224d7efb9ab3
|
7
|
+
data.tar.gz: fea36f5531c6b1fd8360ddb32399af705e92a63d6bde925d58323b8c25d4d5cd7b53268ef449e26a876fae87198dd1d74f3fe8e79ee33109daeb21483f0e0577
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at s.verna@cantierecreativo.net. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Stefano Verna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Dato
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dato`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'dato'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install dato
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dato. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
require_relative "./build/download_schema"
|
5
|
+
require_relative "./build/build_client"
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
task :build_resources do
|
12
|
+
schema = DownloadSchema.new.schema
|
13
|
+
BuildClient.new(schema).build
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dato"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dato.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dato/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dato"
|
8
|
+
spec.version = Dato::VERSION
|
9
|
+
spec.authors = ["Stefano Verna"]
|
10
|
+
spec.email = ["s.verna@cantierecreativo.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby client for DatoCMS API}
|
13
|
+
spec.description = %q{Ruby client for DatoCMS API}
|
14
|
+
spec.homepage = "https://github.com/datocms/ruby-datocms-client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|build|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "rubyzip"
|
26
|
+
spec.add_development_dependency "json_schema"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "faraday", [">= 0.9.0"]
|
29
|
+
spec.add_runtime_dependency "faraday_middleware", [">= 0.9.0"]
|
30
|
+
spec.add_runtime_dependency "activesupport"
|
31
|
+
end
|
data/lib/dato.rb
ADDED
data/lib/dato/client.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'json'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
|
+
|
6
|
+
require 'dato/repo/field'
|
7
|
+
require 'dato/repo/item_type'
|
8
|
+
require 'dato/repo/menu_item'
|
9
|
+
require 'dato/repo/site'
|
10
|
+
require 'dato/repo/upload_request'
|
11
|
+
require 'dato/repo/user'
|
12
|
+
require 'dato/repo/item'
|
13
|
+
|
14
|
+
module Dato
|
15
|
+
class Client
|
16
|
+
REPOS = {
|
17
|
+
fields: Repo::Field,
|
18
|
+
item_types: Repo::ItemType,
|
19
|
+
menu_items: Repo::MenuItem,
|
20
|
+
site: Repo::Site,
|
21
|
+
upload_requests: Repo::UploadRequest,
|
22
|
+
users: Repo::User,
|
23
|
+
items: Repo::Item,
|
24
|
+
}
|
25
|
+
|
26
|
+
attr_reader :token, :domain, :schema
|
27
|
+
|
28
|
+
def initialize(token, domain: 'http://site-api.datocms.com')
|
29
|
+
@domain = domain
|
30
|
+
@token = token
|
31
|
+
end
|
32
|
+
|
33
|
+
REPOS.each do |method_name, repo_klass|
|
34
|
+
define_method method_name do
|
35
|
+
instance_variable_set(
|
36
|
+
"@#{method_name}",
|
37
|
+
instance_variable_get("@#{method_name}") ||
|
38
|
+
repo_klass.new(self)
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def request(*args)
|
44
|
+
begin
|
45
|
+
connection.send(*args).body.with_indifferent_access
|
46
|
+
rescue Faraday::ClientError => e
|
47
|
+
body = JSON.parse(e.response[:body])
|
48
|
+
puts JSON.pretty_generate(body)
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def connection
|
56
|
+
options = {
|
57
|
+
url: domain,
|
58
|
+
headers: {
|
59
|
+
'Accept' => "application/json",
|
60
|
+
'Content-Type' => "application/json",
|
61
|
+
'Authorization' => "Bearer #{@token}"
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
@connection ||= Faraday.new(options) do |c|
|
66
|
+
c.request :json
|
67
|
+
c.response :json, content_type: /\bjson$/
|
68
|
+
c.response :raise_error
|
69
|
+
c.adapter :net_http
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Dato
|
2
|
+
class JsonApiDeserializer
|
3
|
+
def deserialize(data)
|
4
|
+
data = data[:data]
|
5
|
+
|
6
|
+
if data.is_a? Array
|
7
|
+
data.map { |resource| deserialize_resource(resource) }
|
8
|
+
else
|
9
|
+
deserialize_resource(data)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def deserialize_resource(data)
|
14
|
+
result = { id: data[:id] }
|
15
|
+
result.merge!(data[:attributes])
|
16
|
+
|
17
|
+
relationships = data.delete(:relationships)
|
18
|
+
|
19
|
+
if relationships
|
20
|
+
relationships.each do |key, data|
|
21
|
+
data = data["data"]
|
22
|
+
value = if data.is_a? Array
|
23
|
+
data.map { |ref| ref["id"] }
|
24
|
+
elsif data.is_a? Hash
|
25
|
+
data[:id]
|
26
|
+
else
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
result[key] = value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
result.with_indifferent_access
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Dato
|
2
|
+
class JsonApiSerializer
|
3
|
+
attr_reader :type, :attributes, :relationships
|
4
|
+
attr_reader :required_attributes, :required_relationships
|
5
|
+
|
6
|
+
def initialize(
|
7
|
+
type:,
|
8
|
+
attributes: [],
|
9
|
+
required_attributes: [],
|
10
|
+
relationships: {},
|
11
|
+
required_relationships: []
|
12
|
+
)
|
13
|
+
@type = type
|
14
|
+
@attributes = attributes
|
15
|
+
@required_attributes = required_attributes
|
16
|
+
@relationships = relationships
|
17
|
+
@required_relationships = required_relationships
|
18
|
+
end
|
19
|
+
|
20
|
+
def serialize(resource, id = nil)
|
21
|
+
resource = resource.with_indifferent_access
|
22
|
+
data = {}
|
23
|
+
|
24
|
+
if id || resource[:id]
|
25
|
+
data[:id] = id || resource[:id]
|
26
|
+
end
|
27
|
+
|
28
|
+
data[:type] = type
|
29
|
+
data[:attributes] = serialized_attributes(resource)
|
30
|
+
|
31
|
+
if relationships.any?
|
32
|
+
data[:relationships] = serialized_relationships(resource)
|
33
|
+
end
|
34
|
+
|
35
|
+
{ data: data }
|
36
|
+
end
|
37
|
+
|
38
|
+
def serialized_attributes(resource)
|
39
|
+
result = {}
|
40
|
+
|
41
|
+
attributes.each do |attribute|
|
42
|
+
if resource.has_key? attribute
|
43
|
+
result[attribute] = resource[attribute]
|
44
|
+
elsif required_attributes.include? attribute
|
45
|
+
throw "Required attribute: #{attribute}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
def serialized_relationships(resource)
|
53
|
+
result = {}
|
54
|
+
|
55
|
+
relationships.each do |relationship, meta|
|
56
|
+
if resource.has_key? relationship
|
57
|
+
value = resource[relationship]
|
58
|
+
|
59
|
+
data = if value
|
60
|
+
if meta[:collection]
|
61
|
+
value.map do |id|
|
62
|
+
{ type: meta[:type], id: id.to_s }
|
63
|
+
end
|
64
|
+
else
|
65
|
+
{ type: meta[:type], id: value.to_s }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
result[relationship] = { data: data }
|
69
|
+
|
70
|
+
elsif required_relationships.include? relationship
|
71
|
+
throw "Required attribute: #{relationship}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
result
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "dato/json_api_serializer"
|
2
|
+
require "dato/json_api_deserializer"
|
3
|
+
|
4
|
+
module Dato
|
5
|
+
module Repo
|
6
|
+
class Base
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
def initialize(client)
|
10
|
+
@client = client
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
%i(post put delete get).each do |method|
|
16
|
+
define_method "#{method}_request" do |*args|
|
17
|
+
JsonApiDeserializer.new.deserialize(
|
18
|
+
client.request(method, *args)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class Field < Base
|
6
|
+
|
7
|
+
def create(item_type_id, resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :field,
|
10
|
+
attributes: %i(api_key appeareance field_type hint label localized position validators),
|
11
|
+
required_attributes: %i(api_key appeareance field_type hint label localized position validators),
|
12
|
+
).serialize(resource_attributes)
|
13
|
+
|
14
|
+
post_request "/item-types/#{item_type_id}/fields", body
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(field_id, resource_attributes)
|
18
|
+
body = JsonApiSerializer.new(
|
19
|
+
type: :field,
|
20
|
+
attributes: %i(api_key appeareance hint label localized position validators),
|
21
|
+
).serialize(resource_attributes, field_id)
|
22
|
+
|
23
|
+
put_request "/fields/#{field_id}", body
|
24
|
+
end
|
25
|
+
|
26
|
+
def all(item_type_id)
|
27
|
+
get_request "/item-types/#{item_type_id}/fields"
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(field_id)
|
31
|
+
get_request "/fields/#{field_id}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy(field_id)
|
35
|
+
delete_request "/fields/#{field_id}"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class Item < Base
|
6
|
+
|
7
|
+
def create(resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :item,
|
10
|
+
attributes: resource_attributes.keys - [:item_type, :id],
|
11
|
+
relationships: {
|
12
|
+
item_type: { collection: false, type: "item_type" }
|
13
|
+
},
|
14
|
+
required_relationships: %i(item_type),
|
15
|
+
).serialize(resource_attributes)
|
16
|
+
|
17
|
+
post_request "/items", body
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(item_id, resource_attributes)
|
21
|
+
body = JsonApiSerializer.new(
|
22
|
+
type: :item,
|
23
|
+
attributes: resource_attributes.keys - [:id],
|
24
|
+
).serialize(resource_attributes, item_id)
|
25
|
+
puts body
|
26
|
+
|
27
|
+
put_request "/items/#{item_id}", body
|
28
|
+
end
|
29
|
+
|
30
|
+
def all(filters)
|
31
|
+
get_request "/items", filters
|
32
|
+
end
|
33
|
+
|
34
|
+
def find(item_id)
|
35
|
+
get_request "/items/#{item_id}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy(item_id)
|
39
|
+
delete_request "/items/#{item_id}"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class ItemType < Base
|
6
|
+
|
7
|
+
def create(resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :item_type,
|
10
|
+
attributes: %i(api_key name singleton sortable),
|
11
|
+
required_attributes: %i(api_key name singleton sortable),
|
12
|
+
).serialize(resource_attributes)
|
13
|
+
|
14
|
+
post_request "/item-types", body
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(item_type_id, resource_attributes)
|
18
|
+
body = JsonApiSerializer.new(
|
19
|
+
type: :item_type,
|
20
|
+
attributes: %i(api_key name singleton sortable),
|
21
|
+
required_attributes: %i(api_key name singleton sortable),
|
22
|
+
).serialize(resource_attributes, item_type_id)
|
23
|
+
|
24
|
+
put_request "/item-types/#{item_type_id}", body
|
25
|
+
end
|
26
|
+
|
27
|
+
def all()
|
28
|
+
get_request "/item-types"
|
29
|
+
end
|
30
|
+
|
31
|
+
def find(item_type_id)
|
32
|
+
get_request "/item-types/#{item_type_id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy(item_type_id)
|
36
|
+
delete_request "/item-types/#{item_type_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class MenuItem < Base
|
6
|
+
|
7
|
+
def create(resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :menu_item,
|
10
|
+
attributes: %i(label position),
|
11
|
+
relationships: {:item_type=>{:collection=>false, :type=>:item_type}, :parent=>{:collection=>false, :type=>:menu_item}},
|
12
|
+
required_attributes: %i(label position),
|
13
|
+
required_relationships: %i(item_type),
|
14
|
+
).serialize(resource_attributes)
|
15
|
+
|
16
|
+
post_request "/menu-items", body
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(menu_item_id, resource_attributes)
|
20
|
+
body = JsonApiSerializer.new(
|
21
|
+
type: :menu_item,
|
22
|
+
attributes: %i(label position),
|
23
|
+
relationships: {:item_type=>{:collection=>false, :type=>:item_type}, :parent=>{:collection=>false, :type=>:menu_item}},
|
24
|
+
required_attributes: %i(label position),
|
25
|
+
required_relationships: %i(item_type),
|
26
|
+
).serialize(resource_attributes, menu_item_id)
|
27
|
+
|
28
|
+
put_request "/menu-items/#{menu_item_id}", body
|
29
|
+
end
|
30
|
+
|
31
|
+
def all()
|
32
|
+
get_request "/menu-items"
|
33
|
+
end
|
34
|
+
|
35
|
+
def find(menu_item_id)
|
36
|
+
get_request "/menu-items/#{menu_item_id}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy(menu_item_id)
|
40
|
+
delete_request "/menu-items/#{menu_item_id}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class Site < Base
|
6
|
+
|
7
|
+
def find()
|
8
|
+
get_request "/site"
|
9
|
+
end
|
10
|
+
|
11
|
+
def update(resource_attributes)
|
12
|
+
body = JsonApiSerializer.new(
|
13
|
+
type: :site,
|
14
|
+
attributes: %i(deploy_adapter deploy_settings favicon global_seo locales name no_index theme_hue timezone),
|
15
|
+
).serialize(resource_attributes)
|
16
|
+
|
17
|
+
put_request "/site", body
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class UploadRequest < Base
|
6
|
+
|
7
|
+
def create(resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :upload_request,
|
10
|
+
attributes: %i(filename),
|
11
|
+
).serialize(resource_attributes)
|
12
|
+
|
13
|
+
post_request "/upload-requests", body
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'dato/repo/base'
|
2
|
+
|
3
|
+
module Dato
|
4
|
+
module Repo
|
5
|
+
class User < Base
|
6
|
+
|
7
|
+
def create(resource_attributes)
|
8
|
+
body = JsonApiSerializer.new(
|
9
|
+
type: :user,
|
10
|
+
attributes: %i(email first_name is_admin last_name),
|
11
|
+
required_attributes: %i(email first_name last_name),
|
12
|
+
).serialize(resource_attributes)
|
13
|
+
|
14
|
+
post_request "/users", body
|
15
|
+
end
|
16
|
+
|
17
|
+
def update(user_id, resource_attributes)
|
18
|
+
body = JsonApiSerializer.new(
|
19
|
+
type: :user,
|
20
|
+
attributes: %i(email first_name is_admin last_name password),
|
21
|
+
).serialize(resource_attributes, user_id)
|
22
|
+
|
23
|
+
put_request "/users/#{user_id}", body
|
24
|
+
end
|
25
|
+
|
26
|
+
def all()
|
27
|
+
get_request "/users"
|
28
|
+
end
|
29
|
+
|
30
|
+
def find(user_id)
|
31
|
+
get_request "/users/#{user_id}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset_password(resource_attributes)
|
35
|
+
body = JsonApiSerializer.new(
|
36
|
+
type: :user,
|
37
|
+
attributes: %i(email),
|
38
|
+
required_attributes: %i(email),
|
39
|
+
).serialize(resource_attributes)
|
40
|
+
|
41
|
+
post_request "/users/reset_password", body
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy(user_id)
|
45
|
+
delete_request "/users/#{user_id}"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/dato/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefano Verna
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubyzip
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: json_schema
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faraday_middleware
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Ruby client for DatoCMS API
|
126
|
+
email:
|
127
|
+
- s.verna@cantierecreativo.net
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- dato.gemspec
|
143
|
+
- lib/dato.rb
|
144
|
+
- lib/dato/client.rb
|
145
|
+
- lib/dato/json_api_deserializer.rb
|
146
|
+
- lib/dato/json_api_serializer.rb
|
147
|
+
- lib/dato/repo/base.rb
|
148
|
+
- lib/dato/repo/field.rb
|
149
|
+
- lib/dato/repo/item.rb
|
150
|
+
- lib/dato/repo/item_type.rb
|
151
|
+
- lib/dato/repo/menu_item.rb
|
152
|
+
- lib/dato/repo/site.rb
|
153
|
+
- lib/dato/repo/upload_request.rb
|
154
|
+
- lib/dato/repo/user.rb
|
155
|
+
- lib/dato/version.rb
|
156
|
+
homepage: https://github.com/datocms/ruby-datocms-client
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.5.1
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Ruby client for DatoCMS API
|
180
|
+
test_files: []
|