typekit-client 0.0.3 → 0.0.4
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/CHANGELOG.md +6 -1
- data/README.md +1 -4
- data/bin/typekit +0 -8
- data/lib/typekit.rb +3 -5
- data/lib/typekit/client.rb +28 -21
- data/lib/typekit/core.rb +23 -8
- data/lib/typekit/helper.rb +0 -40
- data/lib/typekit/processing.rb +0 -1
- data/lib/typekit/processing/converter.rb +2 -1
- data/lib/typekit/processing/converter/unknown.rb +2 -1
- data/lib/typekit/processing/translator.rb +6 -9
- data/lib/typekit/record.rb +2 -2
- data/lib/typekit/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/typekit/client_spec.rb +1 -3
- data/spec/typekit/helper_spec.rb +0 -88
- data/spec/typekit/processing/converter_spec.rb +1 -2
- data/spec/typekit/record/base_spec.rb +0 -1
- data/spec/typekit/record_spec.rb +0 -1
- data/typekit-client.gemspec +3 -3
- metadata +18 -41
- data/lib/typekit/configuration.rb +0 -16
- data/lib/typekit/configuration/base.rb +0 -21
- data/lib/typekit/configuration/default.rb +0 -38
- data/lib/typekit/connection.rb +0 -10
- data/lib/typekit/connection/adaptor.rb +0 -13
- data/lib/typekit/connection/adaptor/standard.rb +0 -32
- data/lib/typekit/connection/dispatcher.rb +0 -17
- data/lib/typekit/connection/request.rb +0 -26
- data/lib/typekit/connection/response.rb +0 -16
- data/lib/typekit/processing/parser.rb +0 -14
- data/lib/typekit/processing/parser/json.rb +0 -15
- data/lib/typekit/processing/parser/yaml.rb +0 -15
- data/lib/typekit/routing.rb +0 -9
- data/lib/typekit/routing/mapper.rb +0 -43
- data/lib/typekit/routing/node.rb +0 -5
- data/lib/typekit/routing/node/base.rb +0 -46
- data/lib/typekit/routing/node/collection.rb +0 -34
- data/lib/typekit/routing/node/operation.rb +0 -32
- data/lib/typekit/routing/node/root.rb +0 -8
- data/lib/typekit/routing/node/scope.rb +0 -19
- data/lib/typekit/routing/proxy.rb +0 -17
- data/spec/typekit/configuration_spec.rb +0 -50
- data/spec/typekit/connection/adaptor_spec.rb +0 -24
- data/spec/typekit/connection/dispatcher_spec.rb +0 -36
- data/spec/typekit/connection/request_spec.rb +0 -13
- data/spec/typekit/connection/response_spec.rb +0 -18
- data/spec/typekit/processing/parser_spec.rb +0 -23
- data/spec/typekit/routing/mapper_spec.rb +0 -177
- data/spec/typekit/routing/node_spec.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bc086a0bb50bb480f485bbef88d7bebdcc25356
|
4
|
+
data.tar.gz: f8d01ce2b825b203f8df1ec09607549800987c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632b2218c382aac4717d5aebbb612ccf670c83f36ca0b12ac7b1d1a83018f4d2714893638d39dc10f6c032b6ec473a06a683e7a70e50227cb9ae512c5f2b9997
|
7
|
+
data.tar.gz: 6a55fc36b622cb55a54512abbe3b8648efcae9b4f207928e40191b094781a50c18d225dedc7db5fdc48e3f7d961ed60c0952528acde0824fdc7d3844babdc736
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
## Typekit Client (
|
1
|
+
## Typekit Client 0.0.4 (June 1, 2014)
|
2
|
+
* Extraction of the RESTful API logic into a separate gem called
|
3
|
+
[Apitizer](https://github.com/IvanUkhov/apitizer).
|
4
|
+
* Elimination of the `--version` and `--format` options of the CLI.
|
5
|
+
|
6
|
+
## Typekit Client 0.0.3 (May 31, 2014)
|
2
7
|
* Object-restful mapping (families, kits, etc. got proper classes).
|
3
8
|
* Command history and tab completion in the CLI.
|
4
9
|
|
data/README.md
CHANGED
@@ -272,7 +272,7 @@ p client.show(:kits, kit.id, :published)
|
|
272
272
|
```
|
273
273
|
|
274
274
|
Output:
|
275
|
-
```
|
275
|
+
```json
|
276
276
|
{
|
277
277
|
"id": "vzt4lrg",
|
278
278
|
"name": "Megakit",
|
@@ -312,8 +312,6 @@ Required options:
|
|
312
312
|
-t, --token TOKEN Set the API token
|
313
313
|
|
314
314
|
Other options:
|
315
|
-
-v, --version VERSION Set the API version
|
316
|
-
-f, --format FORMAT Set the data format
|
317
315
|
-h, --help Show this message
|
318
316
|
```
|
319
317
|
|
@@ -371,7 +369,6 @@ $
|
|
371
369
|
```
|
372
370
|
|
373
371
|
## Contributing
|
374
|
-
|
375
372
|
1. Fork it ( https://github.com/IvanUkhov/typekit-client/fork )
|
376
373
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
377
374
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/bin/typekit
CHANGED
@@ -91,14 +91,6 @@ parser = OptionParser.new do |o|
|
|
91
91
|
o.separator ''
|
92
92
|
o.separator 'Other options:'
|
93
93
|
|
94
|
-
o.on('-v', '--version VERSION', 'Set the API version') do |value|
|
95
|
-
options[:version] = value
|
96
|
-
end
|
97
|
-
|
98
|
-
o.on('-f', '--format FORMAT', 'Set the data format') do |value|
|
99
|
-
options[:format] = value
|
100
|
-
end
|
101
|
-
|
102
94
|
o.on_tail('-h', '--help', 'Show this message') do
|
103
95
|
raise
|
104
96
|
end
|
data/lib/typekit.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'apitizer'
|
2
2
|
|
3
3
|
require_relative 'typekit/core'
|
4
4
|
require_relative 'typekit/helper'
|
5
|
-
require_relative 'typekit/configuration'
|
6
5
|
|
7
|
-
require_relative 'typekit/routing'
|
8
|
-
require_relative 'typekit/connection'
|
9
6
|
require_relative 'typekit/processing'
|
10
7
|
|
11
8
|
require_relative 'typekit/record'
|
12
|
-
|
13
9
|
require_relative 'typekit/client'
|
10
|
+
|
11
|
+
require_relative 'typekit/version'
|
data/lib/typekit/client.rb
CHANGED
@@ -1,38 +1,45 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
1
|
module Typekit
|
4
2
|
class Client
|
5
3
|
extend Forwardable
|
6
4
|
|
7
|
-
|
8
|
-
private def_delegator :dispatcher, :process, :dispatch
|
9
|
-
private def_delegator :translator, :process, :translate
|
10
|
-
|
11
|
-
def initialize(config: :default, **options)
|
12
|
-
@config = Configuration.build(config, **options)
|
13
|
-
end
|
5
|
+
def_delegator :translator, :process, :translate
|
14
6
|
|
15
|
-
def
|
16
|
-
|
7
|
+
def initialize(**options)
|
8
|
+
@options = Typekit.defaults.merge(options)
|
9
|
+
raise Error, 'Token is missing' unless @options.key?(:token)
|
17
10
|
end
|
18
11
|
|
19
|
-
|
20
|
-
define_method(
|
21
|
-
|
12
|
+
[ :process, :index, :show, :create, :update, :delete ].each do |method|
|
13
|
+
define_method(method) do |*arguments|
|
14
|
+
translate(engine.send(method, *arguments))
|
22
15
|
end
|
23
16
|
end
|
17
|
+
alias_method :perform, :process
|
24
18
|
|
25
19
|
private
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
[ :engine, :translator ].each do |component|
|
22
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
23
|
+
def #{ component }
|
24
|
+
@#{ component } ||= build_#{ component }
|
25
|
+
end
|
26
|
+
METHOD
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_engine
|
30
|
+
version = @options[:version]
|
31
|
+
format = @options[:format]
|
32
|
+
|
33
|
+
options = @options.merge(dictionary: Typekit.dictionary,
|
34
|
+
headers: Typekit.headers.call(@options[:token]))
|
35
|
+
|
36
|
+
Apitizer::Base.new(**options) do
|
37
|
+
instance_exec(version, format, &Typekit.schema)
|
38
|
+
end
|
30
39
|
end
|
31
40
|
|
32
|
-
def
|
33
|
-
|
34
|
-
request = Connection::Request.new(action: action, parameters: parameters)
|
35
|
-
mapper.trace(request, path)
|
41
|
+
def build_translator
|
42
|
+
Processing::Translator.new
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
data/lib/typekit/core.rb
CHANGED
@@ -1,16 +1,31 @@
|
|
1
1
|
module Typekit
|
2
2
|
Error = Class.new(StandardError)
|
3
3
|
|
4
|
-
@
|
4
|
+
@defaults = { version: 1, format: :json }.freeze
|
5
5
|
|
6
|
-
@
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
@schema = Proc.new do |version, format|
|
7
|
+
address "https://typekit.com/api/v#{ version }/#{ format }"
|
8
|
+
|
9
|
+
resources :families, only: :show do
|
10
|
+
show ':variant', on: :member
|
11
|
+
end
|
12
|
+
|
13
|
+
resources :kits do
|
14
|
+
resources :families, only: [ :show, :update, :delete ]
|
15
|
+
show :published, on: :member
|
16
|
+
update :publish, on: :member
|
17
|
+
end
|
18
|
+
|
19
|
+
resources :libraries, only: [ :index, :show ]
|
20
|
+
end
|
21
|
+
|
22
|
+
@dictionary = { :update => :post }.freeze # not PUT, Typekit’s exception
|
23
|
+
|
24
|
+
@headers = Proc.new do |token|
|
25
|
+
{ 'X-Typekit-Token' => token }
|
26
|
+
end
|
11
27
|
|
12
28
|
singleton_class.class_eval do
|
13
|
-
attr_reader :
|
14
|
-
:member_actions, :action_dictionary
|
29
|
+
attr_reader :defaults, :schema, :dictionary, :headers
|
15
30
|
end
|
16
31
|
end
|
data/lib/typekit/helper.rb
CHANGED
@@ -1,27 +1,5 @@
|
|
1
|
-
require 'rack/utils'
|
2
|
-
|
3
1
|
module Typekit
|
4
2
|
module Helper
|
5
|
-
Error = Class.new(Typekit::Error)
|
6
|
-
|
7
|
-
def self.member_action?(action)
|
8
|
-
if Typekit.member_actions.include?(action)
|
9
|
-
true
|
10
|
-
elsif Typekit.collection_actions.include?(action)
|
11
|
-
false
|
12
|
-
else
|
13
|
-
raise Error, 'Unknown action'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.translate_action(action)
|
18
|
-
Typekit.action_dictionary[action] or raise Error, 'Unknown action'
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.build_query(parameters)
|
22
|
-
Rack::Utils.build_nested_query(prepare_parameters(parameters))
|
23
|
-
end
|
24
|
-
|
25
3
|
def self.pluralize(name)
|
26
4
|
case name
|
27
5
|
when /^.*s$/
|
@@ -43,23 +21,5 @@ module Typekit
|
|
43
21
|
name
|
44
22
|
end
|
45
23
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def self.prepare_parameters(parameters)
|
50
|
-
# PATCH: https://github.com/rack/rack/issues/557
|
51
|
-
Hash[
|
52
|
-
parameters.map do |key, value|
|
53
|
-
case value
|
54
|
-
when Integer, TrueClass, FalseClass
|
55
|
-
[ key, value.to_s ]
|
56
|
-
when Hash
|
57
|
-
[ key, prepare_parameters(value) ]
|
58
|
-
else
|
59
|
-
[ key, value ]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
]
|
63
|
-
end
|
64
24
|
end
|
65
25
|
end
|
data/lib/typekit/processing.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
module Typekit
|
2
2
|
module Processing
|
3
3
|
class Translator
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
data = { nil => nil } unless data.is_a?(Hash) && data.length == 1
|
11
|
-
name, object = *data.first
|
12
|
-
Converter.build(name).process(response, object)
|
4
|
+
def process(result)
|
5
|
+
unless result.is_a?(Hash) && result.length == 1
|
6
|
+
raise Error, 'Unknown server response'
|
7
|
+
end
|
8
|
+
name, object = *result.first
|
9
|
+
Converter.build(name).process(result, object)
|
13
10
|
end
|
14
11
|
end
|
15
12
|
end
|
data/lib/typekit/record.rb
CHANGED
@@ -25,11 +25,11 @@ module Typekit
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.collection?(name)
|
28
|
-
collections.include?(name.to_sym)
|
28
|
+
collections.include?(name.to_s.to_sym)
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.member?(name)
|
32
|
-
members.include?(name.to_sym)
|
32
|
+
members.include?(name.to_s.to_sym)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/typekit/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/typekit/client_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'typekit'
|
3
2
|
|
4
3
|
describe Typekit::Client do
|
5
4
|
let(:token) { 'arbitrary' }
|
@@ -28,8 +27,7 @@ describe Typekit::Client do
|
|
28
27
|
options = { vcr: { cassette_name: 'show_families_calluna_found' } }
|
29
28
|
|
30
29
|
it 'returns the Response as is', options do
|
31
|
-
expect { subject.show(:families, 'calluna') }.not_to
|
32
|
-
raise_error
|
30
|
+
expect { subject.show(:families, 'calluna') }.not_to raise_error
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
data/spec/typekit/helper_spec.rb
CHANGED
@@ -1,43 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'typekit'
|
3
2
|
|
4
3
|
describe Typekit::Helper do
|
5
|
-
extend RESTHelper
|
6
|
-
|
7
4
|
let(:subject_module) { Typekit::Helper }
|
8
5
|
|
9
|
-
describe '.member_action?' do
|
10
|
-
restful_member_actions.each do |action|
|
11
|
-
it "returns true for the #{ action } member action" do
|
12
|
-
expect(subject_module.member_action?(action)).to be_true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
restful_collection_actions.each do |action|
|
17
|
-
it "returns false for the #{ action } collection action" do
|
18
|
-
expect(subject_module.member_action?(action)).to be_false
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'raises exceptions when encounters unknown actions' do
|
23
|
-
expect { subject_module.member_action?(:rock) }.to \
|
24
|
-
raise_error(Typekit::Helper::Error, /Unknown action/i)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '.translate_action' do
|
29
|
-
rest_http_dictionary.each do |action, method|
|
30
|
-
it "returns the #{ method } verb for the #{ action } action" do
|
31
|
-
expect(subject_module.translate_action(action)).to eq(method)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'raises exceptions when encounters unknown actions' do
|
36
|
-
expect { subject_module.translate_action(:rock) }.to \
|
37
|
-
raise_error(Typekit::Helper::Error, /Unknown action/i)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
6
|
describe '.pluralize' do
|
42
7
|
{
|
43
8
|
'kit' => 'kits',
|
@@ -71,57 +36,4 @@ describe Typekit::Helper do
|
|
71
36
|
end
|
72
37
|
end
|
73
38
|
end
|
74
|
-
|
75
|
-
describe '.build_query' do
|
76
|
-
it 'handels ordinary parameters' do
|
77
|
-
queries = [
|
78
|
-
'name=Megakit&domains=localhost',
|
79
|
-
'domains=localhost&name=Megakit'
|
80
|
-
]
|
81
|
-
query = subject_module.build_query(
|
82
|
-
name: 'Megakit', domains: 'localhost')
|
83
|
-
expect(queries).to include(query)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'handles parameters whose values are ordinary lists' do
|
87
|
-
query = subject_module.build_query(
|
88
|
-
domains: [ 'example.com', 'example.net' ])
|
89
|
-
expect(query).to eq('domains[]=example.com&domains[]=example.net')
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'handles parameters whose values are object lists' do
|
93
|
-
queries = [
|
94
|
-
'families[0][id]=gkmg&families[1][id]=asdf',
|
95
|
-
'families[1][id]=asdf&families[0][id]=gkmg'
|
96
|
-
]
|
97
|
-
query = subject_module.build_query(
|
98
|
-
families: { 0 => { id: 'gkmg' }, 1 => { id: 'asdf' } })
|
99
|
-
expect(queries).to include(query)
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'converts integers to decimal strings' do
|
103
|
-
query = subject_module.build_query(page: 42)
|
104
|
-
expect(query).to eq('page=42')
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'converts integers in object lists to decimal strings' do
|
108
|
-
queries = [
|
109
|
-
'primes[0][value]=2&primes[1][value]=3',
|
110
|
-
'primes[1][value]=3&primes[0][value]=2'
|
111
|
-
]
|
112
|
-
query = subject_module.build_query(
|
113
|
-
primes: { 0 => { value: 2 }, 1 => { value: 3 } })
|
114
|
-
expect(queries).to include(query)
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'converts the logical true to the string true' do
|
118
|
-
query = subject_module.build_query(badge: true)
|
119
|
-
expect(query).to eq('badge=true')
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'converts the logical false to the string false' do
|
123
|
-
query = subject_module.build_query(badge: false)
|
124
|
-
expect(query).to eq('badge=false')
|
125
|
-
end
|
126
|
-
end
|
127
39
|
end
|