rest_model 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/Guardfile +7 -0
- data/README.md +237 -0
- data/Rakefile +2 -0
- data/examples/all.rb +12 -0
- data/examples/embeds_many/invisible.rb +16 -0
- data/examples/embeds_many/simple.rb +13 -0
- data/examples/embeds_many/with_array.rb +10 -0
- data/examples/embeds_many/with_class_name.rb +13 -0
- data/examples/embeds_many/with_fields.rb +9 -0
- data/examples/embeds_many/with_if.rb +16 -0
- data/examples/embeds_many/with_nil_value.rb +12 -0
- data/examples/embeds_many/with_start_key.rb +13 -0
- data/examples/embeds_one/flattened.rb +12 -0
- data/examples/embeds_one/simple.rb +12 -0
- data/examples/embeds_one/with_class_name.rb +12 -0
- data/examples/embeds_one/with_if.rb +16 -0
- data/examples/embeds_one/with_start_key.rb +12 -0
- data/examples/has_many/simple.rb +28 -0
- data/examples/helper.rb +9 -0
- data/examples/initialize/embeds_many.rb +25 -0
- data/examples/initialize/embeds_many_array.rb +9 -0
- data/examples/initialize/embeds_one.rb +19 -0
- data/examples/initialize/simple.rb +8 -0
- data/examples/properties/array_serialization.rb +8 -0
- data/examples/properties/collections.rb +11 -0
- data/examples/properties/simple.rb +8 -0
- data/examples/properties/with_field.rb +8 -0
- data/examples/properties/with_field_path.rb +8 -0
- data/examples/properties/with_id.rb +8 -0
- data/examples/properties/with_if.rb +21 -0
- data/examples/properties/with_key_converter.rb +18 -0
- data/examples/properties/with_two_key_converters.rb +27 -0
- data/examples/properties/with_values.rb +10 -0
- data/examples/summarization/simple.rb +21 -0
- data/examples/to_input/embeds_many.rb +25 -0
- data/examples/to_input/embeds_many_without_key.rb +31 -0
- data/examples/to_input/embeds_one.rb +13 -0
- data/examples/to_input/embeds_one_without_key.rb +23 -0
- data/examples/to_input/flattened.rb +12 -0
- data/examples/to_input/serializables.rb +19 -0
- data/examples/to_input/simple.rb +8 -0
- data/examples/to_input/with_field.rb +8 -0
- data/examples/to_input/with_field_path.rb +8 -0
- data/examples/to_input/with_fields.rb +8 -0
- data/examples/to_input/without_key.rb +11 -0
- data/examples/to_input/without_nil.rb +11 -0
- data/lib/rest_model/configuration.rb +45 -0
- data/lib/rest_model/key/association.rb +42 -0
- data/lib/rest_model/key/builder.rb +30 -0
- data/lib/rest_model/key/embeddable/builder.rb +19 -0
- data/lib/rest_model/key/embeddable/response.rb +25 -0
- data/lib/rest_model/key/embeddable/retriever.rb +20 -0
- data/lib/rest_model/key/embeddable/sender.rb +41 -0
- data/lib/rest_model/key/embeddable.rb +29 -0
- data/lib/rest_model/key/href/response.rb +10 -0
- data/lib/rest_model/key/href.rb +10 -0
- data/lib/rest_model/key/property/builder.rb +27 -0
- data/lib/rest_model/key/property/response.rb +9 -0
- data/lib/rest_model/key/property/retriever.rb +24 -0
- data/lib/rest_model/key/property/sender.rb +41 -0
- data/lib/rest_model/key/property.rb +22 -0
- data/lib/rest_model/key/relation/builder.rb +24 -0
- data/lib/rest_model/key/relation/response.rb +38 -0
- data/lib/rest_model/key/relation.rb +23 -0
- data/lib/rest_model/key.rb +44 -0
- data/lib/rest_model/response.rb +42 -0
- data/lib/rest_model/serialization/boolean.rb +48 -0
- data/lib/rest_model/serialization/date.rb +19 -0
- data/lib/rest_model/serialization/enumerable.rb +15 -0
- data/lib/rest_model/serialization/float.rb +17 -0
- data/lib/rest_model/serialization/integer.rb +17 -0
- data/lib/rest_model/serialization/string.rb +13 -0
- data/lib/rest_model/source/path.rb +25 -0
- data/lib/rest_model/source/retriever.rb +48 -0
- data/lib/rest_model/source/sender.rb +38 -0
- data/lib/rest_model/version.rb +3 -0
- data/lib/rest_model.rb +101 -0
- data/rest_model.gemspec +26 -0
- data/spec/.DS_Store +0 -0
- data/spec/integration/embeds_many_spec.rb +57 -0
- data/spec/integration/embeds_one_spec.rb +41 -0
- data/spec/integration/has_many_spec.rb +27 -0
- data/spec/integration/property_spec.rb +69 -0
- data/spec/integration/summarization_spec.rb +12 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/examples.rb +29 -0
- data/spec/support/out.rb +17 -0
- data/spec/support/shared_examples.rb +20 -0
- data/spec/unit/configuration_spec.rb +24 -0
- data/spec/unit/key/association_spec.rb +69 -0
- data/spec/unit/key/embeddable/builder_spec.rb +26 -0
- data/spec/unit/key/embeddable/response_spec.rb +55 -0
- data/spec/unit/key/embeddable/retriever_spec.rb +38 -0
- data/spec/unit/key/embeddable_spec.rb +7 -0
- data/spec/unit/key/property/builder_spec.rb +154 -0
- data/spec/unit/key/property/response_spec.rb +22 -0
- data/spec/unit/key/property/retriever_spec.rb +31 -0
- data/spec/unit/key/property_spec.rb +39 -0
- data/spec/unit/key/relation/builder_spec.rb +53 -0
- data/spec/unit/key/relation/response_spec.rb +105 -0
- data/spec/unit/key/relation_spec.rb +71 -0
- data/spec/unit/key_spec.rb +101 -0
- data/spec/unit/response_spec.rb +44 -0
- data/spec/unit/rest_model_spec.rb +46 -0
- data/spec/unit/serialization/boolean_spec.rb +25 -0
- data/spec/unit/serialization/date_spec.rb +13 -0
- data/spec/unit/serialization/float_spec.rb +13 -0
- data/spec/unit/serialization/integer_spec.rb +13 -0
- data/spec/unit/serialization/string_spec.rb +11 -0
- data/spec/unit/source/path_spec.rb +62 -0
- data/spec/unit/source/retriever_spec.rb +85 -0
- metadata +260 -0
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
# RestModel
|
2
|
+
|
3
|
+
**Map from one or more input hashes** to instances of your model classes.
|
4
|
+
|
5
|
+
**Map to restful responses** from these model instances. (Some hypermedia magic happens here).
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Input hash to model
|
10
|
+
|
11
|
+
Given you have:
|
12
|
+
|
13
|
+
input = {
|
14
|
+
"result" => [
|
15
|
+
{
|
16
|
+
"id" => 1938713897398,
|
17
|
+
"login" => "jsmith180",
|
18
|
+
"username" => "John Smith",
|
19
|
+
"personal_info" => {
|
20
|
+
"birth_date" => "1999-02-10",
|
21
|
+
"registered_date" => "2015-04-05"
|
22
|
+
}
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"id" => 92171987391873,
|
26
|
+
"login" => "john_appleseed",
|
27
|
+
"username" => "John Appleseed",
|
28
|
+
"personal_info" => {
|
29
|
+
"birth_date" => "1999-02-10",
|
30
|
+
"registered_date" => "2015-04-05"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
And you want to transform this input in some instances of a `class User; attr_accessor :id, :login, :name, :birth; end`
|
37
|
+
|
38
|
+
With RestModel you can parse the input to instances of `User`:
|
39
|
+
|
40
|
+
users = User.parse(input, :result) # starts looking input hash from 'result' key
|
41
|
+
|
42
|
+
Just define your `User` class like this:
|
43
|
+
|
44
|
+
class User < RestModel
|
45
|
+
id
|
46
|
+
property :login
|
47
|
+
property :name, field: :username # input hash key is different from resource key
|
48
|
+
property :birth, field: 'personal_info/birth_date' # digg hash path defined by '/', the last being the key
|
49
|
+
end
|
50
|
+
|
51
|
+
### Model instances array to restful response hash
|
52
|
+
|
53
|
+
User.resources(users)
|
54
|
+
=>
|
55
|
+
|
56
|
+
{
|
57
|
+
entries: [
|
58
|
+
{
|
59
|
+
id: 1938713897398,
|
60
|
+
login: "jsmith180",
|
61
|
+
name: "John Smith",
|
62
|
+
birth: "1999-02-10",
|
63
|
+
href: "http://app/api/users/1938713897398"
|
64
|
+
},
|
65
|
+
{
|
66
|
+
id: 92171987391873,
|
67
|
+
login: "john_appleseed",
|
68
|
+
name: "John Appleseed",
|
69
|
+
birth: "1999-02-10",
|
70
|
+
href: "http://app/api/users/92171987391873"
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
|
75
|
+
### Model instance to restful response hash
|
76
|
+
|
77
|
+
user.resource
|
78
|
+
=>
|
79
|
+
|
80
|
+
{
|
81
|
+
id: 1938713897398,
|
82
|
+
login: "jsmith180",
|
83
|
+
name: "John Smith",
|
84
|
+
birth: "1999-02-10",
|
85
|
+
href: "http://app/api/users/1938713897398"
|
86
|
+
}
|
87
|
+
|
88
|
+
## Embedding other resources
|
89
|
+
|
90
|
+
### [embeds_one](https://github.com/rodrigues/rest_client/tree/master/examples/embeds_one)
|
91
|
+
|
92
|
+
class Customer < RestModel
|
93
|
+
id field: 'cust_id'
|
94
|
+
embeds_one :address
|
95
|
+
end
|
96
|
+
|
97
|
+
class Address < RestModel
|
98
|
+
property :street,
|
99
|
+
property :number, field: 'n'
|
100
|
+
properties :city, :state, :country
|
101
|
+
end
|
102
|
+
|
103
|
+
{
|
104
|
+
id: 1938713897398,
|
105
|
+
address: {
|
106
|
+
street: 'rest_client st.',
|
107
|
+
number: '39',
|
108
|
+
city: 'hashland',
|
109
|
+
state: 'std',
|
110
|
+
country: 'ruby'
|
111
|
+
},
|
112
|
+
href: "http://app/api/users/1938713897398"
|
113
|
+
}
|
114
|
+
|
115
|
+
### [embeds_many](https://github.com/rodrigues/rest_client/tree/master/examples/embeds_many)
|
116
|
+
|
117
|
+
class OrderItems < RestModel
|
118
|
+
property :item_id, id: true # default serialization: String
|
119
|
+
property :quantity, type: Integer
|
120
|
+
property :unit_price, type: Float
|
121
|
+
property :amount, type: Float
|
122
|
+
end
|
123
|
+
|
124
|
+
class Order < RestModel
|
125
|
+
id
|
126
|
+
embeds_many :items, class: OrderItems
|
127
|
+
end
|
128
|
+
|
129
|
+
{
|
130
|
+
id: 739819813719387,
|
131
|
+
items: [
|
132
|
+
{
|
133
|
+
item_id: 1738917139871,
|
134
|
+
quantity: 18,
|
135
|
+
unit_price: 0.2,
|
136
|
+
amount: 3.6
|
137
|
+
},
|
138
|
+
{
|
139
|
+
item_id: 3987187398782,
|
140
|
+
quantity: 1,
|
141
|
+
unit_price: 39.9,
|
142
|
+
amount: 39.9
|
143
|
+
}
|
144
|
+
]
|
145
|
+
}
|
146
|
+
|
147
|
+
## Relations
|
148
|
+
|
149
|
+
### has_one
|
150
|
+
### has_many
|
151
|
+
### belongs_to
|
152
|
+
|
153
|
+
class User < RestModel
|
154
|
+
id
|
155
|
+
property :login
|
156
|
+
has_one :avatar
|
157
|
+
has_many :achievements
|
158
|
+
belongs_to :guilda
|
159
|
+
end
|
160
|
+
|
161
|
+
{
|
162
|
+
id: 19837139879,
|
163
|
+
login: 'jsmith180',
|
164
|
+
link: [
|
165
|
+
{
|
166
|
+
rel: 'avatar',
|
167
|
+
href: 'http://app/api/users/19837139879/avatar'
|
168
|
+
},
|
169
|
+
{
|
170
|
+
rel: 'achievements',
|
171
|
+
href: 'http://app/api/users/19837139879/achievements'
|
172
|
+
},
|
173
|
+
{
|
174
|
+
rel: 'guilda',
|
175
|
+
href: 'http://app/api/users/19837139879/guilda
|
176
|
+
}
|
177
|
+
]
|
178
|
+
}
|
179
|
+
|
180
|
+
### embedding relations
|
181
|
+
|
182
|
+
If you want your api to handle `http://app/api/users/19371897318937?include[]=avatar&include[]=guilda`
|
183
|
+
|
184
|
+
user = User.parse(input, include: [avatar_input, guilda_input]).first
|
185
|
+
|
186
|
+
{
|
187
|
+
id: 19837139879,
|
188
|
+
login: 'jsmith180',
|
189
|
+
avatar: {
|
190
|
+
name: 'K1ll3r',
|
191
|
+
specie: 'WTF'
|
192
|
+
},
|
193
|
+
guilda: {
|
194
|
+
name: 'K1ll3rs'
|
195
|
+
},
|
196
|
+
link: [
|
197
|
+
{
|
198
|
+
rel: 'achievements',
|
199
|
+
href: 'http://app/api/users/19837139879/achievements'
|
200
|
+
}
|
201
|
+
]
|
202
|
+
}
|
203
|
+
|
204
|
+
### [See more examples here](https://github.com/rodrigues/rest_client/tree/master/examples).
|
205
|
+
|
206
|
+
## Installation
|
207
|
+
|
208
|
+
gem install rest_model
|
209
|
+
|
210
|
+
## Maintainers
|
211
|
+
|
212
|
+
* [Victor Rodrigues](http://github.com/rodrigues)
|
213
|
+
* [Vinicius Higa](http://github.com/viniciushiga)
|
214
|
+
* [William "Kina"](http://github.com/kina)
|
215
|
+
|
216
|
+
## License
|
217
|
+
|
218
|
+
(The MIT License)
|
219
|
+
|
220
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
221
|
+
a copy of this software and associated documentation files (the
|
222
|
+
'Software'), to deal in the Software without restriction, including
|
223
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
224
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
225
|
+
permit persons to whom the Software is furnished to do so, subject to
|
226
|
+
the following conditions:
|
227
|
+
|
228
|
+
The above copyright notice and this permission notice shall be
|
229
|
+
included in all copies or substantial portions of the Software.
|
230
|
+
|
231
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
232
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
233
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
234
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
235
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
236
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
237
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/examples/all.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.push 'examples'; require 'helper'
|
4
|
+
|
5
|
+
Dir["examples/*/**.rb"].each do |file|
|
6
|
+
[:Root, :Item, :Customer, :Entry, :Service].each do |klass|
|
7
|
+
Object.send(:remove_const, klass) if Object.const_defined? klass
|
8
|
+
end
|
9
|
+
|
10
|
+
puts "\n\nexample file: #{file}\n\n"
|
11
|
+
load file
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.push 'examples'; require 'helper'
|
4
|
+
|
5
|
+
class Root < RestModel
|
6
|
+
property :key, id: true
|
7
|
+
property :locale, visible: false
|
8
|
+
embeds_many :names, class_name: 'Hash', visible: false
|
9
|
+
property :name, values: proc {names[locale]}
|
10
|
+
end
|
11
|
+
|
12
|
+
names = {'en' => 'Woot', 'pt-BR' => 'Úia', 'es' => 'Me gusta'}
|
13
|
+
|
14
|
+
@root = Root.from_source(locale: 'pt-BR', key: 19190839, names: names).first
|
15
|
+
|
16
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Entry < RestModel
|
4
|
+
property :id, type: Integer
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < RestModel
|
8
|
+
embeds_many :items, class_name: :entry
|
9
|
+
end
|
10
|
+
|
11
|
+
@root = Root.parse({items: [{id: 2000}]}).first
|
12
|
+
|
13
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Item < RestModel
|
4
|
+
property :id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < RestModel
|
8
|
+
property :id
|
9
|
+
embeds_many :items, if: proc {id == "10"}
|
10
|
+
end
|
11
|
+
|
12
|
+
@root_with_items = Root.parse({id: 10, items: [{id: 2000}]}).first
|
13
|
+
inspect_rest_model(@root_with_items)
|
14
|
+
|
15
|
+
@root_without_items = Root.parse({id: 1, items: [{id: 2000}]}).first
|
16
|
+
inspect_rest_model(@root_without_items)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Item < RestModel
|
4
|
+
property :id, field: :item_id
|
5
|
+
end
|
6
|
+
|
7
|
+
class Root < RestModel
|
8
|
+
embeds_many :items, start_key: 'detalhe.itens'
|
9
|
+
end
|
10
|
+
|
11
|
+
@root = Root.parse({"detalhe" => {"itens" => [{item_id: 2000}]}}).first
|
12
|
+
|
13
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Root < RestModel
|
4
|
+
property :id
|
5
|
+
embeds_one :item, if: proc {id == "1"}
|
6
|
+
end
|
7
|
+
|
8
|
+
class Item < RestModel
|
9
|
+
property :id
|
10
|
+
end
|
11
|
+
|
12
|
+
@root_with_item = Root.parse({id: 1, item: {id: 2000}}).first
|
13
|
+
inspect_rest_model(@root_with_item)
|
14
|
+
|
15
|
+
@root_without_item = Root.parse({id: 100, item: {id: 2000}}).first
|
16
|
+
inspect_rest_model(@root_without_item)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Root < RestModel
|
4
|
+
embeds_one :item, start_key: 'ugly_nesting_key'
|
5
|
+
end
|
6
|
+
|
7
|
+
class Item < RestModel
|
8
|
+
property :id
|
9
|
+
end
|
10
|
+
|
11
|
+
@root = Root.parse({'ugly_nesting_key' => {id: 2000}}).first
|
12
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Service < RestModel
|
4
|
+
property :name
|
5
|
+
belongs_to :customer
|
6
|
+
end
|
7
|
+
|
8
|
+
class Billing < RestModel
|
9
|
+
property :login
|
10
|
+
belongs_to :customer
|
11
|
+
end
|
12
|
+
|
13
|
+
class Developer < RestModel
|
14
|
+
property :login
|
15
|
+
belongs_to :customer
|
16
|
+
end
|
17
|
+
|
18
|
+
class Customer < RestModel
|
19
|
+
id field: :customer_id, type: Integer
|
20
|
+
property :login
|
21
|
+
has_many :services
|
22
|
+
has_one :billing
|
23
|
+
has_one :devops, class_name: :developer
|
24
|
+
end
|
25
|
+
|
26
|
+
@root = Customer.parse({customer_id: 123, login: 'jackiechan2010'}).first
|
27
|
+
|
28
|
+
inspect_rest_model(@root)
|
data/examples/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Customer < RestModel
|
4
|
+
property :name
|
5
|
+
embeds_many :phones
|
6
|
+
end
|
7
|
+
|
8
|
+
class Phone < RestModel
|
9
|
+
properties :number, :extension
|
10
|
+
end
|
11
|
+
|
12
|
+
@root = Customer.new({
|
13
|
+
name: "Jackie Chan",
|
14
|
+
phones: [
|
15
|
+
{
|
16
|
+
number: "2980319083",
|
17
|
+
extension: "1398"
|
18
|
+
},
|
19
|
+
{
|
20
|
+
number: "2979139332",
|
21
|
+
extension: "1011"
|
22
|
+
}
|
23
|
+
]})
|
24
|
+
|
25
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Customer < RestModel
|
4
|
+
property :name
|
5
|
+
embeds_one :address
|
6
|
+
end
|
7
|
+
|
8
|
+
class Address < RestModel
|
9
|
+
properties :street, :number
|
10
|
+
end
|
11
|
+
|
12
|
+
@root = Customer.new({
|
13
|
+
name: "Jackie Chan",
|
14
|
+
address: {
|
15
|
+
street: "Aurora St",
|
16
|
+
number: 666
|
17
|
+
}})
|
18
|
+
|
19
|
+
inspect_rest_model(@root)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
class Customer < RestModel
|
4
|
+
property :login
|
5
|
+
property :password
|
6
|
+
property :description, if: proc {password == "abc"}
|
7
|
+
end
|
8
|
+
|
9
|
+
@root_with_description = Customer.parse({
|
10
|
+
login: 2000,
|
11
|
+
password: "abc",
|
12
|
+
description: "description"}).first
|
13
|
+
|
14
|
+
inspect_rest_model(@root_with_description)
|
15
|
+
|
16
|
+
@root_without_description = Customer.parse({
|
17
|
+
login: 2000,
|
18
|
+
password: "abcd",
|
19
|
+
description: "some text II"}).first
|
20
|
+
|
21
|
+
inspect_rest_model(@root_without_description)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.push 'examples'; require 'helper'
|
2
|
+
|
3
|
+
module Upcasing
|
4
|
+
def self.call(keys)
|
5
|
+
keys.map {|key| key.to_s.upcase}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RestModel::Configuration.configure do |c|
|
10
|
+
c.convert_input_keys = Upcasing
|
11
|
+
end
|
12
|
+
|
13
|
+
class Customer < RestModel
|
14
|
+
property :login
|
15
|
+
end
|
16
|
+
|
17
|
+
@root = Customer.parse({"LOGIN" => 'jackiechan2010'}).first
|
18
|
+
inspect_rest_model(@root)
|