ddy_remote_resource 0.4.11 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Guardfile +3 -0
- data/lib/remote_resource.rb +77 -34
- data/lib/remote_resource/base.rb +20 -8
- data/lib/remote_resource/connection.rb +26 -5
- data/lib/remote_resource/connection_options.rb +5 -3
- data/lib/remote_resource/querying/finder_methods.rb +3 -3
- data/lib/remote_resource/querying/persistence_methods.rb +17 -12
- data/lib/remote_resource/request.rb +96 -62
- data/lib/remote_resource/response.rb +5 -1
- data/lib/remote_resource/rest.rb +13 -17
- data/lib/remote_resource/url_naming.rb +4 -10
- data/lib/remote_resource/url_naming_determination.rb +1 -3
- data/lib/remote_resource/util.rb +64 -0
- data/lib/remote_resource/version.rb +1 -1
- data/remote_resource.gemspec +2 -2
- data/spec/fixtures/text_file.txt +1 -0
- data/spec/integration/all_spec.rb +166 -0
- data/spec/integration/collection_prefix_spec.rb +99 -0
- data/spec/integration/create_spec.rb +181 -0
- data/spec/integration/destroy_spec.rb +252 -0
- data/spec/integration/find_by_spec.rb +168 -0
- data/spec/integration/find_spec.rb +139 -0
- data/spec/integration/headers_spec.rb +222 -0
- data/spec/integration/naming_spec.rb +138 -0
- data/spec/integration/save_spec.rb +320 -0
- data/spec/integration/update_attributes_spec.rb +221 -0
- data/spec/integration/where_spec.rb +152 -0
- data/spec/lib/extensions/ethon/easy/queryable_spec.rb +4 -4
- data/spec/lib/remote_resource/base_spec.rb +54 -110
- data/spec/lib/remote_resource/builder_spec.rb +1 -1
- data/spec/lib/remote_resource/collection_spec.rb +1 -1
- data/spec/lib/remote_resource/connection_options_spec.rb +20 -17
- data/spec/lib/remote_resource/connection_spec.rb +36 -27
- data/spec/lib/remote_resource/querying/finder_methods_spec.rb +199 -72
- data/spec/lib/remote_resource/querying/persistence_methods_spec.rb +228 -220
- data/spec/lib/remote_resource/request_spec.rb +313 -342
- data/spec/lib/remote_resource/response_spec.rb +9 -3
- data/spec/lib/remote_resource/rest_spec.rb +11 -11
- data/spec/lib/remote_resource/url_naming_determination_spec.rb +1 -1
- data/spec/lib/remote_resource/url_naming_spec.rb +7 -22
- data/spec/lib/remote_resource/util_spec.rb +56 -0
- data/spec/lib/remote_resource/version_spec.rb +2 -3
- data/spec/spec_helper.rb +37 -0
- metadata +33 -22
- data/lib/remote_resource/http_errors.rb +0 -33
- data/lib/remote_resource/response_handeling.rb +0 -48
@@ -1,48 +0,0 @@
|
|
1
|
-
module RemoteResource
|
2
|
-
class ResponseHandeling
|
3
|
-
|
4
|
-
attr_reader :resource, :response, :connection_options
|
5
|
-
|
6
|
-
def initialize(resource, response, connection_options = {})
|
7
|
-
@resource = resource
|
8
|
-
@response = response
|
9
|
-
@connection_options = connection_options
|
10
|
-
end
|
11
|
-
|
12
|
-
def perform
|
13
|
-
if response.success?
|
14
|
-
if resource.respond_to? :new
|
15
|
-
resource.build_resource_from_response response
|
16
|
-
else
|
17
|
-
resource
|
18
|
-
end
|
19
|
-
elsif errors?
|
20
|
-
if resource.respond_to? :new
|
21
|
-
#
|
22
|
-
else
|
23
|
-
# assign response
|
24
|
-
resource.assign_errors response.parsed_response_body, root_element
|
25
|
-
end
|
26
|
-
else
|
27
|
-
# nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def errors?
|
32
|
-
parsed_response_body = response.parsed_response_body
|
33
|
-
|
34
|
-
if parsed_response_body
|
35
|
-
parsed_response_body.has_key?("errors") || parsed_response_body.fetch(root_element.to_s, nil).has_key?("errors")
|
36
|
-
else
|
37
|
-
false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def root_element
|
44
|
-
connection_options[:root_element].presence || resource.connection_options.root_element.presence
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|