purzelrakete-restful 0.2.7 → 0.2.8
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/CHANGES.markdown
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Resource model. Something like a DOM model for the api.
|
3
|
+
#
|
4
|
+
module Restful
|
5
|
+
module ApiModel
|
6
|
+
class Map
|
7
|
+
attr_accessor :values, :name, :type
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
self.name = name
|
11
|
+
self.type = :hash
|
12
|
+
self.values = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def links
|
16
|
+
self.values.select { |attribute| attribute.type == :link }
|
17
|
+
end
|
18
|
+
|
19
|
+
def simple_attributes
|
20
|
+
self.values.select { |attribute| attribute.type == :simple_attribute }
|
21
|
+
end
|
22
|
+
|
23
|
+
def collections
|
24
|
+
self.values.select { |attribute| attribute.type == :collection }
|
25
|
+
end
|
26
|
+
|
27
|
+
# invoke serialization
|
28
|
+
def serialize(type)
|
29
|
+
serializer = Restful::Serializers::Base.serializer(type)
|
30
|
+
serializer.serialize(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
# invoke deserialization
|
34
|
+
def deserialize_from(type)
|
35
|
+
serializer = Restful::Serializers::Base.serializer(type)
|
36
|
+
serializer.deserialize(self)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
data/restful.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "restful"
|
3
|
-
s.version = "0.2.
|
3
|
+
s.version = "0.2.8"
|
4
4
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
5
5
|
s.authors = ["Daniel Bornkessel", "Rany Keddo"]
|
6
6
|
s.date = "2009-08-11"
|
7
7
|
s.email = "M4SSIVE@m4ssive.com"
|
8
8
|
s.extra_rdoc_files = %w{ README.markdown }
|
9
|
-
s.files = %w{ init.rb lib/restful/apimodel/attribute.rb lib/restful/apimodel/collection.rb lib/restful/apimodel/link.rb lib/restful/apimodel/resource.rb lib/restful/converters/active_record.rb lib/restful/rails/action_controller.rb lib/restful/rails/active_record/configuration.rb lib/restful/rails/active_record/metadata_tools.rb lib/restful/rails.rb lib/restful/serializers/atom_like_serializer.rb lib/restful/serializers/base.rb lib/restful/serializers/hash_serializer.rb lib/restful/serializers/json_serializer.rb lib/restful/serializers/params_serializer.rb lib/restful/serializers/xml_serializer.rb lib/restful.rb LICENSE.markdown rails/init.rb Rakefile README.markdown restful.gemspec test/converters/active_record_converter_test.rb test/fixtures/models/person.rb test/fixtures/models/pet.rb test/fixtures/models/wallet.rb test/fixtures/people.json.yaml test/fixtures/people.xml.yaml test/fixtures/pets.xml.yaml test/rails/active_record_metadata_test.rb test/rails/configuration_test.rb test/rails/restful_publish_test.rb test/serializers/atom_serializer_test.rb test/serializers/json_serializer_test.rb test/serializers/params_serializer_test.rb test/serializers/xml_serializer_test.rb test/test_helper.rb TODO.markdown }
|
9
|
+
s.files = %w{ CHANGES.markdown init.rb lib/restful/apimodel/attribute.rb lib/restful/apimodel/collection.rb lib/restful/apimodel/link.rb lib/restful/apimodel/map.rb lib/restful/apimodel/resource.rb lib/restful/converters/active_record.rb lib/restful/rails/action_controller.rb lib/restful/rails/active_record/configuration.rb lib/restful/rails/active_record/metadata_tools.rb lib/restful/rails.rb lib/restful/serializers/atom_like_serializer.rb lib/restful/serializers/base.rb lib/restful/serializers/hash_serializer.rb lib/restful/serializers/json_serializer.rb lib/restful/serializers/params_serializer.rb lib/restful/serializers/xml_serializer.rb lib/restful.rb LICENSE.markdown rails/init.rb Rakefile README.markdown restful.gemspec test/converters/active_record_converter_test.rb test/converters/basic_types_converter_test.rb test/fixtures/models/paginated_collection.rb test/fixtures/models/person.rb test/fixtures/models/pet.rb test/fixtures/models/wallet.rb test/fixtures/people.json.yaml test/fixtures/people.xml.yaml test/fixtures/pets.json.yaml test/fixtures/pets.xml.yaml test/rails/active_record_metadata_test.rb test/rails/configuration_test.rb test/rails/restful_publish_test.rb test/serializers/atom_serializer_test.rb test/serializers/json_serializer_test.rb test/serializers/params_serializer_test.rb test/serializers/xml_serializer_test.rb test/test_helper.rb TODO.markdown }
|
10
10
|
s.has_rdoc = true
|
11
11
|
s.rdoc_options = ["--line-numbers", "--inline-source"]
|
12
12
|
s.homepage = "http://github.com/M4SSIVE/restful"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
context "basic types converter" do
|
4
|
+
teardown { reset_config }
|
5
|
+
|
6
|
+
specify "should raise exception if not all array contents respond to .to_restful" do
|
7
|
+
Person.restful_publish(:name)
|
8
|
+
|
9
|
+
should.raise(TypeError) do
|
10
|
+
[""].to_restful
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "should convert an empty array to a restful collection" do
|
15
|
+
collection = [].to_restful
|
16
|
+
collection.name.should.== "nil-classes"
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "should convert an array to a restful collection" do
|
20
|
+
Person.restful_publish(:name)
|
21
|
+
|
22
|
+
collection = [Person.create(:name => "Joe Bloggs")].to_restful
|
23
|
+
collection.name.should.== "people"
|
24
|
+
collection.value.size.should.== 1
|
25
|
+
collection.value.first.simple_attributes.first.value.should.== "Joe Bloggs"
|
26
|
+
end
|
27
|
+
|
28
|
+
specify "should set total_entries on the restful collection if the array responds to this" do
|
29
|
+
Person.restful_publish(:name)
|
30
|
+
people = PaginatedCollection.new([Person.create(:name => "Joe Bloggs")])
|
31
|
+
people.total_entries = 1001
|
32
|
+
|
33
|
+
collection = people.to_restful
|
34
|
+
collection.total_entries.should.== 1001
|
35
|
+
end
|
36
|
+
|
37
|
+
specify "should be able to convert a hash to a resource map" do
|
38
|
+
Person.restful_publish(:name)
|
39
|
+
resource = { "zeperson" => @person = Person.create(:name => "fuddzle") }.to_restful
|
40
|
+
resource.should.is_a?(Restful::ApiModel::Map)
|
41
|
+
|
42
|
+
attrs = resource.simple_attributes
|
43
|
+
attrs.size.should.== 1
|
44
|
+
attrs.first.name.should.== "zeperson"
|
45
|
+
|
46
|
+
attrs.first.value.values.first.value.== "fuddzle"
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
pets_array:
|
2
|
+
|
|
3
|
+
[
|
4
|
+
{
|
5
|
+
"restful_url": "http://example.com:3000/pets/<%= @person.pets.first.to_param %>",
|
6
|
+
"name": "mietze"
|
7
|
+
}
|
8
|
+
]
|
9
|
+
|
10
|
+
pets_array_with_total_entries:
|
11
|
+
|
|
12
|
+
{
|
13
|
+
"total_entries": 1001,
|
14
|
+
"pets": [
|
15
|
+
{
|
16
|
+
"restful_url": "http://example.com:3000/pets/<%= @person.pets.first.to_param %>",
|
17
|
+
"name": "mietze"
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purzelrakete-restful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bornkessel
|
@@ -23,10 +23,12 @@ extensions: []
|
|
23
23
|
extra_rdoc_files:
|
24
24
|
- README.markdown
|
25
25
|
files:
|
26
|
+
- CHANGES.markdown
|
26
27
|
- init.rb
|
27
28
|
- lib/restful/apimodel/attribute.rb
|
28
29
|
- lib/restful/apimodel/collection.rb
|
29
30
|
- lib/restful/apimodel/link.rb
|
31
|
+
- lib/restful/apimodel/map.rb
|
30
32
|
- lib/restful/apimodel/resource.rb
|
31
33
|
- lib/restful/converters/active_record.rb
|
32
34
|
- lib/restful/rails/action_controller.rb
|
@@ -46,11 +48,14 @@ files:
|
|
46
48
|
- README.markdown
|
47
49
|
- restful.gemspec
|
48
50
|
- test/converters/active_record_converter_test.rb
|
51
|
+
- test/converters/basic_types_converter_test.rb
|
52
|
+
- test/fixtures/models/paginated_collection.rb
|
49
53
|
- test/fixtures/models/person.rb
|
50
54
|
- test/fixtures/models/pet.rb
|
51
55
|
- test/fixtures/models/wallet.rb
|
52
56
|
- test/fixtures/people.json.yaml
|
53
57
|
- test/fixtures/people.xml.yaml
|
58
|
+
- test/fixtures/pets.json.yaml
|
54
59
|
- test/fixtures/pets.xml.yaml
|
55
60
|
- test/rails/active_record_metadata_test.rb
|
56
61
|
- test/rails/configuration_test.rb
|