typekit-client 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +350 -0
- data/Rakefile +7 -0
- data/bin/typekit +146 -0
- data/lib/typekit.rb +13 -0
- data/lib/typekit/client.rb +38 -0
- data/lib/typekit/configuration.rb +16 -0
- data/lib/typekit/configuration/base.rb +21 -0
- data/lib/typekit/configuration/default.rb +34 -0
- data/lib/typekit/connection.rb +10 -0
- data/lib/typekit/connection/adaptor.rb +13 -0
- data/lib/typekit/connection/adaptor/standard.rb +32 -0
- data/lib/typekit/connection/dispatcher.rb +17 -0
- data/lib/typekit/connection/request.rb +23 -0
- data/lib/typekit/connection/response.rb +20 -0
- data/lib/typekit/core.rb +16 -0
- data/lib/typekit/helper.rb +43 -0
- data/lib/typekit/parser.rb +14 -0
- data/lib/typekit/parser/json.rb +13 -0
- data/lib/typekit/parser/yaml.rb +13 -0
- data/lib/typekit/processor.rb +38 -0
- data/lib/typekit/routing.rb +9 -0
- data/lib/typekit/routing/map.rb +43 -0
- data/lib/typekit/routing/node.rb +5 -0
- data/lib/typekit/routing/node/base.rb +45 -0
- data/lib/typekit/routing/node/collection.rb +34 -0
- data/lib/typekit/routing/node/operation.rb +32 -0
- data/lib/typekit/routing/node/root.rb +8 -0
- data/lib/typekit/routing/node/scope.rb +19 -0
- data/lib/typekit/routing/proxy.rb +17 -0
- data/lib/typekit/version.rb +3 -0
- data/spec/cassettes/index_kits_ok.yml +16 -0
- data/spec/cassettes/index_kits_unauthorized.yml +16 -0
- data/spec/cassettes/show_families_calluna_found.yml +16 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/rest_helper.rb +22 -0
- data/spec/typekit/client_spec.rb +36 -0
- data/spec/typekit/configuration_spec.rb +34 -0
- data/spec/typekit/connection/adaptor_spec.rb +24 -0
- data/spec/typekit/connection/dispatcher_spec.rb +36 -0
- data/spec/typekit/connection/request_spec.rb +13 -0
- data/spec/typekit/helper_spec.rb +93 -0
- data/spec/typekit/processor_spec.rb +34 -0
- data/spec/typekit/routing/map_spec.rb +106 -0
- data/spec/typekit/routing/node_spec.rb +40 -0
- data/typekit-client.gemspec +33 -0
- metadata +208 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'typekit'
|
3
|
+
|
4
|
+
describe Typekit::Processor do
|
5
|
+
def create(format)
|
6
|
+
Typekit::Processor.new(format: format)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'supports JSON' do
|
10
|
+
parser = create(:json)
|
11
|
+
response = double(success?: true, content: '{ "a": 1 }')
|
12
|
+
result = parser.process(response)
|
13
|
+
expect(result).to eq("a" => 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'supports YAML' do
|
17
|
+
parser = create(:yaml)
|
18
|
+
response = double(success?: true, content: "---\na: 1")
|
19
|
+
result = parser.process(response)
|
20
|
+
expect(result).to eq("a" => 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not support XML' do
|
24
|
+
expect { create(:xml) }.to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises an appropriate exception when a request fails' do
|
28
|
+
parser = create(:json)
|
29
|
+
response = double(success?: false, redirect?: false, code: 401,
|
30
|
+
content: '{ "errors": [ "Not authorized" ] }')
|
31
|
+
expect { parser.process(response) }.to \
|
32
|
+
raise_error(Typekit::Error, 'Not authorized')
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'typekit'
|
3
|
+
|
4
|
+
describe Typekit::Routing::Map do
|
5
|
+
extend RESTHelper
|
6
|
+
|
7
|
+
def create_request(action)
|
8
|
+
# TODO: mock?
|
9
|
+
Typekit::Connection::Request.new(action: action)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#define' do
|
13
|
+
it 'declares new resources' do
|
14
|
+
subject.define { resources(:kits) }
|
15
|
+
request = subject.trace(create_request(:index), [ :kits ])
|
16
|
+
expect(request.address).to eq('kits')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'declares nested resources' do
|
20
|
+
subject.define { resources(:kits) { resources(:families) } }
|
21
|
+
request = subject.trace(create_request(:show),
|
22
|
+
[ :kits, 'xxx', :families, 'yyy' ])
|
23
|
+
expect(request.address).to eq('kits/xxx/families/yyy')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'declares scoped resources' do
|
27
|
+
subject.define do
|
28
|
+
scope 'https://typekit.com/api' do
|
29
|
+
scope [ 'v1', :json ] do
|
30
|
+
resources(:kits) { resources(:families) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
request = subject.trace(create_request(:show),
|
35
|
+
[ :kits, 'xxx', :families, 'yyy' ])
|
36
|
+
expect(request.address).to eq(
|
37
|
+
'https://typekit.com/api/v1/json/kits/xxx/families/yyy')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'declares custom operations' do
|
41
|
+
subject.define { resources(:kits) { show(:published, on: :member) } }
|
42
|
+
request = subject.trace(create_request(:show),
|
43
|
+
[ :kits, 'xxx', :published ])
|
44
|
+
expect(request.address).to eq('kits/xxx/published')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'declares custom operations with variable names' do
|
48
|
+
subject.define do
|
49
|
+
resources :kits do
|
50
|
+
resources :families do
|
51
|
+
show ':variant', on: :member
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
request = subject.trace(create_request(:show),
|
56
|
+
[ :kits, 'xxx', :families, 'yyy', 'zzz' ])
|
57
|
+
expect(request.address).to eq('kits/xxx/families/yyy/zzz')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#trace' do
|
62
|
+
before(:each) do
|
63
|
+
subject.define do
|
64
|
+
resources :families, only: :show
|
65
|
+
resources :kits do
|
66
|
+
resources :families, only: [ :show, :update, :delete ]
|
67
|
+
show :published, on: :member
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
restful_member_actions.each do |action|
|
73
|
+
it "assembles addresses of #{ action } Requests" do
|
74
|
+
request = subject.trace(create_request(action), [ :kits, 'xxx' ])
|
75
|
+
expect(request.address).to eq('kits/xxx')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
restful_collection_actions.each do |action|
|
80
|
+
it "assembles addresses of #{ action } Requests" do
|
81
|
+
request = subject.trace(create_request(action), [ :kits ])
|
82
|
+
expect(request.address).to eq('kits')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
restful_member_actions.each do |action|
|
87
|
+
it "raises exceptions for #{ action } actions to collections" do
|
88
|
+
expect { subject.trace(create_request(action), [ :kits ]) }.to \
|
89
|
+
raise_error(Typekit::Routing::Error, /Not permitted/i)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
restful_collection_actions.each do |action|
|
94
|
+
it "raises exceptions for #{ action } actions to members" do
|
95
|
+
expect { subject.trace(create_request(action), [ :kits, 'xxx' ]) }.to \
|
96
|
+
raise_error(Typekit::Routing::Error, /Not permitted/i)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'raises exceptions for forbidden actions' do
|
101
|
+
expect do
|
102
|
+
subject.trace(create_request(:index), [ :kits, 'xxx', :families ])
|
103
|
+
end.to raise_error(Typekit::Routing::Error, /Not permitted/i)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'typekit'
|
3
|
+
|
4
|
+
describe Typekit::Routing::Node do
|
5
|
+
extend RESTHelper
|
6
|
+
|
7
|
+
let(:subject_module) { Typekit::Routing::Node }
|
8
|
+
|
9
|
+
def create_tree(*path)
|
10
|
+
root = subject_module::Root.new
|
11
|
+
path.inject(root) do |parent, name|
|
12
|
+
node = subject_module::Collection.new(name)
|
13
|
+
parent.append(node)
|
14
|
+
node
|
15
|
+
end
|
16
|
+
root
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'Base#assemble' do
|
20
|
+
let(:root) { create_tree(:kits, :families) }
|
21
|
+
|
22
|
+
restful_collection_actions.each do |action|
|
23
|
+
it "builds up #{ action } Requests" do
|
24
|
+
request = double('Request', :<< => nil, :action => action,
|
25
|
+
:path => [ :kits, 'xxx', :families ])
|
26
|
+
root.assemble(request, [ :kits, 'xxx', :families ])
|
27
|
+
expect(request).to have_received(:<<).exactly(3).times
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
restful_member_actions.each do |action|
|
32
|
+
it "builds up #{ action } Requests" do
|
33
|
+
request = double('Request', :<< => nil, :action => action,
|
34
|
+
:path => [ :kits, 'xxx', :families, 'yyy' ])
|
35
|
+
root.assemble(request, [ :kits, 'xxx', :families, 'yyy' ])
|
36
|
+
expect(request).to have_received(:<<).exactly(4).times
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'typekit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'typekit-client'
|
8
|
+
spec.version = Typekit::VERSION
|
9
|
+
spec.authors = [ 'Ivan Ukhov' ]
|
10
|
+
spec.email = [ 'ivan.ukhov@gmail.com' ]
|
11
|
+
spec.summary = 'A Ruby library for accessing the Typekit API'
|
12
|
+
spec.description = 'A Ruby library for performing create, read, ' \
|
13
|
+
'update, and delete operations on the resources ' \
|
14
|
+
'provided by the Typekit service.'
|
15
|
+
spec.homepage = 'https://github.com/IvanUkhov/typekit-client'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
21
|
+
spec.require_paths = [ 'lib' ]
|
22
|
+
|
23
|
+
spec.required_ruby_version = '>= 2.1'
|
24
|
+
|
25
|
+
spec.add_dependency 'rack', '~> 1.5'
|
26
|
+
spec.add_dependency 'json', '~> 1.8'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
29
|
+
spec.add_development_dependency 'rake', '~> 0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
31
|
+
spec.add_development_dependency 'webmock', '~> 1.18'
|
32
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typekit-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Ukhov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.14'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.14'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.18'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.18'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.9'
|
111
|
+
description: A Ruby library for performing create, read, update, and delete operations
|
112
|
+
on the resources provided by the Typekit service.
|
113
|
+
email:
|
114
|
+
- ivan.ukhov@gmail.com
|
115
|
+
executables:
|
116
|
+
- typekit
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/typekit
|
128
|
+
- lib/typekit.rb
|
129
|
+
- lib/typekit/client.rb
|
130
|
+
- lib/typekit/configuration.rb
|
131
|
+
- lib/typekit/configuration/base.rb
|
132
|
+
- lib/typekit/configuration/default.rb
|
133
|
+
- lib/typekit/connection.rb
|
134
|
+
- lib/typekit/connection/adaptor.rb
|
135
|
+
- lib/typekit/connection/adaptor/standard.rb
|
136
|
+
- lib/typekit/connection/dispatcher.rb
|
137
|
+
- lib/typekit/connection/request.rb
|
138
|
+
- lib/typekit/connection/response.rb
|
139
|
+
- lib/typekit/core.rb
|
140
|
+
- lib/typekit/helper.rb
|
141
|
+
- lib/typekit/parser.rb
|
142
|
+
- lib/typekit/parser/json.rb
|
143
|
+
- lib/typekit/parser/yaml.rb
|
144
|
+
- lib/typekit/processor.rb
|
145
|
+
- lib/typekit/routing.rb
|
146
|
+
- lib/typekit/routing/map.rb
|
147
|
+
- lib/typekit/routing/node.rb
|
148
|
+
- lib/typekit/routing/node/base.rb
|
149
|
+
- lib/typekit/routing/node/collection.rb
|
150
|
+
- lib/typekit/routing/node/operation.rb
|
151
|
+
- lib/typekit/routing/node/root.rb
|
152
|
+
- lib/typekit/routing/node/scope.rb
|
153
|
+
- lib/typekit/routing/proxy.rb
|
154
|
+
- lib/typekit/version.rb
|
155
|
+
- spec/cassettes/index_kits_ok.yml
|
156
|
+
- spec/cassettes/index_kits_unauthorized.yml
|
157
|
+
- spec/cassettes/show_families_calluna_found.yml
|
158
|
+
- spec/spec_helper.rb
|
159
|
+
- spec/support/rest_helper.rb
|
160
|
+
- spec/typekit/client_spec.rb
|
161
|
+
- spec/typekit/configuration_spec.rb
|
162
|
+
- spec/typekit/connection/adaptor_spec.rb
|
163
|
+
- spec/typekit/connection/dispatcher_spec.rb
|
164
|
+
- spec/typekit/connection/request_spec.rb
|
165
|
+
- spec/typekit/helper_spec.rb
|
166
|
+
- spec/typekit/processor_spec.rb
|
167
|
+
- spec/typekit/routing/map_spec.rb
|
168
|
+
- spec/typekit/routing/node_spec.rb
|
169
|
+
- typekit-client.gemspec
|
170
|
+
homepage: https://github.com/IvanUkhov/typekit-client
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '2.1'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.2.2
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: A Ruby library for accessing the Typekit API
|
194
|
+
test_files:
|
195
|
+
- spec/cassettes/index_kits_ok.yml
|
196
|
+
- spec/cassettes/index_kits_unauthorized.yml
|
197
|
+
- spec/cassettes/show_families_calluna_found.yml
|
198
|
+
- spec/spec_helper.rb
|
199
|
+
- spec/support/rest_helper.rb
|
200
|
+
- spec/typekit/client_spec.rb
|
201
|
+
- spec/typekit/configuration_spec.rb
|
202
|
+
- spec/typekit/connection/adaptor_spec.rb
|
203
|
+
- spec/typekit/connection/dispatcher_spec.rb
|
204
|
+
- spec/typekit/connection/request_spec.rb
|
205
|
+
- spec/typekit/helper_spec.rb
|
206
|
+
- spec/typekit/processor_spec.rb
|
207
|
+
- spec/typekit/routing/map_spec.rb
|
208
|
+
- spec/typekit/routing/node_spec.rb
|