typekit-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +6 -0
  4. data/CHANGELOG.md +9 -5
  5. data/Guardfile +7 -0
  6. data/README.md +160 -131
  7. data/bin/typekit +21 -8
  8. data/lib/typekit/client.rb +5 -5
  9. data/lib/typekit/configuration/base.rb +1 -1
  10. data/lib/typekit/configuration/default.rb +9 -5
  11. data/lib/typekit/connection/dispatcher.rb +2 -2
  12. data/lib/typekit/connection/request.rb +5 -2
  13. data/lib/typekit/connection/response.rb +4 -8
  14. data/lib/typekit/helper.rb +22 -0
  15. data/lib/typekit/processing/converter/boolean.rb +11 -0
  16. data/lib/typekit/processing/converter/datetime.rb +11 -0
  17. data/lib/typekit/processing/converter/errors.rb +22 -0
  18. data/lib/typekit/processing/converter/record.rb +15 -0
  19. data/lib/typekit/processing/converter/records.rb +18 -0
  20. data/lib/typekit/processing/converter/unknown.rb +14 -0
  21. data/lib/typekit/processing/converter.rb +32 -0
  22. data/lib/typekit/processing/parser/json.rb +15 -0
  23. data/lib/typekit/processing/parser/yaml.rb +15 -0
  24. data/lib/typekit/processing/parser.rb +14 -0
  25. data/lib/typekit/processing/translator.rb +16 -0
  26. data/lib/typekit/processing.rb +9 -0
  27. data/lib/typekit/record/base.rb +30 -0
  28. data/lib/typekit/record/family.rb +7 -0
  29. data/lib/typekit/record/kit.rb +7 -0
  30. data/lib/typekit/record/library.rb +7 -0
  31. data/lib/typekit/record/variation.rb +8 -0
  32. data/lib/typekit/record.rb +35 -0
  33. data/lib/typekit/routing/{map.rb → mapper.rb} +1 -1
  34. data/lib/typekit/routing/node/base.rb +1 -0
  35. data/lib/typekit/routing.rb +1 -1
  36. data/lib/typekit/version.rb +1 -1
  37. data/lib/typekit.rb +4 -4
  38. data/spec/cassettes/delete_kits_xxx_ok.yml +16 -0
  39. data/spec/typekit/client_spec.rb +11 -3
  40. data/spec/typekit/configuration_spec.rb +20 -4
  41. data/spec/typekit/connection/dispatcher_spec.rb +4 -4
  42. data/spec/typekit/connection/response_spec.rb +18 -0
  43. data/spec/typekit/helper_spec.rb +34 -0
  44. data/spec/typekit/processing/converter_spec.rb +54 -0
  45. data/spec/typekit/processing/parser_spec.rb +23 -0
  46. data/spec/typekit/record/base_spec.rb +33 -0
  47. data/spec/typekit/record_spec.rb +48 -0
  48. data/spec/typekit/routing/mapper_spec.rb +177 -0
  49. data/spec/typekit/routing/node_spec.rb +31 -10
  50. data/typekit-client.gemspec +2 -1
  51. metadata +53 -13
  52. data/lib/typekit/parser/json.rb +0 -13
  53. data/lib/typekit/parser/yaml.rb +0 -13
  54. data/lib/typekit/parser.rb +0 -14
  55. data/lib/typekit/processor.rb +0 -38
  56. data/spec/typekit/processor_spec.rb +0 -34
  57. data/spec/typekit/routing/map_spec.rb +0 -106
@@ -1,106 +0,0 @@
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