microcms-ruby-sdk 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce42fc094821080f133ac9faf93e5efbe4cc7fec65ad4930e65e61a4eb3e4add
4
- data.tar.gz: bf9c56b513719887e1ac417db6e903d2b299e583a66f6a39c515e315dc54b714
3
+ metadata.gz: 7981b7722c57e9c32a2ca0681228addc23c92576c8ade1259874de877bbeb5c1
4
+ data.tar.gz: c5cf56769dca274a7fffb90e73f6c9814ca8570288e24e9a00fdc0e6eb349b1e
5
5
  SHA512:
6
- metadata.gz: 18650d072175f4ce851f0d66cb60b6e2a6bd588bb6184bd88b8424783a73f183391e60b2a2ac07f75546efba1c29bf863939edccd5c74d6f35796ebfc1013ebf
7
- data.tar.gz: 6f92d78767727676f97041bbb4bbc934ead25ab774b73322517c7664640cca91c9589c1dd47340da2fca434655977cc9a715d6966a8914145fd9177e84659f9c
6
+ metadata.gz: e5265db69895b973b8f877017b108c59ab854ed3699de6fa13f158d36f2e401f14180495575c8b7efd28ff50b26ba05194d8535e081b6bde52b7124890dec824
7
+ data.tar.gz: 2ee9017853f3803eb9ef9c2672457b21b18a9a92bacf41ea5d2e7b514f24eaf866e8d5435b2a43f80e3299ef4f4e7e0257c15503f77e004012a1bf027e13891c
data/.rubocop.yml CHANGED
@@ -5,3 +5,7 @@ AllCops:
5
5
  Metrics/BlockLength:
6
6
  Exclude:
7
7
  - 'spec/**/*'
8
+
9
+ Style/OpenStructUse:
10
+ Exclude:
11
+ - 'spec/**/*'
data/README.md CHANGED
@@ -49,7 +49,7 @@ puts MicroCMS.list('endpoint')
49
49
  puts MicroCMS.list(
50
50
  'endpoint',
51
51
  {
52
- drarf_key: "abcd",
52
+ draft_key: "abcd",
53
53
  limit: 100,
54
54
  offset: 1,
55
55
  orders: ['updatedAt'],
@@ -152,4 +152,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
152
152
 
153
153
  ## Contributing
154
154
 
155
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/microcms.
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['YOUR_DOMAIN']
4
- MicroCMS.api_key = ENV['YOUR_API_KEY']
3
+ MicroCMS.service_domain = ENV.fetch('YOUR_DOMAIN', nil)
4
+ MicroCMS.api_key = ENV.fetch('YOUR_API_KEY', nil)
5
5
 
6
- endpoint = ENV['YOUR_ENDPOINT']
6
+ endpoint = ENV.fetch('YOUR_ENDPOINT', nil)
7
7
 
8
8
  puts MicroCMS.list(endpoint)
9
9
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MicroCMS
4
- VERSION = '1.0.2'
4
+ VERSION = '1.1.0'
5
5
  end
data/lib/microcms.rb CHANGED
@@ -96,9 +96,9 @@ module MicroCMS
96
96
  req = build_request(method, uri, body)
97
97
  res = http.request(req)
98
98
 
99
- raise "microCMS response error: Status is #{res.code}, Body is #{res.body}" if res.code.to_i >= 400
99
+ raise APIError.new(status_code: res.code.to_i, body: res.body) if res.code.to_i >= 400
100
100
 
101
- 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
102
102
  end
103
103
 
104
104
  def get_request_class(method)
@@ -142,4 +142,29 @@ module MicroCMS
142
142
  http
143
143
  end
144
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
145
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'] = spec.homepage
16
- spec.metadata['source_code_uri'] = 'https://github.com/microcmsio/microcms-ruby-sdk'
17
- spec.metadata['changelog_uri'] = 'https://github.com/microcmsio/microcms-ruby-sdk'
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.0.2
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: 2021-11-08 00:00:00.000000000 Z
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: