webflow-ruby 0.7.0 → 1.0.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: f4c73ca10bddf602a11d63a305e8147cfed9b5472c59d65a153844a3302bce45
4
- data.tar.gz: a72c6ba8f56a4a1e0f2e9541673865569aec4baa8c11cf840f44f0088def8fb8
3
+ metadata.gz: 86911a03c1684d161e4308f07197af038ebdb175369b1c75e1d62eaf9143de4a
4
+ data.tar.gz: 9df52553d7211783fdd1145a90dbbcec7dbaf398435a516eff8ba5c0990cd11f
5
5
  SHA512:
6
- metadata.gz: f2b7e05783dfb5205b4916519764e0a94eb8a4ca859095a423a8a4b07757d721a526a16f1aae92a484110b9377ce92fac169d523c9949159b0f26cb1064e3251
7
- data.tar.gz: 3b3746a6da9a951111aff2cacc3dca8fa90291a378ba765445982b4d20c913c6b540a1a74e119dce9b5ded593e58a4de575f06affb83ad1d35983b8c56486000
6
+ metadata.gz: '081549aad5ce13361cca07e0537263493484d7de30383697ec6d0185754c7f2c4215bcfe1ff00b444aa3e46edc957ad61942cf34265fcf3653b65d675e976c45'
7
+ data.tar.gz: 433cf0bf095bc151b342738bef6bc6373286fda23a6688e3ae72e6b690e569249731dc74af4d9f37b0c6db2c6d8bf7fefb29799808ec3917e416244c06ddae5d
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  *.gem
10
+ *.swo
11
+ *.swp
@@ -1,3 +1,7 @@
1
+ ## 1.0.0
2
+
3
+ * [BREAKING] Raise errors when status > 200, see also https://github.com/penseo/webflow-ruby/pull/7 😍 @sega
4
+
1
5
  ## 0.7.0
2
6
 
3
7
  * [FEATURE] Configuration class to store api token https://github.com/penseo/webflow-ruby/pull/6 😍 @mateuscruz
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webflow-ruby (0.7.0)
4
+ webflow-ruby (1.0.0)
5
5
  http
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -28,9 +28,8 @@ Have a look at the tests, seriously!
28
28
 
29
29
  ## Todo
30
30
 
31
- * Error handling, it's all JSON for now
32
31
  * Resource mapping, it's plain hashes for now
33
- * Proper docs
32
+ * Proper docs (please look at the tests for now)
34
33
 
35
34
  ## Contributing
36
35
 
@@ -119,30 +119,17 @@ module Webflow
119
119
 
120
120
  response = HTTP.auth(bearer).headers(headers).request(method, url, params: params, json: data)
121
121
 
122
- rate_limit = response.headers.select { |key, value| key =~ /X-Ratelimit/ }.to_h
123
- @rate_limit = rate_limit unless rate_limit.empty?
122
+ track_rate_limit(response.headers)
124
123
 
125
- JSON.parse(response.body)
126
- end
124
+ result = JSON.parse(response.body)
125
+ raise Webflow::Error.new(result) if response.code >= 400
127
126
 
128
- def track_rate_limit(headers)
127
+ result
129
128
  end
130
129
 
131
- # https://developers.webflow.com/#errors
132
- def self.error_codes
133
- {
134
- [400, SyntaxError] => 'Request body was incorrectly formatted. Likely invalid JSON being sent up.',
135
- [400, InvalidAPIVersion] => 'Requested an invalid API version',
136
- [400, UnsupportedVersion] => 'Requested an API version that in unsupported by the requested route',
137
- [400, NotImplemented] => 'This feature is not currently implemented',
138
- [400, ValidationError] => 'Validation failure (see err field in the response)',
139
- [400, Conflict] => 'Request has a conflict with existing data.',
140
- [401, Unauthorized] => 'Provided access token is invalid or does not have access to requested resource',
141
- [404, NotFound] => 'Requested resource not found',
142
- [429, RateLimit] => 'The rate limit of the provided access_token has been reached. Please have your application respect the X-RateLimit-Remaining header we include on API responses.',
143
- [500, ServerError] => 'We had a problem with our server. Try again later.',
144
- [400, UnknownError] => 'An error occurred which is not enumerated here, but is not a server error.',
145
- }
130
+ def track_rate_limit(headers)
131
+ rate_limit = headers.select { |key, value| key =~ /X-Ratelimit/ }.to_h
132
+ @rate_limit = rate_limit unless rate_limit.empty?
146
133
  end
147
134
  end
148
135
  end
@@ -0,0 +1,34 @@
1
+ module Webflow
2
+ class Error < StandardError
3
+ # https://developers.webflow.com/#errors
4
+ # 400 SyntaxError Request body was incorrectly formatted. Likely invalid JSON being sent up.
5
+ # 400 InvalidAPIVersion Requested an invalid API version
6
+ # 400 UnsupportedVersion Requested an API version that in unsupported by the requested route
7
+ # 400 NotImplemented This feature is not currently implemented
8
+ # 400 ValidationError Validation failure (see problems field in the response)
9
+ # 400 Conflict Request has a conflict with existing data.
10
+ # 401 Unauthorized Provided access token is invalid or does not have access to requested resource
11
+ # 404 NotFound Requested resource not found
12
+ # 429 RateLimit The rate limit of the provided access_token has been reached. Please have your application respect the X-RateLimit-Remaining header we include on API responses.
13
+ # 500 ServerError We had a problem with our server. Try again later.
14
+ # 400 UnknownError An error occurred which is not enumerated here, but is not a server error.
15
+ #
16
+ # Sample error response
17
+ #
18
+ # {
19
+ # "msg": "Cannot access resource",
20
+ # "code": 401,
21
+ # "name": "Unauthorized",
22
+ # "path": "/sites/invalid_site",
23
+ # "err": "Unauthorized: Cannot access resource"
24
+ # }
25
+
26
+ attr_reader :data
27
+
28
+ def initialize(data)
29
+ @data = data
30
+
31
+ super(data['msg'])
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,4 @@
1
1
  require 'webflow/version'
2
2
  require 'webflow/config'
3
3
  require 'webflow/client'
4
+ require 'webflow/error'
@@ -1,3 +1,3 @@
1
1
  module Webflow
2
- VERSION = "0.7.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webflow-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - phoet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-30 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -131,6 +131,7 @@ files:
131
131
  - lib/webflow.rb
132
132
  - lib/webflow/client.rb
133
133
  - lib/webflow/config.rb
134
+ - lib/webflow/error.rb
134
135
  - lib/webflow/ruby.rb
135
136
  - lib/webflow/version.rb
136
137
  - webflow.gemspec