leadlight 0.0.2 → 0.0.3
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.
- data/Gemfile.lock +5 -7
- data/README.md +82 -0
- data/default.gems +1 -0
- data/leadlight.gemspec +16 -7
- data/lib/leadlight.rb +18 -62
- data/lib/leadlight/basic_converter.rb +18 -0
- data/lib/leadlight/codec.rb +2 -0
- data/lib/leadlight/entity.rb +1 -0
- data/lib/leadlight/errors.rb +10 -2
- data/lib/leadlight/header_helpers.rb +11 -0
- data/lib/leadlight/hyperlinkable.rb +1 -1
- data/lib/leadlight/representation.rb +19 -1
- data/lib/leadlight/request.rb +44 -11
- data/lib/leadlight/service.rb +4 -9
- data/lib/leadlight/service_class_methods.rb +69 -0
- data/lib/leadlight/service_middleware.rb +2 -14
- data/lib/leadlight/tint.rb +6 -2
- data/lib/leadlight/tint_helper.rb +27 -4
- data/lib/leadlight/type_map.rb +101 -0
- data/spec/cassettes/Leadlight/authorized_GitHub_example/_user/has_the_expected_content.yml +8 -8
- data/spec/cassettes/Leadlight/authorized_GitHub_example/_user/indicates_the_expected_oath_scopes.yml +8 -8
- data/spec/cassettes/Leadlight/authorized_GitHub_example/adding_and_removing_team_members.yml +273 -284
- data/spec/cassettes/Leadlight/authorized_GitHub_example/{adding_and_removing_team_members/.yml → adding_and_removing_teams.yml} +57 -84
- data/spec/cassettes/Leadlight/authorized_GitHub_example/test_team/.yml +111 -117
- data/spec/cassettes/Leadlight/basic_GitHub_example/_root/.yml +58 -25
- data/spec/cassettes/Leadlight/basic_GitHub_example/_root/__location__/.yml +58 -25
- data/spec/cassettes/Leadlight/basic_GitHub_example/_root/should_be_a_204_no_content.yml +58 -25
- data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/.yml +58 -25
- data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/__location__/.yml +58 -25
- data/spec/cassettes/Leadlight/tinted_GitHub_example/_root/should_be_a_204_no_content.yml +58 -25
- data/spec/cassettes/Leadlight/tinted_GitHub_example/_user/has_the_expected_content.yml +122 -50
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/.yml +190 -77
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_able_to_follow_next_link.yml +260 -104
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable.yml +616 -212
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_be_enumerable_over_page_boundaries.yml +331 -131
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_followers/should_have_next_and_last_links.yml +190 -77
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_link/exists.yml +58 -25
- data/spec/cassettes/Leadlight/tinted_GitHub_example/user_link/links_to_the_expected_URL.yml +58 -25
- data/spec/leadlight/hyperlinkable_spec.rb +3 -1
- data/spec/leadlight/link_template_spec.rb +2 -1
- data/spec/leadlight/request_spec.rb +44 -21
- data/spec/leadlight/service_middleware_spec.rb +9 -46
- data/spec/leadlight/service_spec.rb +30 -24
- data/spec/leadlight/tint_helper_spec.rb +67 -1
- data/spec/leadlight/tint_spec.rb +69 -0
- data/spec/leadlight/type_map_spec.rb +127 -0
- data/spec/leadlight_spec.rb +102 -51
- data/spec/support/credentials.rb +10 -2
- data/spec/support/vcr.rb +1 -1
- metadata +61 -32
- data/lib/leadlight/type.rb +0 -71
- data/spec/leadlight/type_spec.rb +0 -137
data/lib/leadlight/type.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'fattr'
|
2
|
-
require 'addressable/template'
|
3
|
-
require 'leadlight/tint'
|
4
|
-
|
5
|
-
module Leadlight
|
6
|
-
class Type < Module
|
7
|
-
attr_reader :name
|
8
|
-
attr_reader :service
|
9
|
-
fattr :enctype
|
10
|
-
fattr :link_to_create
|
11
|
-
|
12
|
-
def initialize(name, service, &body)
|
13
|
-
@name = name
|
14
|
-
@service = service
|
15
|
-
@builder = Object.method(:new)
|
16
|
-
@enctype = 'application/json'
|
17
|
-
super() do
|
18
|
-
instance_exec &preamble
|
19
|
-
instance_exec &body
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def inspect
|
24
|
-
"#<Leadlight::Type:#{name}>"
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_s
|
28
|
-
"Type(#{name})"
|
29
|
-
end
|
30
|
-
|
31
|
-
def builder(&block)
|
32
|
-
@builder = block
|
33
|
-
end
|
34
|
-
|
35
|
-
def build(*args)
|
36
|
-
obj = @builder.call(*args).extend(self)
|
37
|
-
yield obj if block_given?
|
38
|
-
obj
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_entity(object)
|
42
|
-
Entity.new(enctype)
|
43
|
-
end
|
44
|
-
|
45
|
-
def encode(representation, options={})
|
46
|
-
encoder = options.fetch(:encoder){ representation.__service__ }
|
47
|
-
encoder.encode(enctype, representation, options)
|
48
|
-
end
|
49
|
-
|
50
|
-
def extended(object)
|
51
|
-
super
|
52
|
-
if link_to_create
|
53
|
-
object.add_link(link_to_create, 'create', "Create a new #{name}")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def tint
|
58
|
-
@tint ||= Tint.new("type:#{name}") do
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def preamble
|
65
|
-
the_type = self
|
66
|
-
proc {
|
67
|
-
define_method(:__type__){ the_type }
|
68
|
-
}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/leadlight/type_spec.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'spec_helper_lite'
|
2
|
-
require 'leadlight/type'
|
3
|
-
|
4
|
-
module Leadlight
|
5
|
-
describe Type do
|
6
|
-
let(:service) { stub(:service) }
|
7
|
-
let(:name) { "test_type" }
|
8
|
-
let(:type) { Type.new(name, service, &body) }
|
9
|
-
let(:body) { Proc.new{} }
|
10
|
-
let(:instance){ stub(:instance) }
|
11
|
-
let(:object) { instance.extend(type) }
|
12
|
-
let(:encoder) { stub(:encoder) }
|
13
|
-
|
14
|
-
subject { type }
|
15
|
-
|
16
|
-
its(:name) { should eq(name) }
|
17
|
-
its(:service) { should equal(service) }
|
18
|
-
its(:inspect) { should eq("#<Leadlight::Type:#{name}>") }
|
19
|
-
its(:to_s) { should eq("Type(#{name})") }
|
20
|
-
|
21
|
-
describe '#build' do
|
22
|
-
let(:body) {
|
23
|
-
my_builder = stub_builder
|
24
|
-
proc do |*args|
|
25
|
-
builder &my_builder
|
26
|
-
end
|
27
|
-
}
|
28
|
-
let(:stub_builder) { proc{|*args| instance} }
|
29
|
-
it 'uses the specified builder block' do
|
30
|
-
type.build.should eq(instance)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'passes params to the builder' do
|
34
|
-
stub_builder.should_receive(:call).with(1,2,3)
|
35
|
-
type.build(1,2,3)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'yields the built object' do
|
39
|
-
yielded = :not_set
|
40
|
-
type.build do |obj|
|
41
|
-
yielded = obj
|
42
|
-
end
|
43
|
-
yielded.should equal(instance)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'includes itself into the built object' do
|
47
|
-
type.build.should be_a(type)
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'with no builder specified' do
|
51
|
-
let(:body) { proc{} }
|
52
|
-
it 'defaults to Object.new' do
|
53
|
-
type.build.class.should == Object
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe 'when included' do
|
59
|
-
subject { object }
|
60
|
-
it 'adds a __type__ to the extended object, referencing itself' do
|
61
|
-
subject.__type__.should equal(type)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#enctype' do
|
66
|
-
context 'when unspecified' do
|
67
|
-
its(:enctype) { should eq('application/json') }
|
68
|
-
|
69
|
-
it 'is used when encoding' do
|
70
|
-
body = stub
|
71
|
-
entity_body = stub
|
72
|
-
options = {encoder: encoder}
|
73
|
-
encoder.should_receive(:encode).
|
74
|
-
with('application/json', body, options).
|
75
|
-
and_return(entity_body)
|
76
|
-
type.encode(body, options).should equal(entity_body)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when explicitly specified' do
|
81
|
-
let(:body) { proc{ enctype 'text/plain' } }
|
82
|
-
|
83
|
-
it 'is changed' do
|
84
|
-
type.enctype.should eq('text/plain')
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'is used when encoding' do
|
88
|
-
body = stub
|
89
|
-
entity_body = stub
|
90
|
-
options = {encoder: encoder}
|
91
|
-
encoder.should_receive(:encode).
|
92
|
-
with('text/plain', body, options).
|
93
|
-
and_return(entity_body)
|
94
|
-
type.encode(body, options).should equal(entity_body)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'link_to_create' do
|
100
|
-
let(:body) {
|
101
|
-
the_link = link
|
102
|
-
proc {
|
103
|
-
link_to_create(the_link)
|
104
|
-
}
|
105
|
-
}
|
106
|
-
let(:link) { '/foo/{x}/bar' }
|
107
|
-
|
108
|
-
it 'is saved' do
|
109
|
-
type.link_to_create.should eq(link)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'adds a link to the representation' do
|
113
|
-
instance.should_receive(:add_link).with(link, 'create', "Create a new #{name}")
|
114
|
-
object
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
describe '#tint' do
|
120
|
-
subject { type.tint }
|
121
|
-
|
122
|
-
it { should be_a(Tint) }
|
123
|
-
its(:name) { should eq("type:#{name}") }
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '#encode' do
|
127
|
-
it 'defaults to using the representation service as encoder' do
|
128
|
-
representation = stub(__service__: service)
|
129
|
-
entity = stub
|
130
|
-
service.should_receive(:encode).
|
131
|
-
with('application/json', representation, {}).
|
132
|
-
and_return(entity)
|
133
|
-
type.encode(representation).should equal(entity)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|