typekit-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/README.md +1 -4
  4. data/bin/typekit +0 -8
  5. data/lib/typekit.rb +3 -5
  6. data/lib/typekit/client.rb +28 -21
  7. data/lib/typekit/core.rb +23 -8
  8. data/lib/typekit/helper.rb +0 -40
  9. data/lib/typekit/processing.rb +0 -1
  10. data/lib/typekit/processing/converter.rb +2 -1
  11. data/lib/typekit/processing/converter/unknown.rb +2 -1
  12. data/lib/typekit/processing/translator.rb +6 -9
  13. data/lib/typekit/record.rb +2 -2
  14. data/lib/typekit/version.rb +1 -1
  15. data/spec/spec_helper.rb +1 -0
  16. data/spec/typekit/client_spec.rb +1 -3
  17. data/spec/typekit/helper_spec.rb +0 -88
  18. data/spec/typekit/processing/converter_spec.rb +1 -2
  19. data/spec/typekit/record/base_spec.rb +0 -1
  20. data/spec/typekit/record_spec.rb +0 -1
  21. data/typekit-client.gemspec +3 -3
  22. metadata +18 -41
  23. data/lib/typekit/configuration.rb +0 -16
  24. data/lib/typekit/configuration/base.rb +0 -21
  25. data/lib/typekit/configuration/default.rb +0 -38
  26. data/lib/typekit/connection.rb +0 -10
  27. data/lib/typekit/connection/adaptor.rb +0 -13
  28. data/lib/typekit/connection/adaptor/standard.rb +0 -32
  29. data/lib/typekit/connection/dispatcher.rb +0 -17
  30. data/lib/typekit/connection/request.rb +0 -26
  31. data/lib/typekit/connection/response.rb +0 -16
  32. data/lib/typekit/processing/parser.rb +0 -14
  33. data/lib/typekit/processing/parser/json.rb +0 -15
  34. data/lib/typekit/processing/parser/yaml.rb +0 -15
  35. data/lib/typekit/routing.rb +0 -9
  36. data/lib/typekit/routing/mapper.rb +0 -43
  37. data/lib/typekit/routing/node.rb +0 -5
  38. data/lib/typekit/routing/node/base.rb +0 -46
  39. data/lib/typekit/routing/node/collection.rb +0 -34
  40. data/lib/typekit/routing/node/operation.rb +0 -32
  41. data/lib/typekit/routing/node/root.rb +0 -8
  42. data/lib/typekit/routing/node/scope.rb +0 -19
  43. data/lib/typekit/routing/proxy.rb +0 -17
  44. data/spec/typekit/configuration_spec.rb +0 -50
  45. data/spec/typekit/connection/adaptor_spec.rb +0 -24
  46. data/spec/typekit/connection/dispatcher_spec.rb +0 -36
  47. data/spec/typekit/connection/request_spec.rb +0 -13
  48. data/spec/typekit/connection/response_spec.rb +0 -18
  49. data/spec/typekit/processing/parser_spec.rb +0 -23
  50. data/spec/typekit/routing/mapper_spec.rb +0 -177
  51. data/spec/typekit/routing/node_spec.rb +0 -61
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'typekit'
3
2
 
4
3
  describe Typekit::Processing::Converter do
5
4
  def create(name)
@@ -47,7 +46,7 @@ describe Typekit::Processing::Converter do
47
46
  %w{kittens puppies}.each do |name|
48
47
  it "returns unknowns like '#{ name }' as they are" do
49
48
  result = create(name).process(request, 42)
50
- expect(result).to be(42)
49
+ expect(result).to eq(name => 42)
51
50
  end
52
51
  end
53
52
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'typekit'
3
2
 
4
3
  describe Typekit::Record::Base do
5
4
  let(:subject_class) { Typekit::Record::Base }
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'typekit'
3
2
 
4
3
  describe Typekit::Record do
5
4
  let(:subject_module) { Typekit::Record }
@@ -9,9 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = [ 'Ivan Ukhov' ]
10
10
  spec.email = [ 'ivan.ukhov@gmail.com' ]
11
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.'
12
+ spec.description = 'A Ruby library for manipulating the resources ' \
13
+ 'provided by the Typekit Web service.'
15
14
  spec.homepage = 'https://github.com/IvanUkhov/typekit-client'
16
15
  spec.license = 'MIT'
17
16
 
@@ -24,6 +23,7 @@ Gem::Specification.new do |spec|
24
23
 
25
24
  spec.add_dependency 'rack', '~> 1.5'
26
25
  spec.add_dependency 'json', '~> 1.8'
26
+ spec.add_dependency 'apitizer', '~> 0.0.1'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.6'
29
29
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typekit-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Ukhov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: apitizer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +136,8 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '2.9'
125
- description: A Ruby library for performing create, read, update, and delete operations
126
- on the resources provided by the Typekit service.
139
+ description: A Ruby library for manipulating the resources provided by the Typekit
140
+ Web service.
127
141
  email:
128
142
  - ivan.ukhov@gmail.com
129
143
  executables:
@@ -143,15 +157,6 @@ files:
143
157
  - bin/typekit
144
158
  - lib/typekit.rb
145
159
  - lib/typekit/client.rb
146
- - lib/typekit/configuration.rb
147
- - lib/typekit/configuration/base.rb
148
- - lib/typekit/configuration/default.rb
149
- - lib/typekit/connection.rb
150
- - lib/typekit/connection/adaptor.rb
151
- - lib/typekit/connection/adaptor/standard.rb
152
- - lib/typekit/connection/dispatcher.rb
153
- - lib/typekit/connection/request.rb
154
- - lib/typekit/connection/response.rb
155
160
  - lib/typekit/core.rb
156
161
  - lib/typekit/helper.rb
157
162
  - lib/typekit/processing.rb
@@ -162,9 +167,6 @@ files:
162
167
  - lib/typekit/processing/converter/record.rb
163
168
  - lib/typekit/processing/converter/records.rb
164
169
  - lib/typekit/processing/converter/unknown.rb
165
- - lib/typekit/processing/parser.rb
166
- - lib/typekit/processing/parser/json.rb
167
- - lib/typekit/processing/parser/yaml.rb
168
170
  - lib/typekit/processing/translator.rb
169
171
  - lib/typekit/record.rb
170
172
  - lib/typekit/record/base.rb
@@ -172,15 +174,6 @@ files:
172
174
  - lib/typekit/record/kit.rb
173
175
  - lib/typekit/record/library.rb
174
176
  - lib/typekit/record/variation.rb
175
- - lib/typekit/routing.rb
176
- - lib/typekit/routing/mapper.rb
177
- - lib/typekit/routing/node.rb
178
- - lib/typekit/routing/node/base.rb
179
- - lib/typekit/routing/node/collection.rb
180
- - lib/typekit/routing/node/operation.rb
181
- - lib/typekit/routing/node/root.rb
182
- - lib/typekit/routing/node/scope.rb
183
- - lib/typekit/routing/proxy.rb
184
177
  - lib/typekit/version.rb
185
178
  - spec/cassettes/delete_kits_xxx_ok.yml
186
179
  - spec/cassettes/index_kits_ok.yml
@@ -189,18 +182,10 @@ files:
189
182
  - spec/spec_helper.rb
190
183
  - spec/support/rest_helper.rb
191
184
  - spec/typekit/client_spec.rb
192
- - spec/typekit/configuration_spec.rb
193
- - spec/typekit/connection/adaptor_spec.rb
194
- - spec/typekit/connection/dispatcher_spec.rb
195
- - spec/typekit/connection/request_spec.rb
196
- - spec/typekit/connection/response_spec.rb
197
185
  - spec/typekit/helper_spec.rb
198
186
  - spec/typekit/processing/converter_spec.rb
199
- - spec/typekit/processing/parser_spec.rb
200
187
  - spec/typekit/record/base_spec.rb
201
188
  - spec/typekit/record_spec.rb
202
- - spec/typekit/routing/mapper_spec.rb
203
- - spec/typekit/routing/node_spec.rb
204
189
  - typekit-client.gemspec
205
190
  homepage: https://github.com/IvanUkhov/typekit-client
206
191
  licenses:
@@ -234,15 +219,7 @@ test_files:
234
219
  - spec/spec_helper.rb
235
220
  - spec/support/rest_helper.rb
236
221
  - spec/typekit/client_spec.rb
237
- - spec/typekit/configuration_spec.rb
238
- - spec/typekit/connection/adaptor_spec.rb
239
- - spec/typekit/connection/dispatcher_spec.rb
240
- - spec/typekit/connection/request_spec.rb
241
- - spec/typekit/connection/response_spec.rb
242
222
  - spec/typekit/helper_spec.rb
243
223
  - spec/typekit/processing/converter_spec.rb
244
- - spec/typekit/processing/parser_spec.rb
245
224
  - spec/typekit/record/base_spec.rb
246
225
  - spec/typekit/record_spec.rb
247
- - spec/typekit/routing/mapper_spec.rb
248
- - spec/typekit/routing/node_spec.rb
@@ -1,16 +0,0 @@
1
- require_relative 'configuration/base'
2
- require_relative 'configuration/default'
3
-
4
- module Typekit
5
- module Configuration
6
- Error = Class.new(Typekit::Error)
7
-
8
- def self.build(name, **options)
9
- self.const_get(name.to_s.capitalize).new(**options)
10
- rescue NameError
11
- raise Error, 'Unknown configuration'
12
- rescue ArgumentError => e
13
- raise Error, 'Not enough arguments'
14
- end
15
- end
16
- end
@@ -1,21 +0,0 @@
1
- module Typekit
2
- module Configuration
3
- class Base
4
- attr_reader :version, :format, :token
5
-
6
- def initialize(version: 1, format: :json, token:)
7
- @version = version
8
- @format = format
9
- @token = token
10
- end
11
-
12
- [ :mapper, :dispatcher, :translator ].each do |component|
13
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
14
- def #{ component }
15
- @#{ component } ||= build_#{ component }
16
- end
17
- METHOD
18
- end
19
- end
20
- end
21
- end
@@ -1,38 +0,0 @@
1
- module Typekit
2
- module Configuration
3
- class Default < Base
4
- private
5
-
6
- def build_mapper
7
- context = build_context
8
- Routing::Mapper.new do
9
- scope context do
10
- resources :families, only: :show do
11
- show ':variant', on: :member
12
- end
13
-
14
- resources :kits do
15
- resources :families, only: [ :show, :update, :delete ]
16
- show :published, on: :member
17
- update :publish, on: :member
18
- end
19
-
20
- resources :libraries, only: [ :index, :show ]
21
- end
22
- end
23
- end
24
-
25
- def build_dispatcher
26
- Connection::Dispatcher.new(adaptor: :standard, token: token)
27
- end
28
-
29
- def build_translator
30
- Processing::Translator.new(format: format)
31
- end
32
-
33
- def build_context
34
- [ Typekit.address, "v#{ version }", format ]
35
- end
36
- end
37
- end
38
- end
@@ -1,10 +0,0 @@
1
- require_relative 'connection/adaptor'
2
- require_relative 'connection/request'
3
- require_relative 'connection/response'
4
- require_relative 'connection/dispatcher'
5
-
6
- module Typekit
7
- module Connection
8
- Error = Class.new(Typekit::Error)
9
- end
10
- end
@@ -1,13 +0,0 @@
1
- require_relative 'adaptor/standard'
2
-
3
- module Typekit
4
- module Connection
5
- module Adaptor
6
- def self.build(name)
7
- self.const_get(name.to_s.capitalize).new
8
- rescue NameError
9
- raise Error, 'Unknown connection adaptor'
10
- end
11
- end
12
- end
13
- end
@@ -1,32 +0,0 @@
1
- require 'net/https'
2
- require 'uri'
3
-
4
- module Typekit
5
- module Connection
6
- module Adaptor
7
- class Standard
8
- def process(method, address, parameters = {}, headers = {})
9
- klass = Net::HTTP.const_get(method.to_s.capitalize)
10
- request = klass.new(build_uri(address, parameters))
11
- headers.each { |k, v| request[k] = v }
12
- http = Net::HTTP.new(request.uri.host, request.uri.port)
13
- http.use_ssl = true if address =~ /^https:/
14
- response = http.request(request)
15
- [ response.code, response.to_hash, response.body ]
16
- rescue NameError
17
- raise Error, 'Invalid method'
18
- rescue SocketError
19
- raise Error, 'Connection failed'
20
- end
21
-
22
- private
23
-
24
- def build_uri(address, parameters)
25
- chunks = [ address ]
26
- chunks << Helper.build_query(parameters) unless parameters.empty?
27
- URI(chunks.join('?'))
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,17 +0,0 @@
1
- module Typekit
2
- module Connection
3
- class Dispatcher
4
- def initialize(adaptor: :standard, token:)
5
- @token = token
6
- @adaptor = Adaptor.build(adaptor)
7
- end
8
-
9
- def process(request)
10
- method = Helper.translate_action(request.action)
11
- code, _, body = @adaptor.process(method, request.address,
12
- request.parameters, 'X-Typekit-Token' => @token)
13
- Response.new(code: code.to_i, body: body)
14
- end
15
- end
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Typekit
4
- module Connection
5
- class Request
6
- extend Forwardable
7
-
8
- attr_reader :action, :parameters, :path, :node
9
- def_delegators :@path, :<<
10
-
11
- def initialize(action:, parameters: {})
12
- @action = action
13
- @parameters = parameters
14
- @path = []
15
- end
16
-
17
- def address
18
- @path.map(&:to_s).join('/')
19
- end
20
-
21
- def sign(node)
22
- @node = node
23
- end
24
- end
25
- end
26
- end
@@ -1,16 +0,0 @@
1
- module Typekit
2
- module Connection
3
- class Response
4
- attr_reader :code, :body
5
-
6
- def initialize(code:, body:)
7
- @code = code
8
- @body = body
9
- end
10
-
11
- def success?
12
- [ 200, 302 ].include?(@code)
13
- end
14
- end
15
- end
16
- end
@@ -1,14 +0,0 @@
1
- require_relative 'parser/json'
2
- require_relative 'parser/yaml'
3
-
4
- module Typekit
5
- module Processing
6
- module Parser
7
- def self.build(format)
8
- self.const_get(format.to_s.upcase).new
9
- rescue NameError
10
- raise Error, 'Unknown format'
11
- end
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- require 'json'
2
-
3
- module Typekit
4
- module Processing
5
- module Parser
6
- class JSON
7
- def process(data)
8
- ::JSON.parse(data)
9
- rescue
10
- raise Error, 'Unable to parse'
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- require 'yaml'
2
-
3
- module Typekit
4
- module Processing
5
- module Parser
6
- class YAML
7
- def process(data)
8
- ::YAML.load(data)
9
- rescue
10
- raise Error, 'Unable to parse'
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require_relative 'routing/node'
2
- require_relative 'routing/proxy'
3
- require_relative 'routing/mapper'
4
-
5
- module Typekit
6
- module Routing
7
- Error = Class.new(Typekit::Error)
8
- end
9
- end
@@ -1,43 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Typekit
4
- module Routing
5
- class Mapper
6
- extend Forwardable
7
-
8
- def_delegator :@root, :assemble, :trace
9
-
10
- def initialize(&block)
11
- @root = Node::Root.new
12
- define(&block) if block_given?
13
- end
14
-
15
- def define(&block)
16
- proxy = Proxy.new(self)
17
- proxy.instance_eval(&block)
18
- end
19
-
20
- def define_scope(path, parent: @root, &block)
21
- child = Node::Scope.new(path)
22
- parent.append(child)
23
- proxy = Proxy.new(self, parent: child)
24
- proxy.instance_eval(&block)
25
- end
26
-
27
- def define_resources(name, parent: @root, **options, &block)
28
- child = Node::Collection.new(name, **options)
29
- parent.append(child)
30
- return unless block_given?
31
- proxy = Proxy.new(self, parent: child)
32
- proxy.instance_eval(&block)
33
- end
34
-
35
- Typekit.actions.each do |action|
36
- define_method "define_#{ action }" do |name, parent:, **options|
37
- child = Node::Operation.new(name, action: action, **options)
38
- parent.append(child)
39
- end
40
- end
41
- end
42
- end
43
- end