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 CHANGED
@@ -174,7 +174,7 @@ Or install it yourself as:
174
174
  def self.find(id)
175
175
  http_get "/users/#{id}.json" do |response|
176
176
  new JSON.parse(response.body)
177
- emd
177
+ end
178
178
  end
179
179
 
180
180
  private
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'
@@ -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
- response = http.get(path, data)
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
- assign_attributes JSON.parse(response.body) if response.body
56
+ save_success(response)
56
57
  else
57
- if response.code.to_i == 422 #:unprocessable_entity
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
@@ -1,3 +1,3 @@
1
1
  module CleanModel
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
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.3
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-09-25 00:00:00.000000000 Z
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: &26200020 !ruby/object:Gem::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: *26200020
24
+ version_requirements: *25155312
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activemodel
27
- requirement: &26162892 !ruby/object:Gem::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: *26162892
35
+ version_requirements: *25065840
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: web_client
38
- requirement: &26145552 !ruby/object:Gem::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: '0'
43
+ version: 0.0.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *26145552
46
+ version_requirements: *25068576
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &26039160 !ruby/object:Gem::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: *26039160
57
+ version_requirements: *25069740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &25913220 !ruby/object:Gem::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: *25913220
68
+ version_requirements: *25044888
69
69
  description: Extensions for ActiveModel to implement multiple types of models
70
70
  email:
71
71
  - gabynaiman@gmail.com