almodovar 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -4
- data/lib/almodovar.rb +15 -181
- data/lib/almodovar/digest_auth.rb +4 -0
- data/lib/almodovar/http_accessor.rb +26 -0
- data/lib/almodovar/resource.rb +56 -0
- data/lib/almodovar/resource_collection.rb +31 -0
- data/lib/almodovar/resource_presenter.rb +110 -0
- data/lib/almodovar/resource_presenter/collection.rb +24 -0
- data/lib/almodovar/resource_presenter/link.rb +103 -0
- data/lib/almodovar/single_resource.rb +79 -0
- data/lib/almodovar/to_xml.rb +21 -0
- metadata +47 -91
- data/lib/to_xml.rb +0 -24
- data/vendor/resourceful-0.5.3-patched/MIT-LICENSE +0 -21
- data/vendor/resourceful-0.5.3-patched/Manifest +0 -29
- data/vendor/resourceful-0.5.3-patched/README.markdown +0 -84
- data/vendor/resourceful-0.5.3-patched/Rakefile +0 -71
- data/vendor/resourceful-0.5.3-patched/lib/resourceful.rb +0 -18
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/authentication_manager.rb +0 -108
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/cache_manager.rb +0 -240
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/exceptions.rb +0 -34
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/header.rb +0 -126
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/http_accessor.rb +0 -98
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/memcache_cache_manager.rb +0 -75
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/net_http_adapter.rb +0 -70
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/options_interpreter.rb +0 -78
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/request.rb +0 -230
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/resource.rb +0 -165
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/response.rb +0 -221
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/stubbed_resource_proxy.rb +0 -47
- data/vendor/resourceful-0.5.3-patched/lib/resourceful/util.rb +0 -6
- data/vendor/resourceful-0.5.3-patched/resourceful.gemspec +0 -48
- data/vendor/resourceful-0.5.3-patched/spec/acceptance/authorization_spec.rb +0 -16
- data/vendor/resourceful-0.5.3-patched/spec/acceptance/caching_spec.rb +0 -192
- data/vendor/resourceful-0.5.3-patched/spec/acceptance/header_spec.rb +0 -24
- data/vendor/resourceful-0.5.3-patched/spec/acceptance/redirecting_spec.rb +0 -12
- data/vendor/resourceful-0.5.3-patched/spec/acceptance/resource_spec.rb +0 -84
- data/vendor/resourceful-0.5.3-patched/spec/acceptance_shared_specs.rb +0 -44
- data/vendor/resourceful-0.5.3-patched/spec/old_acceptance_specs.rb +0 -378
- data/vendor/resourceful-0.5.3-patched/spec/simple_sinatra_server.rb +0 -74
- data/vendor/resourceful-0.5.3-patched/spec/simple_sinatra_server_spec.rb +0 -98
- data/vendor/resourceful-0.5.3-patched/spec/spec.opts +0 -3
- data/vendor/resourceful-0.5.3-patched/spec/spec_helper.rb +0 -28
@@ -0,0 +1,24 @@
|
|
1
|
+
module Almodovar
|
2
|
+
|
3
|
+
class ResourcePresenter::Collection
|
4
|
+
|
5
|
+
def initialize(resource_class, resources_args = [])
|
6
|
+
@resource_class = resource_class
|
7
|
+
@resources = resources_args.map { |arg| @resource_class.new(arg) }
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_xml(options = {})
|
11
|
+
@resources.to_xml(options.merge({:root => resource_type.pluralize}))
|
12
|
+
end
|
13
|
+
|
14
|
+
def as_json(options = {})
|
15
|
+
{ 'entries' => @resources.map { |resource| resource.as_json(options) }}
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_type
|
19
|
+
@resource_class.resource_type
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Almodovar
|
2
|
+
|
3
|
+
class ResourcePresenter::Link
|
4
|
+
|
5
|
+
attr_reader :rel, :href, :expand_resource, :expand_args
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
@rel, @href, @expand_resource, @expand_args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_xml(options = {})
|
12
|
+
XmlSerializer.new(self, options.merge(:skip_instruct => true)).to_xml
|
13
|
+
end
|
14
|
+
|
15
|
+
def as_json(options)
|
16
|
+
JsonSerializer.new(self, options).as_json
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource
|
20
|
+
resource_collection? ? resource_collection : single_resource
|
21
|
+
end
|
22
|
+
|
23
|
+
def resource_collection?
|
24
|
+
expand_args.is_a?(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource_collection
|
28
|
+
ResourcePresenter::Collection.new(expand_resource, expand_args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def single_resource
|
32
|
+
expand_resource.new(*[expand_args].compact)
|
33
|
+
end
|
34
|
+
|
35
|
+
def expand_resource?
|
36
|
+
expand_resource.present?
|
37
|
+
end
|
38
|
+
|
39
|
+
class Serializer
|
40
|
+
|
41
|
+
attr_reader :link, :options
|
42
|
+
|
43
|
+
def initialize(link, options)
|
44
|
+
@link = link
|
45
|
+
@options = options
|
46
|
+
end
|
47
|
+
|
48
|
+
def expands?
|
49
|
+
link.expand_resource? &&
|
50
|
+
Array(options[:expand]).include?(link.rel) &&
|
51
|
+
!Array(options[:dont_expand]).include?(link.href)
|
52
|
+
end
|
53
|
+
|
54
|
+
def dont_expand_link!
|
55
|
+
(options[:dont_expand] ||= []) << link.href
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class XmlSerializer < Serializer
|
61
|
+
|
62
|
+
def to_xml
|
63
|
+
builder.link :rel => link.rel, :href => link.href, &expand_block
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def builder
|
69
|
+
options[:builder]
|
70
|
+
end
|
71
|
+
|
72
|
+
def expand_block
|
73
|
+
Proc.new { expand_resource } if expands?
|
74
|
+
end
|
75
|
+
|
76
|
+
def expand_resource
|
77
|
+
dont_expand_link!
|
78
|
+
link.resource.to_xml(options)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
class JsonSerializer < Serializer
|
84
|
+
|
85
|
+
def as_json
|
86
|
+
ActiveSupport::OrderedHash.new.tap do |message|
|
87
|
+
message["#{link.rel}_link"] = link.href
|
88
|
+
message[link.rel] = expand_resource if expands?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def expand_resource
|
95
|
+
dont_expand_link!
|
96
|
+
link.resource.as_json(options)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Almodovar
|
2
|
+
class SingleResource
|
3
|
+
include HttpAccessor
|
4
|
+
|
5
|
+
undef_method :id if instance_methods.include?("id")
|
6
|
+
undef_method :type if instance_methods.include?("type")
|
7
|
+
|
8
|
+
def initialize(url, auth, xml = nil, options = {})
|
9
|
+
@url = url
|
10
|
+
@auth = auth
|
11
|
+
@xml = xml
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def update(attrs = {})
|
16
|
+
raise ArgumentError.new("You must specify one only root element which is the type of resource (e.g. `:project => { :name => 'Wadus' }` instead of just `:name => 'Wadus'`)") if attrs.size > 1
|
17
|
+
root, body = attrs.first
|
18
|
+
response = http.put(@url, body.to_xml(:root => root), :content_type => "application/xml")
|
19
|
+
@xml = Nokogiri::XML.parse(response.body).root
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
http.delete(@url)
|
24
|
+
end
|
25
|
+
|
26
|
+
def url
|
27
|
+
@url ||= xml.at_xpath("./link[@rel='self']").try(:[], "href")
|
28
|
+
end
|
29
|
+
|
30
|
+
delegate :to_xml, :to => :xml
|
31
|
+
alias_method :inspect, :to_xml
|
32
|
+
|
33
|
+
def [](key) # for resources with type "document"
|
34
|
+
return super unless xml.at_xpath("/*[@type='document']")
|
35
|
+
Hash.from_xml(xml.to_xml).values.first[key]
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_to?(meth)
|
39
|
+
super || node(meth).present? || link(meth).present?
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def method_missing(meth, *args, &blk)
|
45
|
+
if node = node(meth)
|
46
|
+
return node['type'] == 'document' ? Resource.from_xml(node.to_xml) : node_text(node)
|
47
|
+
end
|
48
|
+
|
49
|
+
link = link(meth)
|
50
|
+
return Resource.new(link["href"], @auth, link.at_xpath("./*"), *args) if link
|
51
|
+
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
def node(name)
|
56
|
+
xml.at_xpath("./*[name()='#{name}' or name()='#{attribute_name(name)}']")
|
57
|
+
end
|
58
|
+
|
59
|
+
def link(name)
|
60
|
+
xml.at_xpath("./link[@rel='#{name}' or @rel='#{attribute_name(name)}']")
|
61
|
+
end
|
62
|
+
|
63
|
+
def node_text(node)
|
64
|
+
case node['type']
|
65
|
+
when "integer"
|
66
|
+
node.text.to_i
|
67
|
+
when "datetime"
|
68
|
+
Time.parse(node.text)
|
69
|
+
else
|
70
|
+
node.text
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def attribute_name(attribute)
|
75
|
+
attribute.to_s.gsub('_', '-')
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Almodovar
|
2
|
+
module ArrayToXml
|
3
|
+
def to_xml_with_links(options = {})
|
4
|
+
return to_xml_without_links(options) unless options[:convert_links]
|
5
|
+
options[:builder].tag!(:link, :rel => options[:root]) do |xml|
|
6
|
+
to_xml_without_links options.merge(:builder => xml)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Resource
|
12
|
+
def to_xml(options = {})
|
13
|
+
options[:builder].tag!(:link, :rel => options[:root], :href => url)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Array
|
19
|
+
include Almodovar::ArrayToXml
|
20
|
+
alias_method_chain :to_xml, :links
|
21
|
+
end
|
metadata
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
name: almodovar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
hash: 7
|
5
|
-
prerelease:
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 5
|
9
8
|
- 6
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- BeBanjo S.L.
|
@@ -15,27 +15,27 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-10-07 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
name: patron
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
25
|
none: false
|
24
26
|
requirements:
|
25
|
-
- - "
|
27
|
+
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 0
|
30
|
-
|
31
|
-
- 3
|
32
|
-
version: 0.5.3
|
33
|
-
requirement: *id001
|
32
|
+
version: "0"
|
34
33
|
type: :runtime
|
35
|
-
|
36
|
-
prerelease: false
|
34
|
+
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
36
|
+
name: builder
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
@@ -44,28 +44,26 @@ dependencies:
|
|
44
44
|
segments:
|
45
45
|
- 0
|
46
46
|
version: "0"
|
47
|
-
requirement: *id002
|
48
47
|
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
49
50
|
name: nokogiri
|
50
51
|
prerelease: false
|
51
|
-
|
52
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
hash: 3
|
58
58
|
segments:
|
59
|
-
- 2
|
60
|
-
- 3
|
61
59
|
- 0
|
62
|
-
version:
|
63
|
-
requirement: *id003
|
60
|
+
version: "0"
|
64
61
|
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
65
64
|
name: activesupport
|
66
65
|
prerelease: false
|
67
|
-
|
68
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
67
|
none: false
|
70
68
|
requirements:
|
71
69
|
- - ">="
|
@@ -74,28 +72,12 @@ dependencies:
|
|
74
72
|
segments:
|
75
73
|
- 0
|
76
74
|
version: "0"
|
77
|
-
|
78
|
-
|
79
|
-
name: rake
|
80
|
-
prerelease: false
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
81
77
|
- !ruby/object:Gem::Dependency
|
82
|
-
|
83
|
-
none: false
|
84
|
-
requirements:
|
85
|
-
- - ~>
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
hash: 27
|
88
|
-
segments:
|
89
|
-
- 1
|
90
|
-
- 3
|
91
|
-
- 0
|
92
|
-
version: 1.3.0
|
93
|
-
requirement: *id005
|
94
|
-
type: :development
|
95
|
-
name: rspec
|
78
|
+
name: i18n
|
96
79
|
prerelease: false
|
97
|
-
|
98
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
99
81
|
none: false
|
100
82
|
requirements:
|
101
83
|
- - ">="
|
@@ -104,26 +86,22 @@ dependencies:
|
|
104
86
|
segments:
|
105
87
|
- 0
|
106
88
|
version: "0"
|
107
|
-
|
108
|
-
|
109
|
-
name: steak
|
110
|
-
prerelease: false
|
89
|
+
type: :runtime
|
90
|
+
version_requirements: *id005
|
111
91
|
- !ruby/object:Gem::Dependency
|
112
|
-
|
92
|
+
name: yajl-ruby
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
113
95
|
none: false
|
114
96
|
requirements:
|
115
|
-
- -
|
97
|
+
- - ">="
|
116
98
|
- !ruby/object:Gem::Version
|
117
|
-
hash:
|
99
|
+
hash: 3
|
118
100
|
segments:
|
119
|
-
- 1
|
120
|
-
- 3
|
121
101
|
- 0
|
122
|
-
version:
|
123
|
-
|
124
|
-
|
125
|
-
name: webmock
|
126
|
-
prerelease: false
|
102
|
+
version: "0"
|
103
|
+
type: :runtime
|
104
|
+
version_requirements: *id006
|
127
105
|
description:
|
128
106
|
email: ballsbreaking@bebanjo.com
|
129
107
|
executables: []
|
@@ -133,39 +111,17 @@ extensions: []
|
|
133
111
|
extra_rdoc_files:
|
134
112
|
- README.rdoc
|
135
113
|
files:
|
136
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/authentication_manager.rb
|
137
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/cache_manager.rb
|
138
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/exceptions.rb
|
139
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/header.rb
|
140
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/http_accessor.rb
|
141
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/memcache_cache_manager.rb
|
142
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/net_http_adapter.rb
|
143
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/options_interpreter.rb
|
144
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/request.rb
|
145
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/resource.rb
|
146
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/response.rb
|
147
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/stubbed_resource_proxy.rb
|
148
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful/util.rb
|
149
|
-
- vendor/resourceful-0.5.3-patched/lib/resourceful.rb
|
150
|
-
- vendor/resourceful-0.5.3-patched/Manifest
|
151
|
-
- vendor/resourceful-0.5.3-patched/MIT-LICENSE
|
152
|
-
- vendor/resourceful-0.5.3-patched/Rakefile
|
153
|
-
- vendor/resourceful-0.5.3-patched/README.markdown
|
154
|
-
- vendor/resourceful-0.5.3-patched/resourceful.gemspec
|
155
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance/authorization_spec.rb
|
156
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance/caching_spec.rb
|
157
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance/header_spec.rb
|
158
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance/redirecting_spec.rb
|
159
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance/resource_spec.rb
|
160
|
-
- vendor/resourceful-0.5.3-patched/spec/acceptance_shared_specs.rb
|
161
|
-
- vendor/resourceful-0.5.3-patched/spec/old_acceptance_specs.rb
|
162
|
-
- vendor/resourceful-0.5.3-patched/spec/simple_sinatra_server.rb
|
163
|
-
- vendor/resourceful-0.5.3-patched/spec/simple_sinatra_server_spec.rb
|
164
|
-
- vendor/resourceful-0.5.3-patched/spec/spec.opts
|
165
|
-
- vendor/resourceful-0.5.3-patched/spec/spec_helper.rb
|
166
|
-
- lib/almodovar.rb
|
167
|
-
- lib/to_xml.rb
|
168
114
|
- README.rdoc
|
115
|
+
- lib/almodovar/digest_auth.rb
|
116
|
+
- lib/almodovar/http_accessor.rb
|
117
|
+
- lib/almodovar/resource.rb
|
118
|
+
- lib/almodovar/resource_collection.rb
|
119
|
+
- lib/almodovar/resource_presenter/collection.rb
|
120
|
+
- lib/almodovar/resource_presenter/link.rb
|
121
|
+
- lib/almodovar/resource_presenter.rb
|
122
|
+
- lib/almodovar/single_resource.rb
|
123
|
+
- lib/almodovar/to_xml.rb
|
124
|
+
- lib/almodovar.rb
|
169
125
|
has_rdoc: true
|
170
126
|
homepage: http://wiki.github.com/bebanjo/almodovar/
|
171
127
|
licenses: []
|
@@ -197,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
153
|
requirements: []
|
198
154
|
|
199
155
|
rubyforge_project:
|
200
|
-
rubygems_version: 1.
|
156
|
+
rubygems_version: 1.6.2
|
201
157
|
signing_key:
|
202
158
|
specification_version: 3
|
203
159
|
summary: BeBanjo API client
|