typekit-client 0.0.5 → 0.0.6

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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -3
  3. data/.travis.yml +4 -0
  4. data/.yardopts +6 -0
  5. data/CHANGELOG.md +12 -0
  6. data/Guardfile +21 -3
  7. data/README.md +253 -248
  8. data/bin/typekit-client +16 -16
  9. data/bin/typekit-publisher +6 -5
  10. data/lib/typekit.rb +6 -2
  11. data/lib/typekit/client.rb +66 -24
  12. data/lib/typekit/collection.rb +6 -11
  13. data/lib/typekit/collection/base.rb +40 -0
  14. data/lib/typekit/collection/serialization.rb +17 -0
  15. data/lib/typekit/converter.rb +26 -0
  16. data/lib/typekit/converter/boolean.rb +12 -0
  17. data/lib/typekit/converter/collection.rb +13 -0
  18. data/lib/typekit/converter/datetime.rb +12 -0
  19. data/lib/typekit/converter/element.rb +13 -0
  20. data/lib/typekit/converter/errors.rb +12 -0
  21. data/lib/typekit/converter/unknown.rb +13 -0
  22. data/lib/typekit/core.rb +8 -10
  23. data/lib/typekit/element.rb +27 -0
  24. data/lib/typekit/element/association.rb +63 -0
  25. data/lib/typekit/element/base.rb +61 -0
  26. data/lib/typekit/element/persistence.rb +61 -0
  27. data/lib/typekit/element/query.rb +25 -0
  28. data/lib/typekit/element/serialization.rb +17 -0
  29. data/lib/typekit/error.rb +23 -0
  30. data/lib/typekit/helper.rb +59 -10
  31. data/lib/typekit/record.rb +18 -22
  32. data/lib/typekit/record/family.rb +24 -1
  33. data/lib/typekit/record/kit.rb +29 -1
  34. data/lib/typekit/record/library.rb +4 -1
  35. data/lib/typekit/record/variation.rb +13 -1
  36. data/lib/typekit/version.rb +1 -1
  37. data/spec/feature/create_kit_spec.rb +52 -0
  38. data/spec/feature/delete_kit_spec.rb +33 -0
  39. data/spec/feature/index_kits_spec.rb +55 -0
  40. data/spec/feature/publish_kit_spec.rb +15 -0
  41. data/spec/feature/show_family_spec.rb +75 -0
  42. data/spec/feature/show_kit_spec.rb +56 -0
  43. data/spec/feature/show_library_spec.rb +29 -0
  44. data/spec/feature/show_variation_spec.rb +18 -0
  45. data/spec/feature/update_kit_spec.rb +88 -0
  46. data/spec/fixture/cassette/create_kits_bad.yml +16 -0
  47. data/spec/fixture/cassette/create_kits_ok.yml +16 -0
  48. data/spec/fixture/cassette/delete_kits_xxx_not_found.yml +13 -0
  49. data/spec/{cassettes → fixture/cassette}/delete_kits_xxx_ok.yml +0 -3
  50. data/spec/fixture/cassette/index_kits_show_kit_xxx_ok.yml +25 -0
  51. data/spec/{cassettes → fixture/cassette}/index_kits_unauthorized.yml +0 -3
  52. data/spec/{cassettes → fixture/cassette}/show_families_xxx_found.yml +0 -3
  53. data/spec/{cassettes → fixture/cassette}/show_families_xxx_ok.yml +0 -3
  54. data/spec/{cassettes → fixture/cassette}/show_families_xxx_yyy_ok.yml +0 -3
  55. data/spec/fixture/cassette/show_families_yyy_update_kits_xxx_families_ok.yml +35 -0
  56. data/spec/fixture/cassette/show_kits_xxx_families_yyy_show_family_yyy_ok.yml +45 -0
  57. data/spec/fixture/cassette/show_kits_xxx_not_found.yml +13 -0
  58. data/spec/fixture/cassette/show_kits_xxx_show_family_yyy_ok.yml +46 -0
  59. data/spec/{cassettes → fixture/cassette}/show_libraries_xxx_ok.yml +0 -3
  60. data/spec/fixture/cassette/update_kits_xxx_empty_families_ok.yml +16 -0
  61. data/spec/fixture/cassette/update_kits_xxx_families_ok.yml +18 -0
  62. data/spec/fixture/cassette/update_kits_xxx_families_variations_ok.yml +18 -0
  63. data/spec/fixture/cassette/update_kits_xxx_name_ok.yml +17 -0
  64. data/spec/fixture/cassette/update_kits_xxx_publish_ok.yml +16 -0
  65. data/spec/fixture/record/article.rb +11 -0
  66. data/spec/fixture/record/section.rb +10 -0
  67. data/spec/lib/typekit/collection_spec.rb +22 -0
  68. data/spec/{typekit/processing → lib/typekit}/converter_spec.rb +13 -13
  69. data/spec/lib/typekit/element/association_spec.rb +96 -0
  70. data/spec/lib/typekit/element/base_spec.rb +70 -0
  71. data/spec/lib/typekit/element/persistence_spec.rb +97 -0
  72. data/spec/lib/typekit/element/serialization_spec.rb +28 -0
  73. data/spec/lib/typekit/element_spec.rb +58 -0
  74. data/spec/{typekit → lib/typekit}/helper_spec.rb +6 -8
  75. data/spec/lib/typekit/record_spec.rb +57 -0
  76. data/spec/spec_helper.rb +10 -3
  77. data/spec/support/common_helper.rb +5 -0
  78. data/spec/support/record_helper.rb +38 -0
  79. data/typekit-client.gemspec +11 -4
  80. metadata +164 -58
  81. data/lib/typekit/processing.rb +0 -8
  82. data/lib/typekit/processing/converter.rb +0 -28
  83. data/lib/typekit/processing/converter/boolean.rb +0 -14
  84. data/lib/typekit/processing/converter/collection.rb +0 -18
  85. data/lib/typekit/processing/converter/datetime.rb +0 -14
  86. data/lib/typekit/processing/converter/errors.rb +0 -24
  87. data/lib/typekit/processing/converter/record.rb +0 -16
  88. data/lib/typekit/processing/converter/unknown.rb +0 -15
  89. data/lib/typekit/processing/translator.rb +0 -13
  90. data/lib/typekit/record/base.rb +0 -52
  91. data/spec/cassettes/index_kits_ok.yml +0 -16
  92. data/spec/cassettes/show_kits_xxx_families_yyy_ok.yml +0 -16
  93. data/spec/cassettes/show_kits_xxx_ok.yml +0 -17
  94. data/spec/features/client/delete_kit_spec.rb +0 -13
  95. data/spec/features/client/index_kits_spec.rb +0 -25
  96. data/spec/features/client/show_family_spec.rb +0 -47
  97. data/spec/features/client/show_kit_spec.rb +0 -18
  98. data/spec/features/client/show_library_spec.rb +0 -18
  99. data/spec/features/client/show_variation_spec.rb +0 -22
  100. data/spec/support/resource_helper.rb +0 -34
  101. data/spec/typekit/record/base_spec.rb +0 -85
  102. data/spec/typekit/record_spec.rb +0 -80
@@ -1,14 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class Boolean
5
- def initialize(*_)
6
- end
7
-
8
- def process(response, object)
9
- object # already boolean
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,18 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class Collection
5
- def initialize(name)
6
- @klass = Typekit::Record.classify(name)
7
- raise Error, 'Unknown class' unless @klass
8
- end
9
-
10
- def process(response, collection_attributes)
11
- collection_attributes.map do |attributes|
12
- @klass.new(attributes)
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class DateTime
5
- def initialize(*_)
6
- end
7
-
8
- def process(response, object)
9
- ::DateTime.parse(object)
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,24 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class Errors
5
- ERRORS = {
6
- 400 => 'There are errors in the data provided by your application',
7
- 401 => 'Authentication is needed to access the requested endpoint',
8
- 403 => 'Your application has been rate limited',
9
- 404 => 'You are requesting a resource that does not exist',
10
- 500 => 'The servers of Typekit are unable to process the request',
11
- 503 => 'The Typekit API is offline for maintenance'
12
- }
13
- ERRORS.default = 'Unknown server error'
14
-
15
- def initialize(*_)
16
- end
17
-
18
- def process(response, errors)
19
- raise Error, Array(errors || ERRORS[response.code]).join(', ')
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class Record
5
- def initialize(name)
6
- @klass = Typekit::Record.classify(name)
7
- raise Error, 'Unknown class' unless @klass
8
- end
9
-
10
- def process(response, attributes)
11
- @klass.new(attributes)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- module Typekit
2
- module Processing
3
- module Converter
4
- class Unknown
5
- def initialize(name)
6
- @name = name
7
- end
8
-
9
- def process(response, object)
10
- { @name => object }
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,13 +0,0 @@
1
- module Typekit
2
- module Processing
3
- class Translator
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)
10
- end
11
- end
12
- end
13
- end
@@ -1,52 +0,0 @@
1
- module Typekit
2
- module Record
3
- class Base
4
- extend Forwardable
5
-
6
- attr_reader :attributes
7
- def_delegator :attributes, :to_json
8
-
9
- def self.has_many(name)
10
- possessions << name
11
- end
12
-
13
- def self.possessions
14
- @possessions ||= []
15
- end
16
-
17
- def self.belongs_to(name)
18
- owners << name
19
- end
20
-
21
- def self.owners
22
- @owners ||= []
23
- end
24
-
25
- def initialize(attributes = {})
26
- attributes = { id: attributes } unless attributes.is_a?(Hash)
27
- @attributes = Helper.symbolize_keys(attributes)
28
-
29
- self.class.possessions.each do |name|
30
- next unless @attributes.key?(name)
31
- @attributes[name] = Collection.new(name, @attributes[name])
32
- end
33
-
34
- self.class.owners.each do |name|
35
- next unless @attributes.key?(name)
36
- @attributes[name] = Record.build(name, @attributes[name])
37
- end
38
- end
39
-
40
- def method_missing(name, *arguments)
41
- if name.to_s =~ /^(?<name>.*)=$/
42
- name = Regexp.last_match(:name).to_sym
43
- return super unless @attributes.key?(name)
44
- @attributes.send(:[]=, name, *arguments)
45
- else
46
- return super unless @attributes.key?(name)
47
- @attributes.send(:[], name, *arguments)
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,16 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://typekit.com/api/v1/json/kits
6
- response:
7
- status:
8
- code: 200
9
- message: OK
10
- headers:
11
- Status:
12
- - 200 OK
13
- body:
14
- encoding: UTF-8
15
- string: '{"kits":[{"id":"bas4cfe","link":"/api/v1/json/kits/bas4cfe"},{"id":"sfh6bkj","link":"/api/v1/json/kits/sfh6bkj"},{"id":"kof8zcn","link":"/api/v1/json/kits/kof8zcn"},{"id":"muq6mxx","link":"/api/v1/json/kits/muq6mxx"}]}'
16
- recorded_at: Fri, 23 May 2014 00:00:00 GMT
@@ -1,16 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://typekit.com/api/v1/json/kits/xxx/families/yyy
6
- response:
7
- status:
8
- code: 200
9
- message: OK
10
- headers:
11
- Status:
12
- - 200 OK
13
- body:
14
- encoding: UTF-8
15
- string: '{"family":{"id":"vcsm","name":"Proxima Nova","slug":"proxima-nova","css_names":["proxima-nova"],"css_stack":"\"proxima-nova\",sans-serif","subset":"default","variations":["n1","n3","n4"]}}'
16
- recorded_at: Fri, 06 Jun 2014 00:00:00 GMT
@@ -1,17 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://typekit.com/api/v1/json/kits/xxx
6
- response:
7
- status:
8
- code: 200
9
- message: OK
10
- headers:
11
- Status:
12
- - 200 OK
13
- body:
14
- encoding: UTF-8
15
- string: '{"kit":{"id":"bas4cfe","name":"Ivan Ukhov at LiU","analytics":false,"badge":false,"domains":["localhost","10.0.2.2","www.ida.liu.se/~ivauk83"],"families":[{"id":"vcsm","name":"Proxima
16
- Nova","slug":"proxima-nova","css_names":["proxima-nova"],"css_stack":"\"proxima-nova\",sans-serif","subset":"default","variations":["n1","n3","n4"]},{"id":"vybr","name":"Calluna","slug":"calluna","css_names":["calluna"],"css_stack":"\"calluna\",serif","subset":"default","variations":["n4","i4"]}]}}'
17
- recorded_at: Thu, 05 Jun 2014 00:00:00 GMT
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#delete a kit' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- options = { vcr: { cassette_name: 'delete_kits_xxx_ok' } }
7
-
8
- let(:result) { subject.delete(:kits, 'xxx') }
9
-
10
- it 'returns true', options do
11
- expect(result).to be true
12
- end
13
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#index kits' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- context 'when successful' do
7
- options = { vcr: { cassette_name: 'index_kits_ok' } }
8
-
9
- let(:result) { subject.index(:kits) }
10
-
11
- it 'returns Records', options do
12
- expect(result.map(&:class).uniq).to \
13
- contain_exactly(Typekit::Record::Kit)
14
- end
15
- end
16
-
17
- context 'when unauthorized' do
18
- options = { vcr: { cassette_name: 'index_kits_unauthorized' } }
19
-
20
- it 'raises exceptions', options do
21
- expect { subject.index(:kits) }.to \
22
- raise_error(Typekit::Processing::Error, /Not authorized/i)
23
- end
24
- end
25
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#show a family' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- shared_examples 'an adequate reader' do |options|
7
- it 'returns a Family', options do
8
- expect(result).to be_kind_of(Typekit::Record::Family)
9
- end
10
-
11
- it 'returns a Family with Variations', options do
12
- expect(result.variations.map(&:class).uniq).to \
13
- contain_exactly(Typekit::Record::Variation)
14
- end
15
- end
16
-
17
- context 'when looking up directly' do
18
- options = { vcr: { cassette_name: 'show_families_xxx_ok' } }
19
-
20
- let(:result) { subject.show(:families, 'xxx') }
21
-
22
- it_behaves_like 'an adequate reader', options
23
-
24
- it 'returns a Family with Libraries', options do
25
- expect(result.libraries.map(&:class).uniq).to \
26
- contain_exactly(Typekit::Record::Library)
27
- end
28
- end
29
-
30
- context 'when looking up through a kit' do
31
- options = { vcr: { cassette_name: 'show_kits_xxx_families_yyy_ok' } }
32
-
33
- let(:result) { subject.show(:kits, 'xxx', :families, 'yyy') }
34
-
35
- it_behaves_like 'an adequate reader', options
36
- end
37
-
38
- context 'when looking up directly via slugs' do
39
- options = { vcr: { cassette_name: 'show_families_xxx_found' } }
40
-
41
- let(:result) { subject.show(:families, 'xxx') }
42
-
43
- it 'returns a Family', options do
44
- expect(result).to be_kind_of(Typekit::Record::Family)
45
- end
46
- end
47
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#show a kit' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- options = { vcr: { cassette_name: 'show_kits_xxx_ok' } }
7
-
8
- let(:result) { subject.show(:kits, 'xxx') }
9
-
10
- it 'returns a Kit', options do
11
- expect(result).to be_kind_of(Typekit::Record::Kit)
12
- end
13
-
14
- it 'returns a Kit with Families', options do
15
- expect(result.families.map(&:class).uniq).to \
16
- contain_exactly(Typekit::Record::Family)
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#show a library' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- options = { vcr: { cassette_name: 'show_libraries_xxx_ok' } }
7
-
8
- let(:result) { subject.show(:libraries, 'xxx') }
9
-
10
- it 'returns a Library', options do
11
- expect(result).to be_kind_of(Typekit::Record::Library)
12
- end
13
-
14
- it 'returns a Library with Families', options do
15
- expect(result.families.map(&:class).uniq).to \
16
- contain_exactly(Typekit::Record::Family)
17
- end
18
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe 'Client#show a variation' do
4
- let(:subject) { Typekit::Client.new(token: 'arbitrary') }
5
-
6
- options = { vcr: { cassette_name: 'show_families_xxx_yyy_ok' } }
7
-
8
- let(:result) { subject.show(:families, 'xxx', 'yyy') }
9
-
10
- it 'returns a Variation', options do
11
- expect(result).to be_kind_of(Typekit::Record::Variation)
12
- end
13
-
14
- it 'returns a Variation with Libraries', options do
15
- expect(result.libraries.map(&:class).uniq).to \
16
- contain_exactly(Typekit::Record::Library)
17
- end
18
-
19
- it 'returns a Variation with a Family', options do
20
- expect(result.family).to be_kind_of(Typekit::Record::Family)
21
- end
22
- end
@@ -1,34 +0,0 @@
1
- module ResourceHelper
2
- RECORD_NAMES = %w{family kit library variation}
3
- COLLECTION_NAMES = %w{families kits libraries variations}
4
-
5
- def record_names
6
- RECORD_CLASS_NAMES
7
- end
8
-
9
- def record_symbols
10
- @record_symbols ||= RECORD_NAMES.map(&:to_sym)
11
- end
12
-
13
- def record_classes
14
- @record_classes ||= RECORD_NAMES.map do |name|
15
- Typekit::Record.const_get(name.capitalize)
16
- end
17
- end
18
-
19
- def collection_names
20
- COLLECTION_NAMES
21
- end
22
-
23
- def collection_symbols
24
- @collection_symbols ||= COLLECTION_NAMES.map(&:to_sym)
25
- end
26
-
27
- def record_mapping
28
- @record_mapping ||= Hash[record_symbols.clone.zip(record_classes)]
29
- end
30
-
31
- def collection_mapping
32
- @collection_mapping ||= Hash[collection_symbols.clone.zip(record_classes)]
33
- end
34
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Typekit::Record::Base do
4
- let(:subject_module) { Typekit::Record }
5
-
6
- def create_class
7
- Class.new(subject_module::Base)
8
- end
9
-
10
- let(:subject_class) { create_class }
11
-
12
- describe '.has_many' do
13
- it 'declares one-to-many relations between Records' do
14
- expect { subject_class.has_many(:sections) }.not_to raise_error
15
- end
16
- end
17
-
18
- describe '.belongs_to' do
19
- it 'declares one-to-one relations between Records' do
20
- expect { subject_class.belongs_to(:article) }.not_to raise_error
21
- end
22
- end
23
-
24
- describe '#new' do
25
- it 'treats each option as an attribute' do
26
- subject = subject_class.new(name: 'Awesome')
27
- expect { subject.name = 'Superb' }.to \
28
- change { subject.name }.from('Awesome').to('Superb')
29
- end
30
-
31
- it 'handles attribute names given as strings' do
32
- subject = subject_class.new('name' => 'Awesome')
33
- expect { subject.name = 'Superb' }.to \
34
- change { subject.name }.from('Awesome').to('Superb')
35
- end
36
- end
37
-
38
- context 'when there are one-to-many relations defined' do
39
- let(:another_class) { create_class }
40
-
41
- before(:example) do
42
- allow(subject_module).to receive(:classify).and_return(another_class)
43
- subject_class.has_many(:sections)
44
- end
45
-
46
- describe '#new' do
47
- context 'when the attributes of the relations are given' do
48
- subject do
49
- subject_class.new(sections: [ { title: 'First' },
50
- { title: 'Second' } ])
51
- end
52
-
53
- it 'initializes relations as Collections' do
54
- expect(subject.sections).to be_kind_of(Typekit::Collection)
55
- end
56
-
57
- it 'initializes Collections based on the attributes' do
58
- expect(subject.sections.map(&:title)).to \
59
- contain_exactly('First', 'Second')
60
- end
61
- end
62
-
63
- context 'when the attributes of the relations are missing' do
64
- subject { subject_class.new }
65
-
66
- it 'does not initialize Collections' do
67
- expect { subject.sections }.to raise_error(NoMethodError)
68
- end
69
- end
70
- end
71
- end
72
-
73
- describe '#attributes' do
74
- it 'returns all attributes' do
75
- subject = subject_class.new(id: 1, name: 'Awesome')
76
- expect(subject.attributes).to eq(id: 1, name: 'Awesome')
77
- end
78
-
79
- it 'reflects attribute assignments' do
80
- subject = subject_class.new(id: 1)
81
- subject.id = 42
82
- expect(subject.attributes).to eq(id: 42)
83
- end
84
- end
85
- end