clean_model 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/clean_model.gemspec +1 -1
- data/lib/clean_model/remote.rb +21 -10
- data/lib/clean_model/version.rb +1 -1
- metadata +14 -14
data/README.md
CHANGED
data/clean_model.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency 'activesupport', '>= 3.0.0'
|
20
20
|
s.add_dependency 'activemodel', '>= 3.0.0'
|
21
|
-
s.add_dependency 'web_client'
|
21
|
+
s.add_dependency 'web_client', '0.0.3'
|
22
22
|
|
23
23
|
s.add_development_dependency 'rspec'
|
24
24
|
s.add_development_dependency 'webmock'
|
data/lib/clean_model/remote.rb
CHANGED
@@ -17,9 +17,10 @@ module CleanModel
|
|
17
17
|
WebClient::Base.new(connection)
|
18
18
|
end
|
19
19
|
|
20
|
-
def http_get(path, data={})
|
20
|
+
def http_get(path, data=nil, headers={})
|
21
21
|
begin
|
22
|
-
|
22
|
+
headers[:content_type] ||= 'application/json'
|
23
|
+
response = http.get(path, data, headers)
|
23
24
|
if response.is_a?(Net::HTTPSuccess)
|
24
25
|
block_given? ? yield(response) : response
|
25
26
|
else
|
@@ -52,15 +53,9 @@ module CleanModel
|
|
52
53
|
begin
|
53
54
|
response = new_record? ? create : update
|
54
55
|
if response.is_a?(Net::HTTPSuccess)
|
55
|
-
|
56
|
+
save_success(response)
|
56
57
|
else
|
57
|
-
|
58
|
-
JSON.parse(response.body).each do |attribute, messages|
|
59
|
-
messages.each { |m| errors[attribute.to_sym] << m }
|
60
|
-
end
|
61
|
-
else
|
62
|
-
errors[:base] = response.content_type == 'application/json' ? response.body : "#{response.code} - Unexpected error"
|
63
|
-
end
|
58
|
+
save_fail(response)
|
64
59
|
end
|
65
60
|
rescue WebClient::Error => ex
|
66
61
|
errors[:base] = ex.message
|
@@ -81,6 +76,22 @@ module CleanModel
|
|
81
76
|
errors.empty?
|
82
77
|
end
|
83
78
|
|
79
|
+
private
|
80
|
+
|
81
|
+
def save_success(response)
|
82
|
+
assign_attributes JSON.parse(response.body) if response.body
|
83
|
+
end
|
84
|
+
|
85
|
+
def save_fail(response)
|
86
|
+
if response.code.to_i == 422 #:unprocessable_entity
|
87
|
+
JSON.parse(response.body).each do |attribute, messages|
|
88
|
+
messages.each { |m| errors[attribute.to_sym] << m }
|
89
|
+
end
|
90
|
+
else
|
91
|
+
errors[:base] = response.content_type == 'application/json' ? response.body : "#{response.code} - Unexpected error"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
84
95
|
end
|
85
96
|
|
86
97
|
end
|
data/lib/clean_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clean_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &25155312 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25155312
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &25065840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,21 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *25065840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: web_client
|
38
|
-
requirement: &
|
38
|
+
requirement: &25068576 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - =
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 0.0.3
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *25068576
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &25069740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *25069740
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: webmock
|
60
|
-
requirement: &
|
60
|
+
requirement: &25044888 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *25044888
|
69
69
|
description: Extensions for ActiveModel to implement multiple types of models
|
70
70
|
email:
|
71
71
|
- gabynaiman@gmail.com
|