odata 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bcb409923afacd4cbe61f5529778a48095d8bfa
4
- data.tar.gz: 1e9717542f01cebe59d94f7cc96eaecc41105a5f
3
+ metadata.gz: 8c8d4272413289a30d35a4b09f817f3d7686c3dc
4
+ data.tar.gz: 0d07830dbda9b044c740ec0cd3d879cbe7844276
5
5
  SHA512:
6
- metadata.gz: 6bdf2a6ff80565a48c9c013d4bfacdd6d2051f7917c4cf2bbd708aa553fb2e2179e0d8943f53691e230c8fcb0e030bc6d6426a93ff4851e2e292060ee401cb98
7
- data.tar.gz: 89ffb30a578f9dc4e66c3181f4f30598a0fca8499e101420cd80c1f5722c6eb0b57698a2e030ff00b8ad51257f562aa05c9af3d16cc5a82a3fd05fbb24006025
6
+ metadata.gz: 7e3308fd2fdc7ad523dc2b6f64015cee6467d8d00cc26dbf759b23c0aa68b28c918b87846944cb084a2b4bc09368051a1c2e1d24093027b3d0972068b2a97ca4
7
+ data.tar.gz: 7177e7a0995e6323cf2e0a929b8a3e9547552f8c8cf01c1e6d94eb5b4b718a3c98598b8dd1bae34518d4ecca2e60904862aa1a6eaccf118e4b63482b198794ba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.6.7
4
+
5
+ * Changed how commit failures are handled to use logging instead of raising an
6
+ error.
7
+ * Added errors array to OData::Entity.
8
+
3
9
  ## 0.6.6
4
10
 
5
11
  * Updated OData::EntitySet#setup_entity_post_request to properly format primary
data/lib/odata/entity.rb CHANGED
@@ -13,6 +13,8 @@ module OData
13
13
  attr_reader :service_name
14
14
  # Links to other OData entitites
15
15
  attr_reader :links
16
+ # List of errors on entity
17
+ attr_reader :errors
16
18
 
17
19
  # Initializes a bare Entity
18
20
  # @param options [Hash]
@@ -21,6 +23,7 @@ module OData
21
23
  @namespace = options[:namespace]
22
24
  @service_name = options[:service_name]
23
25
  @links = options[:links] || {}
26
+ @errors = []
24
27
  end
25
28
 
26
29
  # Returns name of Entity from Service specified type.
@@ -124,6 +127,10 @@ module OData
124
127
  self[primary_key].nil?
125
128
  end
126
129
 
130
+ def any_errors?
131
+ !errors.empty?
132
+ end
133
+
127
134
  private
128
135
 
129
136
  def instantiate_property(property_name, value)
@@ -105,9 +105,15 @@ module OData
105
105
  url_chunk, options = setup_entity_post_request(entity)
106
106
  result = execute_entity_post_request(options, url_chunk)
107
107
  if entity.is_new?
108
- doc = ::Nokogiri::XML(result).remove_namespaces!
109
- entity[entity.primary_key] = doc.xpath("//content/properties/#{entity.primary_key}").first.content
108
+ doc = ::Nokogiri::XML(result.body).remove_namespaces!
109
+ primary_key_node = doc.xpath("//content/properties/#{entity.primary_key}").first
110
+ entity[entity.primary_key] = primary_key_node.content unless primary_key_node.nil?
110
111
  end
112
+
113
+ unless result.code.to_s =~ /^2[0-9][0-9]$/
114
+ entity.errors << ['could not commit entity']
115
+ end
116
+
111
117
  entity
112
118
  end
113
119
 
@@ -143,9 +149,22 @@ module OData
143
149
  def execute_entity_post_request(options, url_chunk)
144
150
  result = service.execute(url_chunk, options)
145
151
  unless result.code.to_s =~ /^2[0-9][0-9]$/
146
- raise StandardError, 'Something went wrong committing your entity'
152
+ service.logger.debug <<-EOS
153
+ [ODATA: #{service_name}]
154
+ An error was encountered committing your entity:
155
+
156
+ POSTed URL:
157
+ #{url_chunk}
158
+
159
+ POSTed Entity:
160
+ #{options[:body]}
161
+
162
+ Result Body:
163
+ #{result.body}
164
+ EOS
165
+ service.logger.info "[ODATA: #{service_name}] Unable to commit data to #{url_chunk}"
147
166
  end
148
- result.body
167
+ result
149
168
  end
150
169
 
151
170
  def setup_entity_post_request(entity)
data/lib/odata/service.rb CHANGED
@@ -218,6 +218,14 @@ module OData
218
218
  properties_to_return
219
219
  end
220
220
 
221
+ def logger
222
+ @logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
223
+ end
224
+
225
+ def logger=(custom_logger)
226
+ @logger = custom_logger
227
+ end
228
+
221
229
  private
222
230
 
223
231
  def default_options
data/lib/odata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OData
2
- VERSION = '0.6.6'
2
+ VERSION = '0.6.7'
3
3
  end
@@ -95,7 +95,11 @@ describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
95
95
  } }
96
96
 
97
97
  describe 'with an existing entity', vcr: {cassette_name: 'entity_set_specs/existing_entry'} do
98
- it { expect {subject << existing_entity}.to_not raise_error }
98
+ before(:each) do
99
+ subject << existing_entity
100
+ end
101
+
102
+ it { expect(existing_entity.any_errors?).to eq(false) }
99
103
  end
100
104
 
101
105
  describe 'with a new entity', vcr: {cassette_name: 'entity_set_specs/new_entry'} do
@@ -108,7 +112,11 @@ describe OData::EntitySet, vcr: {cassette_name: 'entity_set_specs'} do
108
112
  end
109
113
 
110
114
  describe 'with a bad entity', vcr: {cassette_name: 'entity_set_specs/bad_entry'} do
111
- it { expect {subject << bad_entity}.to raise_error(StandardError, 'Something went wrong committing your entity') }
115
+ before(:each) do
116
+ subject << bad_entity
117
+ end
118
+
119
+ it { expect(bad_entity.any_errors?).to eq(true) }
112
120
  end
113
121
  end
114
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Thompson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-06 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler