webflow-ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/lib/webflow/client.rb +51 -9
- data/lib/webflow/ruby.rb +0 -2
- data/lib/webflow/version.rb +1 -1
- data/webflow.gemspec +3 -0
- metadata +43 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2df995b45bc57f7941d8fae264b58e29593d69d3
|
4
|
+
data.tar.gz: 25abadb527e7ae8360da648bf5f55ed174f67b9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a72d46c3803b36dc9484a15b2bad0a6b2304d036c74ccc00a90e5b680a7306afe21ca9fc7da4f7adeb2fe293501763ba349c0fd436b572d6f6592fce3a70539b
|
7
|
+
data.tar.gz: 8193ed9ec0fba4bd6ca28f67e9d5860b7ed73ec9c982ef5b155da0929b96fa901fa1d0d4c6382c0b4aa2a3887db4531c56759147b71860b031d4b8e61906ac81
|
data/Gemfile
CHANGED
data/lib/webflow/client.rb
CHANGED
@@ -5,9 +5,19 @@ require 'oj'
|
|
5
5
|
module Webflow
|
6
6
|
class Client
|
7
7
|
HOST = 'https://api.webflow.com'
|
8
|
+
OJ_OPTIONS = {mode: :strict, nilnil: true}
|
8
9
|
|
9
10
|
def initialize(token)
|
10
11
|
@token = token
|
12
|
+
@rate_limit = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def rate_limit
|
16
|
+
@rate_limit
|
17
|
+
end
|
18
|
+
|
19
|
+
def info
|
20
|
+
get("/info")
|
11
21
|
end
|
12
22
|
|
13
23
|
def info
|
@@ -57,19 +67,25 @@ module Webflow
|
|
57
67
|
private
|
58
68
|
|
59
69
|
def get(path, params: nil)
|
60
|
-
|
70
|
+
request(path, method: :get, params: params)
|
61
71
|
end
|
62
72
|
|
63
73
|
def post(path, data)
|
64
|
-
|
74
|
+
request(path, method: :post, body: data)
|
65
75
|
end
|
66
76
|
|
67
77
|
def put(path, data)
|
68
|
-
|
78
|
+
request(path, method: :put, body: data)
|
69
79
|
end
|
70
80
|
|
71
81
|
def delete(path)
|
72
|
-
|
82
|
+
request(path, method: :delete)
|
83
|
+
end
|
84
|
+
|
85
|
+
def request(path, method: :get, params: nil, body: nil)
|
86
|
+
body = Oj.dump(body, OJ_OPTIONS) if body
|
87
|
+
json = http(path, method: method, params: params, headers: request_headers, body: body)
|
88
|
+
Oj.load(json, OJ_OPTIONS)
|
73
89
|
end
|
74
90
|
|
75
91
|
def http(path, method: :get, params: nil, headers: nil, body: nil)
|
@@ -79,17 +95,43 @@ module Webflow
|
|
79
95
|
method: method,
|
80
96
|
params: params,
|
81
97
|
headers: headers,
|
82
|
-
body:
|
98
|
+
body: body,
|
83
99
|
)
|
84
|
-
|
85
|
-
|
100
|
+
response = request.run
|
101
|
+
|
102
|
+
track_rate_limit(response.headers)
|
103
|
+
|
104
|
+
response.body
|
105
|
+
end
|
106
|
+
|
107
|
+
def track_rate_limit(headers)
|
108
|
+
rate_limit = headers.select { |key, value| key =~ /X-Ratelimit/ }
|
109
|
+
@rate_limit = rate_limit unless rate_limit.empty?
|
110
|
+
# byebug
|
86
111
|
end
|
87
112
|
|
88
|
-
def
|
113
|
+
def request_headers
|
89
114
|
{
|
90
115
|
'Authorization' => "Bearer #{@token}",
|
91
116
|
'Content-Type' => 'application/json',
|
92
|
-
'
|
117
|
+
'Accept-Version' => '1.0.0',
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
def error_codes
|
122
|
+
# https://developers.webflow.com/#errors
|
123
|
+
{
|
124
|
+
[400, SyntaxError] => 'Request body was incorrectly formatted. Likely invalid JSON being sent up.',
|
125
|
+
[400, InvalidAPIVersion] => 'Requested an invalid API version',
|
126
|
+
[400, UnsupportedVersion] => 'Requested an API version that in unsupported by the requested route',
|
127
|
+
[400, NotImplemented] => 'This feature is not currently implemented',
|
128
|
+
[400, ValidationError] => 'Validation failure (see problems field in the response)',
|
129
|
+
[400, Conflict] => 'Request has a conflict with existing data.',
|
130
|
+
[401, Unauthorized] => 'Provided access token is invalid or does not have access to requested resource',
|
131
|
+
[404, NotFound] => 'Requested resource not found',
|
132
|
+
[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.',
|
133
|
+
[500, ServerError] => 'We had a problem with our server. Try again later.',
|
134
|
+
[400, UnknownError] => 'An error occurred which is not enumerated here, but is not a server error.',
|
93
135
|
}
|
94
136
|
end
|
95
137
|
end
|
data/lib/webflow/ruby.rb
CHANGED
data/lib/webflow/version.rb
CHANGED
data/webflow.gemspec
CHANGED
@@ -28,4 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency "bundler", "~> 1.13"
|
29
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
30
30
|
spec.add_development_dependency "minitest", "~> 5.0"
|
31
|
+
spec.add_development_dependency "byebug"
|
32
|
+
spec.add_development_dependency "vcr"
|
33
|
+
spec.add_development_dependency "webmock"
|
31
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webflow-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- phoet
|
@@ -94,6 +94,48 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vcr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
description: Webflow API bindings for Ruby
|
98
140
|
email:
|
99
141
|
- phoetmail@googlemail.com
|