microcms-ruby-sdk 1.0.0 → 1.1.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/.rubocop.yml +4 -0
- data/README.md +110 -20
- data/examples/examples.rb +3 -3
- data/lib/microcms/version.rb +1 -1
- data/lib/microcms.rb +33 -3
- data/microcms.gemspec +5 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7981b7722c57e9c32a2ca0681228addc23c92576c8ade1259874de877bbeb5c1
|
4
|
+
data.tar.gz: c5cf56769dca274a7fffb90e73f6c9814ca8570288e24e9a00fdc0e6eb349b1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5265db69895b973b8f877017b108c59ab854ed3699de6fa13f158d36f2e401f14180495575c8b7efd28ff50b26ba05194d8535e081b6bde52b7124890dec824
|
7
|
+
data.tar.gz: 2ee9017853f3803eb9ef9c2672457b21b18a9a92bacf41ea5d2e7b514f24eaf866e8d5435b2a43f80e3299ef4f4e7e0257c15503f77e004012a1bf027e13891c
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
[microCMS](https://document.microcms.io/manual/api-request) Ruby SDK.
|
4
4
|
|
5
|
+
## Tutorial
|
6
|
+
|
7
|
+
See [official tutorial](https://document.microcms.io/tutorial/ruby/ruby-top).
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -20,38 +24,124 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
27
|
+
### Import
|
28
|
+
|
23
29
|
```rb
|
24
30
|
require 'microcms'
|
31
|
+
```
|
25
32
|
|
26
|
-
|
27
|
-
MicroCMS.api_key = ENV['YOUR_API_KEY']
|
33
|
+
### Create client object
|
28
34
|
|
29
|
-
|
35
|
+
```rb
|
36
|
+
MicroCMS.service_domain = 'YOUR_DOMAIN'
|
37
|
+
MicroCMS.api_key = 'YOUR_API_KEY'
|
38
|
+
```
|
30
39
|
|
31
|
-
|
40
|
+
### Get content list
|
32
41
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
orders: ['updatedAt'],
|
37
|
-
q: 'Hello',
|
38
|
-
fields: %w[id title],
|
39
|
-
filters: 'publishedAt[greater_than]2021-01-01'
|
40
|
-
})
|
42
|
+
```rb
|
43
|
+
puts MicroCMS.list('endpoint')
|
44
|
+
```
|
41
45
|
|
42
|
-
|
46
|
+
### Get content list with parameters
|
43
47
|
|
44
|
-
|
48
|
+
```rb
|
49
|
+
puts MicroCMS.list(
|
50
|
+
'endpoint',
|
51
|
+
{
|
52
|
+
draft_key: "abcd",
|
53
|
+
limit: 100,
|
54
|
+
offset: 1,
|
55
|
+
orders: ['updatedAt'],
|
56
|
+
q: 'Hello',
|
57
|
+
fields: %w[id title],
|
58
|
+
ids: ['foo'],
|
59
|
+
filters: 'publishedAt[greater_than]2021-01-01',
|
60
|
+
depth: 1,
|
61
|
+
},
|
62
|
+
)
|
63
|
+
```
|
45
64
|
|
46
|
-
|
65
|
+
### Get single content
|
47
66
|
|
48
|
-
|
67
|
+
```rb
|
68
|
+
puts MicroCMS.get('endpoint', 'ruby')
|
69
|
+
```
|
70
|
+
|
71
|
+
### Get single content with parameters
|
72
|
+
|
73
|
+
```rb
|
74
|
+
puts MicroCMS.get(
|
75
|
+
'endpoint',
|
76
|
+
'ruby',
|
77
|
+
{
|
78
|
+
draft_key: 'abcdef1234',
|
79
|
+
fields: %w[title publishedAt],
|
80
|
+
depth: 1,
|
81
|
+
},
|
82
|
+
)
|
83
|
+
```
|
49
84
|
|
50
|
-
|
85
|
+
### Get object form content
|
51
86
|
|
52
|
-
|
87
|
+
```rb
|
88
|
+
puts MicroCMS.get('endpoint')
|
89
|
+
```
|
90
|
+
|
91
|
+
### Create content
|
53
92
|
|
54
|
-
|
93
|
+
```rb
|
94
|
+
puts MicroCMS.create('endpoint', { text: 'Hello, microcms-ruby-sdk!' })
|
95
|
+
```
|
96
|
+
|
97
|
+
### Create content with specified ID
|
98
|
+
|
99
|
+
```rb
|
100
|
+
puts MicroCMS.create(
|
101
|
+
'endpoint',
|
102
|
+
{
|
103
|
+
id: 'my-content-id',
|
104
|
+
text: 'Hello, microcms-ruby-sdk!',
|
105
|
+
},
|
106
|
+
)
|
107
|
+
```
|
108
|
+
|
109
|
+
### Create draft content
|
110
|
+
|
111
|
+
```rb
|
112
|
+
puts MicroCMS.create(
|
113
|
+
'endpoint',
|
114
|
+
{
|
115
|
+
id: 'my-content-id',
|
116
|
+
text: 'Hello, microcms-ruby-sdk!',
|
117
|
+
},
|
118
|
+
{ status: 'draft' },
|
119
|
+
)
|
120
|
+
```
|
121
|
+
|
122
|
+
### Update content
|
123
|
+
|
124
|
+
```rb
|
125
|
+
|
126
|
+
puts MicroCMS.update(
|
127
|
+
'endpoint',
|
128
|
+
{
|
129
|
+
id: 'microcms-ruby-sdk',
|
130
|
+
text: 'Hello, microcms-ruby-sdk update method!',
|
131
|
+
},
|
132
|
+
)
|
133
|
+
```
|
134
|
+
|
135
|
+
### Update object form content
|
136
|
+
|
137
|
+
```rb
|
138
|
+
puts MicroCMS.update('endpoint', { text: 'Hello, microcms-ruby-sdk update method!' })
|
139
|
+
```
|
140
|
+
|
141
|
+
### Delete content
|
142
|
+
|
143
|
+
```rb
|
144
|
+
MicroCMS.delete('endpoint', 'microcms-ruby-sdk')
|
55
145
|
```
|
56
146
|
|
57
147
|
## Development
|
@@ -62,4 +152,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
62
152
|
|
63
153
|
## Contributing
|
64
154
|
|
65
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
155
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/microcmsio/microcms-ruby-sdk>.
|
data/examples/examples.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
MicroCMS.service_domain = ENV
|
4
|
-
MicroCMS.api_key = ENV
|
3
|
+
MicroCMS.service_domain = ENV.fetch('YOUR_DOMAIN', nil)
|
4
|
+
MicroCMS.api_key = ENV.fetch('YOUR_API_KEY', nil)
|
5
5
|
|
6
|
-
endpoint = ENV
|
6
|
+
endpoint = ENV.fetch('YOUR_ENDPOINT', nil)
|
7
7
|
|
8
8
|
puts MicroCMS.list(endpoint)
|
9
9
|
|
data/lib/microcms/version.rb
CHANGED
data/lib/microcms.rb
CHANGED
@@ -28,7 +28,12 @@ module MicroCMS
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def list(endpoint, option = {})
|
31
|
-
send_http_request('GET', endpoint, nil, build_query(option))
|
31
|
+
list = send_http_request('GET', endpoint, nil, build_query(option))
|
32
|
+
if list[:totalCount]
|
33
|
+
list[:total_count] = list[:totalCount]
|
34
|
+
list.delete_field(:totalCount)
|
35
|
+
end
|
36
|
+
list
|
32
37
|
end
|
33
38
|
|
34
39
|
def get(endpoint, id = '', option = {})
|
@@ -91,9 +96,9 @@ module MicroCMS
|
|
91
96
|
req = build_request(method, uri, body)
|
92
97
|
res = http.request(req)
|
93
98
|
|
94
|
-
raise
|
99
|
+
raise APIError.new(status_code: res.code.to_i, body: res.body) if res.code.to_i >= 400
|
95
100
|
|
96
|
-
JSON.parse(res.body, object_class: OpenStruct) if res.header['Content-Type'].include?('application/json')
|
101
|
+
JSON.parse(res.body, object_class: OpenStruct) if res.header['Content-Type'].include?('application/json') # rubocop:disable Style/OpenStructUse
|
97
102
|
end
|
98
103
|
|
99
104
|
def get_request_class(method)
|
@@ -137,4 +142,29 @@ module MicroCMS
|
|
137
142
|
http
|
138
143
|
end
|
139
144
|
end
|
145
|
+
|
146
|
+
# APIError
|
147
|
+
class APIError < StandardError
|
148
|
+
attr_accessor :status_code, :body
|
149
|
+
|
150
|
+
def initialize(status_code:, body:)
|
151
|
+
@status_code = status_code
|
152
|
+
@body = parse_body(body)
|
153
|
+
|
154
|
+
message = @body['message'] || 'Unknown error occured.'
|
155
|
+
super(message)
|
156
|
+
end
|
157
|
+
|
158
|
+
def inspect
|
159
|
+
"#<#{self.class.name} @status_code=#{status_code}, @body=#{body.inspect} @message=#{message.inspect}>"
|
160
|
+
end
|
161
|
+
|
162
|
+
private
|
163
|
+
|
164
|
+
def parse_body(body)
|
165
|
+
JSON.parse(body)
|
166
|
+
rescue JSON::ParserError
|
167
|
+
{}
|
168
|
+
end
|
169
|
+
end
|
140
170
|
end
|
data/microcms.gemspec
CHANGED
@@ -12,9 +12,11 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/microcmsio/microcms-ruby-sdk'
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
14
14
|
|
15
|
-
spec.metadata['homepage_uri']
|
16
|
-
spec.metadata['source_code_uri'] =
|
17
|
-
spec.metadata['changelog_uri']
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
+
spec.metadata['changelog_uri'] = spec.homepage
|
18
|
+
|
19
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
18
20
|
|
19
21
|
# Specify which files should be added to the gem when it is released.
|
20
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microcms-ruby-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- microCMS
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: microCMS Ruby SDK
|
14
14
|
email:
|
@@ -38,6 +38,7 @@ metadata:
|
|
38
38
|
homepage_uri: https://github.com/microcmsio/microcms-ruby-sdk
|
39
39
|
source_code_uri: https://github.com/microcmsio/microcms-ruby-sdk
|
40
40
|
changelog_uri: https://github.com/microcmsio/microcms-ruby-sdk
|
41
|
+
rubygems_mfa_required: 'true'
|
41
42
|
post_install_message:
|
42
43
|
rdoc_options: []
|
43
44
|
require_paths:
|