typekit-client 0.0.2 → 0.0.3
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/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +9 -5
- data/Guardfile +7 -0
- data/README.md +160 -131
- data/bin/typekit +21 -8
- data/lib/typekit/client.rb +5 -5
- data/lib/typekit/configuration/base.rb +1 -1
- data/lib/typekit/configuration/default.rb +9 -5
- data/lib/typekit/connection/dispatcher.rb +2 -2
- data/lib/typekit/connection/request.rb +5 -2
- data/lib/typekit/connection/response.rb +4 -8
- data/lib/typekit/helper.rb +22 -0
- data/lib/typekit/processing/converter/boolean.rb +11 -0
- data/lib/typekit/processing/converter/datetime.rb +11 -0
- data/lib/typekit/processing/converter/errors.rb +22 -0
- data/lib/typekit/processing/converter/record.rb +15 -0
- data/lib/typekit/processing/converter/records.rb +18 -0
- data/lib/typekit/processing/converter/unknown.rb +14 -0
- data/lib/typekit/processing/converter.rb +32 -0
- data/lib/typekit/processing/parser/json.rb +15 -0
- data/lib/typekit/processing/parser/yaml.rb +15 -0
- data/lib/typekit/processing/parser.rb +14 -0
- data/lib/typekit/processing/translator.rb +16 -0
- data/lib/typekit/processing.rb +9 -0
- data/lib/typekit/record/base.rb +30 -0
- data/lib/typekit/record/family.rb +7 -0
- data/lib/typekit/record/kit.rb +7 -0
- data/lib/typekit/record/library.rb +7 -0
- data/lib/typekit/record/variation.rb +8 -0
- data/lib/typekit/record.rb +35 -0
- data/lib/typekit/routing/{map.rb → mapper.rb} +1 -1
- data/lib/typekit/routing/node/base.rb +1 -0
- data/lib/typekit/routing.rb +1 -1
- data/lib/typekit/version.rb +1 -1
- data/lib/typekit.rb +4 -4
- data/spec/cassettes/delete_kits_xxx_ok.yml +16 -0
- data/spec/typekit/client_spec.rb +11 -3
- data/spec/typekit/configuration_spec.rb +20 -4
- data/spec/typekit/connection/dispatcher_spec.rb +4 -4
- data/spec/typekit/connection/response_spec.rb +18 -0
- data/spec/typekit/helper_spec.rb +34 -0
- data/spec/typekit/processing/converter_spec.rb +54 -0
- data/spec/typekit/processing/parser_spec.rb +23 -0
- data/spec/typekit/record/base_spec.rb +33 -0
- data/spec/typekit/record_spec.rb +48 -0
- data/spec/typekit/routing/mapper_spec.rb +177 -0
- data/spec/typekit/routing/node_spec.rb +31 -10
- data/typekit-client.gemspec +2 -1
- metadata +53 -13
- data/lib/typekit/parser/json.rb +0 -13
- data/lib/typekit/parser/yaml.rb +0 -13
- data/lib/typekit/parser.rb +0 -14
- data/lib/typekit/processor.rb +0 -38
- data/spec/typekit/processor_spec.rb +0 -34
- data/spec/typekit/routing/map_spec.rb +0 -106
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88f79a82bec7c431919822610e0b780faaa7c5aa
|
4
|
+
data.tar.gz: 13dff8c0ffb2cd4df92f76cb89574e11ef8644e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 568ade996d80ad36f2af3d374f4ef71cc0cebf6d56b7c2be718277967def5b82fd65fded286d5d21fde117f7251439809c809a05b25db6441ec092a7fca55b91
|
7
|
+
data.tar.gz: f0644585301a5fe1b8ee6384f6076c603c4265747e0dc390330c201d5d3d0c003a4d7f5c53da2a4c78f01bfb807a4f66b109df6674084890ac1b33bdf3d66a34
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
## Typekit
|
2
|
-
*
|
3
|
-
*
|
4
|
-
|
5
|
-
|
1
|
+
## Typekit Client (master)
|
2
|
+
* Object-restful mapping (families, kits, etc. got proper classes).
|
3
|
+
* Command history and tab completion in the CLI.
|
4
|
+
|
5
|
+
## Typekit Client 0.0.2 (May 28, 2014)
|
6
|
+
* New name for the gem (still `require 'typekit'`).
|
7
|
+
* Basic DSL for describing RESTful resources.
|
8
|
+
* Client-side verification of user requests.
|
9
|
+
* Refactoring, preparing for new features.
|
6
10
|
|
7
11
|
## Typekit 0.0.1 (May 16, 2014)
|
data/Guardfile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
guard :rspec do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
4
|
+
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{ m[1] }_spec.rb" }
|
6
|
+
watch(%r{^lib/(.*\.rb)$}) { |m| "spec/#{ File.dirname(m[1]) }" }
|
7
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Typekit Client
|
1
|
+
# Typekit Client [](http://badge.fury.io/rb/typekit-client) [](https://travis-ci.org/IvanUkhov/typekit-client)
|
2
2
|
A Ruby library for accessing the [Typekit API](https://typekit.com/docs/api).
|
3
3
|
|
4
4
|
## Installation
|
@@ -55,41 +55,56 @@ The arguments are as follows:
|
|
55
55
|
|
56
56
|
`perform` has an alias for each of the actions: `index(*path, parameters = {})`,
|
57
57
|
`show(*path, parameters = {})`, `create(*path, parameters = {})`, and so on.
|
58
|
-
|
59
|
-
what the Typekit API sends back to `client`. The only exception is when
|
60
|
-
the API returns an error, in which case an appropriate exception is being
|
61
|
-
raised.
|
62
|
-
|
63
|
-
Before sending the actual request to the Typekit API, the library checks
|
58
|
+
Before sending the actual request to the Typekit API, `perform` checks
|
64
59
|
whether the resource given by `*path` makes sense and, if it does, whether
|
65
60
|
`action` can be performed on that resource. So, if you receive an exception,
|
66
|
-
check
|
61
|
+
check the [API reference](https://typekit.com/docs/api/).
|
67
62
|
|
68
63
|
Now, let us have a look at some typical use cases. For clarity, the code
|
69
64
|
below makes use of the following auxiliary function:
|
70
65
|
```ruby
|
71
66
|
def p(data)
|
72
67
|
puts JSON.pretty_generate(data)
|
68
|
+
rescue JSON::GeneratorError
|
69
|
+
puts data.inspect
|
73
70
|
end
|
74
71
|
```
|
75
72
|
|
76
73
|
### Show all kits
|
77
74
|
Code:
|
78
75
|
```ruby
|
79
|
-
p client.index(:kits)
|
76
|
+
p kits = client.index(:kits)
|
77
|
+
p kits.map(&:class)
|
78
|
+
p kits.first.attributes
|
79
|
+
p kits.first.link
|
80
80
|
```
|
81
81
|
|
82
82
|
Output:
|
83
83
|
```json
|
84
|
+
[
|
85
|
+
{
|
86
|
+
"id": "bas4cfe",
|
87
|
+
"link": "/api/v1/json/kits/bas4cfe"
|
88
|
+
},
|
89
|
+
{
|
90
|
+
"id": "sfh6bkj",
|
91
|
+
"link": "/api/v1/json/kits/sfh6bkj"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"id": "kof8zcn",
|
95
|
+
"link": "/api/v1/json/kits/kof8zcn"
|
96
|
+
}
|
97
|
+
]
|
98
|
+
[
|
99
|
+
"Typekit::Record::Kit",
|
100
|
+
"Typekit::Record::Kit",
|
101
|
+
"Typekit::Record::Kit"
|
102
|
+
]
|
84
103
|
{
|
85
|
-
"
|
86
|
-
|
87
|
-
"id": "bas4cfe",
|
88
|
-
"link": "/api/v1/json/kits/bas4cfe"
|
89
|
-
},
|
90
|
-
...
|
91
|
-
]
|
104
|
+
"id": "bas4cfe",
|
105
|
+
"link": "/api/v1/json/kits/bas4cfe"
|
92
106
|
}
|
107
|
+
"/api/v1/json/kits/bas4cfe"
|
93
108
|
```
|
94
109
|
|
95
110
|
### Show the description of a variant of a font family
|
@@ -101,19 +116,17 @@ p client.show(:families, 'vcsm', 'i9')
|
|
101
116
|
Output:
|
102
117
|
```json
|
103
118
|
{
|
104
|
-
"
|
105
|
-
|
106
|
-
|
107
|
-
"
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
...
|
116
|
-
}
|
119
|
+
"id": "vcsm:i9",
|
120
|
+
"name": "Proxima Nova Black Italic",
|
121
|
+
"family": {
|
122
|
+
"id": "vcsm",
|
123
|
+
"link": "/api/v1/json/families/vcsm",
|
124
|
+
"name": "Proxima Nova"
|
125
|
+
},
|
126
|
+
"font_style": "italic",
|
127
|
+
"font_variant": "normal",
|
128
|
+
"font_weight": "900",
|
129
|
+
...
|
117
130
|
}
|
118
131
|
```
|
119
132
|
|
@@ -126,30 +139,28 @@ p client.show(:libraries, 'trial', page: 10, per_page: 5)
|
|
126
139
|
Output:
|
127
140
|
```json
|
128
141
|
{
|
129
|
-
"
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
"
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
"per_page": 5
|
152
|
-
}
|
142
|
+
"id": "trial",
|
143
|
+
"link": "/api/v1/json/libraries/trial",
|
144
|
+
"name": "Trial Library",
|
145
|
+
"families": [
|
146
|
+
{
|
147
|
+
"id": "qnhl",
|
148
|
+
"link": "/api/v1/json/families/qnhl",
|
149
|
+
"name": "Caliban Std"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"id": "vybr",
|
153
|
+
"link": "/api/v1/json/families/vybr",
|
154
|
+
"name": "Calluna"
|
155
|
+
},
|
156
|
+
...
|
157
|
+
],
|
158
|
+
"pagination": {
|
159
|
+
"count": 261,
|
160
|
+
"on": "families",
|
161
|
+
"page": 10,
|
162
|
+
"page_count": 53,
|
163
|
+
"per_page": 5
|
153
164
|
}
|
154
165
|
}
|
155
166
|
```
|
@@ -157,115 +168,137 @@ Output:
|
|
157
168
|
### Create a new kit
|
158
169
|
Code:
|
159
170
|
```ruby
|
160
|
-
p
|
161
|
-
kit_id = result['kit']['id']
|
171
|
+
p kit = client.create(:kits, name: 'Megakit', domains: 'localhost')
|
162
172
|
```
|
163
173
|
|
164
174
|
Output:
|
165
175
|
```json
|
166
176
|
{
|
167
|
-
"
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
"
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
]
|
178
|
-
}
|
177
|
+
"id": "izw0qiq",
|
178
|
+
"name": "Megakit",
|
179
|
+
"analytics": false,
|
180
|
+
"badge": true,
|
181
|
+
"domains": [
|
182
|
+
"localhost"
|
183
|
+
],
|
184
|
+
"families": [
|
185
|
+
|
186
|
+
]
|
179
187
|
}
|
180
188
|
```
|
181
189
|
|
182
190
|
### Disable the badge of a kit
|
183
191
|
Code:
|
184
192
|
```ruby
|
185
|
-
p client.update(:kits,
|
193
|
+
p client.update(:kits, kit.id, badge: false)
|
186
194
|
```
|
187
195
|
|
188
196
|
Output:
|
189
197
|
```json
|
190
198
|
{
|
191
|
-
"
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
"
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
]
|
202
|
-
}
|
199
|
+
"id": "izw0qiq",
|
200
|
+
"name": "Megakit",
|
201
|
+
"analytics": false,
|
202
|
+
"badge": false,
|
203
|
+
"domains": [
|
204
|
+
"localhost"
|
205
|
+
],
|
206
|
+
"families": [
|
207
|
+
|
208
|
+
]
|
203
209
|
}
|
204
210
|
```
|
205
211
|
|
206
212
|
### Look up the id of a font family by its slug
|
207
213
|
Code:
|
208
214
|
```ruby
|
209
|
-
p
|
210
|
-
family_id = result['family']['id']
|
215
|
+
p family = client.show(:families, 'proxima-nova')
|
211
216
|
```
|
212
217
|
|
213
218
|
Output:
|
214
219
|
```json
|
215
220
|
{
|
216
|
-
"
|
217
|
-
|
218
|
-
"link": "/api/v1/json/families/vcsm"
|
219
|
-
}
|
221
|
+
"id": "vcsm",
|
222
|
+
"link": "/api/v1/json/families/vcsm"
|
220
223
|
}
|
221
224
|
```
|
222
225
|
|
223
226
|
### Add a font family into a kit
|
224
227
|
Code:
|
225
228
|
```ruby
|
226
|
-
p client.update(:kits,
|
229
|
+
p client.update(:kits, kit.id, families: { "0" => { id: family.id } })
|
227
230
|
```
|
228
231
|
|
229
232
|
Output:
|
230
233
|
```json
|
231
234
|
{
|
232
|
-
"
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
"
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
"
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
]
|
252
|
-
}
|
235
|
+
"id": "nys8sny",
|
236
|
+
"name": "Megakit",
|
237
|
+
"analytics": false,
|
238
|
+
"badge": false,
|
239
|
+
"domains": [
|
240
|
+
"localhost"
|
241
|
+
],
|
242
|
+
"families": [
|
243
|
+
{
|
244
|
+
"id": "vcsm",
|
245
|
+
"name": "Proxima Nova",
|
246
|
+
"slug": "proxima-nova",
|
247
|
+
"css_names": [
|
248
|
+
"proxima-nova-1",
|
249
|
+
"proxima-nova-2"
|
250
|
+
],
|
251
|
+
...
|
252
|
+
}
|
253
|
+
]
|
253
254
|
}
|
254
255
|
```
|
255
256
|
|
256
|
-
###
|
257
|
-
|
257
|
+
### Publish a kit
|
258
|
+
Code:
|
258
259
|
```ruby
|
259
|
-
p client.
|
260
|
+
p client.update(:kits, kit.id, :publish)
|
260
261
|
```
|
261
262
|
|
262
263
|
Output:
|
263
|
-
```
|
264
|
+
```
|
265
|
+
#<DateTime: 2014-05-31T06:45:29+00:00 ((2456809j,24329s,0n),+0s,2299161j)>
|
266
|
+
```
|
267
|
+
|
268
|
+
### Show the description of a published kit
|
269
|
+
Code:
|
270
|
+
```ruby
|
271
|
+
p client.show(:kits, kit.id, :published)
|
272
|
+
```
|
273
|
+
|
274
|
+
Output:
|
275
|
+
```
|
264
276
|
{
|
265
|
-
"
|
277
|
+
"id": "vzt4lrg",
|
278
|
+
"name": "Megakit",
|
279
|
+
"analytics": false,
|
280
|
+
"badge": false,
|
281
|
+
"domains": [
|
282
|
+
"localhost"
|
283
|
+
],
|
284
|
+
"families": [
|
285
|
+
...
|
286
|
+
],
|
287
|
+
"published": "2014-05-31T06:45:29Z"
|
266
288
|
}
|
267
289
|
```
|
268
290
|
|
291
|
+
### Delete a kit
|
292
|
+
Command:
|
293
|
+
```ruby
|
294
|
+
p client.delete(:kits, kit.id)
|
295
|
+
```
|
296
|
+
|
297
|
+
Output:
|
298
|
+
```
|
299
|
+
true
|
300
|
+
```
|
301
|
+
|
269
302
|
## Command-line Interface (CLI)
|
270
303
|
There is a simple CLI provided in order to demonstrate the usage of the
|
271
304
|
library and to give the ability to perform basic operations without writing
|
@@ -294,15 +327,13 @@ The tool has two modes: normal and interactive. If `command` is provided,
|
|
294
327
|
the tool executes only that particular command and terminates:
|
295
328
|
```
|
296
329
|
$ typekit -t $tk_token index kits
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
]
|
305
|
-
}
|
330
|
+
[
|
331
|
+
{
|
332
|
+
"id": "bas4cfe",
|
333
|
+
"link": "/api/v1/json/kits/bas4cfe"
|
334
|
+
},
|
335
|
+
...
|
336
|
+
]
|
306
337
|
$
|
307
338
|
```
|
308
339
|
|
@@ -327,15 +358,13 @@ Examples:
|
|
327
358
|
update kits bas4cfe { "name": "Ultrakit" }
|
328
359
|
delete kits bas4cfe
|
329
360
|
> index kits
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
]
|
338
|
-
}
|
361
|
+
[
|
362
|
+
{
|
363
|
+
"id": "bas4cfe",
|
364
|
+
"link": "/api/v1/json/kits/bas4cfe"
|
365
|
+
},
|
366
|
+
...
|
367
|
+
]
|
339
368
|
> exit
|
340
369
|
Bye.
|
341
370
|
$
|
data/bin/typekit
CHANGED
@@ -3,10 +3,14 @@
|
|
3
3
|
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
4
4
|
|
5
5
|
require 'typekit'
|
6
|
+
require 'readline'
|
6
7
|
require 'optparse'
|
7
8
|
require 'json'
|
8
9
|
|
9
10
|
class Controller
|
11
|
+
ACTIONS = %w{index show create update delete}
|
12
|
+
KEYWORDS = %w{families kits libraries published publish}
|
13
|
+
|
10
14
|
def initialize(**options)
|
11
15
|
@client = Typekit::Client.new(**options)
|
12
16
|
end
|
@@ -22,7 +26,7 @@ class Controller
|
|
22
26
|
puts <<-HELP
|
23
27
|
Usage: <action> <resource> [parameters]
|
24
28
|
|
25
|
-
<action> show, create, update, or delete
|
29
|
+
<action> index, show, create, update, or delete
|
26
30
|
<resource> a list separated by whitespaces
|
27
31
|
[parameters] a JSON-encoded hash (optional)
|
28
32
|
|
@@ -41,6 +45,8 @@ HELP
|
|
41
45
|
|
42
46
|
def print(output)
|
43
47
|
puts JSON.pretty_generate(output)
|
48
|
+
rescue JSON::GeneratorError
|
49
|
+
puts output.to_s # neither hash nor array
|
44
50
|
end
|
45
51
|
|
46
52
|
def parse(command)
|
@@ -50,12 +56,8 @@ HELP
|
|
50
56
|
action, path = chunks[0], chunks[1..-1]
|
51
57
|
|
52
58
|
raise 'Missing action name' if action.nil?
|
53
|
-
raise 'Invalid action name' unless action
|
54
|
-
|
59
|
+
raise 'Invalid action name' unless ACTIONS.include?(action)
|
55
60
|
raise 'Missing resource name' if path.empty?
|
56
|
-
unless path.all?{ |chunk| chunk =~ /^[-\w\d]+$/ }
|
57
|
-
raise 'Invalid resource name'
|
58
|
-
end
|
59
61
|
|
60
62
|
[ action, path, parameters ]
|
61
63
|
end
|
@@ -123,11 +125,22 @@ end
|
|
123
125
|
|
124
126
|
puts %{Type 'help' for help and 'exit' to exit.}
|
125
127
|
|
128
|
+
COMMANDS = Controller::ACTIONS + Controller::KEYWORDS + %w{help exit}
|
129
|
+
Readline.completion_proc = proc do |input|
|
130
|
+
COMMANDS.grep(/^#{ Regexp.escape(input) }/)
|
131
|
+
end
|
132
|
+
|
126
133
|
loop do
|
127
134
|
begin
|
128
|
-
|
129
|
-
command
|
135
|
+
command = Readline.readline('> ', true)
|
136
|
+
if command.nil? # ^D
|
137
|
+
puts
|
138
|
+
next
|
139
|
+
end
|
140
|
+
|
141
|
+
command.strip!
|
130
142
|
next if command.empty?
|
143
|
+
|
131
144
|
case command
|
132
145
|
when 'exit'
|
133
146
|
break
|
data/lib/typekit/client.rb
CHANGED
@@ -4,16 +4,16 @@ module Typekit
|
|
4
4
|
class Client
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def_delegators :@config, :
|
8
|
-
private def_delegator :dispatcher, :
|
9
|
-
private def_delegator :
|
7
|
+
def_delegators :@config, :mapper, :dispatcher, :translator
|
8
|
+
private def_delegator :dispatcher, :process, :dispatch
|
9
|
+
private def_delegator :translator, :process, :translate
|
10
10
|
|
11
11
|
def initialize(config: :default, **options)
|
12
12
|
@config = Configuration.build(config, **options)
|
13
13
|
end
|
14
14
|
|
15
15
|
def perform(*arguments)
|
16
|
-
|
16
|
+
translate(dispatch(trace(*arguments)))
|
17
17
|
end
|
18
18
|
|
19
19
|
Typekit.actions.each do |action|
|
@@ -32,7 +32,7 @@ module Typekit
|
|
32
32
|
def trace(*arguments)
|
33
33
|
action, path, parameters = prepare(*arguments)
|
34
34
|
request = Connection::Request.new(action: action, parameters: parameters)
|
35
|
-
|
35
|
+
mapper.trace(request, path)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -9,7 +9,7 @@ module Typekit
|
|
9
9
|
@token = token
|
10
10
|
end
|
11
11
|
|
12
|
-
[ :
|
12
|
+
[ :mapper, :dispatcher, :translator ].each do |component|
|
13
13
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
14
14
|
def #{ component }
|
15
15
|
@#{ component } ||= build_#{ component }
|
@@ -3,9 +3,9 @@ module Typekit
|
|
3
3
|
class Default < Base
|
4
4
|
private
|
5
5
|
|
6
|
-
def
|
7
|
-
context =
|
8
|
-
Routing::
|
6
|
+
def build_mapper
|
7
|
+
context = build_context
|
8
|
+
Routing::Mapper.new do
|
9
9
|
scope context do
|
10
10
|
resources :families, only: :show do
|
11
11
|
show ':variant', on: :member
|
@@ -26,8 +26,12 @@ module Typekit
|
|
26
26
|
Connection::Dispatcher.new(adaptor: :standard, token: token)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def build_translator
|
30
|
+
Processing::Translator.new(format: format)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_context
|
34
|
+
[ Typekit.address, "v#{ version }", format ]
|
31
35
|
end
|
32
36
|
end
|
33
37
|
end
|
@@ -6,11 +6,11 @@ module Typekit
|
|
6
6
|
@adaptor = Adaptor.build(adaptor)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def process(request)
|
10
10
|
method = Helper.translate_action(request.action)
|
11
11
|
code, _, body = @adaptor.process(method, request.address,
|
12
12
|
request.parameters, 'X-Typekit-Token' => @token)
|
13
|
-
Response.new(code: code.to_i,
|
13
|
+
Response.new(code: code.to_i, body: body)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -5,7 +5,7 @@ module Typekit
|
|
5
5
|
class Request
|
6
6
|
extend Forwardable
|
7
7
|
|
8
|
-
attr_reader :action, :parameters, :path
|
8
|
+
attr_reader :action, :parameters, :path, :node
|
9
9
|
def_delegators :@path, :<<
|
10
10
|
|
11
11
|
def initialize(action:, parameters: {})
|
@@ -15,9 +15,12 @@ module Typekit
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def address
|
18
|
-
# TODO: cache?
|
19
18
|
@path.map(&:to_s).join('/')
|
20
19
|
end
|
20
|
+
|
21
|
+
def sign(node)
|
22
|
+
@node = node
|
23
|
+
end
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module Typekit
|
2
2
|
module Connection
|
3
3
|
class Response
|
4
|
-
attr_reader :code, :
|
4
|
+
attr_reader :code, :body
|
5
5
|
|
6
|
-
def initialize(code:,
|
6
|
+
def initialize(code:, body:)
|
7
7
|
@code = code
|
8
|
-
@
|
8
|
+
@body = body
|
9
9
|
end
|
10
10
|
|
11
11
|
def success?
|
12
|
-
@code
|
13
|
-
end
|
14
|
-
|
15
|
-
def redirect?
|
16
|
-
@code == 302
|
12
|
+
[ 200, 302 ].include?(@code)
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|