flexirest 1.2.16 → 1.2.17

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: 67924c36e94f6b5a9ad4cbdf09d7762c20b88ecd
4
- data.tar.gz: 2ac29ea6fef0704c66d7af8105d7009bdeb0141b
3
+ metadata.gz: 74460a02097196ff9ac4e73815ad1be63f1664dd
4
+ data.tar.gz: 6b138a264aeb07a1012ccfbfbca944f0074f27bf
5
5
  SHA512:
6
- metadata.gz: 682f4f180a66df72de50b82cd3263b5c3e9f6d2fc70c23b3ed49a5cf7e3242d8bf0526f0e4d2834e37f80f48915fe09d9907cf286ca60f7584703703d355d0b2
7
- data.tar.gz: cb065db508aaf6ce615d42e353436b8da4b4c5cb17fd9d3f7b07f6dcb5cc7ee5d8e2da9d30efc9dc9ea6fc316c1179c32783160dddbefca589a2ecf129269c80
6
+ metadata.gz: cd6868bc4b2de02129bb7078fdd5742a32246ad7275af9d9811dc6f2c2ed005ead6bcc243eff491e6240f05852614dad1899ce529526e21a9c2a6ceb497081cd
7
+ data.tar.gz: 94548faeb9a21ce22b6227ef3f3ccf100357f090b71a177b393a893e19c37b7c8113a16f148fe5f26e6750ac5020a2b5b13e6e3a67b7416b7e09343c6ea8ac44
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.17
4
+
5
+ Bugfixes:
6
+
7
+ - Corrected parsing of dates/datetimes coming in responses (thanks to Matthias Neumayr)
8
+
3
9
  ## 1.2.16
4
10
 
5
11
  Feature:
data/Rakefile CHANGED
@@ -5,9 +5,10 @@ RSpec::Core::RakeTask.new('spec')
5
5
  task :console do
6
6
  require 'irb'
7
7
  require 'irb/completion'
8
- require 'flexirest'
8
+ require './lib/flexirest'
9
9
  ARGV.clear
10
10
  IRB.start
11
11
  end
12
+ task :c => :console
12
13
 
13
14
  task :default => :spec
@@ -0,0 +1,15 @@
1
+ module Flexirest
2
+ module AttributeParsing
3
+ private
4
+
5
+ def parse_attribute_value(v)
6
+ if v.to_s[(/^(((19|20)\d\d[- \/.](0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9]))|((0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9])[- \/.](19|20)\d\d))$/)]
7
+ Date.parse(v)
8
+ elsif v.to_s[/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?))$/]
9
+ DateTime.parse(v)
10
+ else
11
+ v
12
+ end
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,7 @@ module Flexirest
6
6
  include Validation
7
7
  include Caching
8
8
  include Recording
9
+ include AttributeParsing
9
10
 
10
11
  attr_accessor :_status
11
12
  attr_accessor :_etag
@@ -24,13 +25,7 @@ module Flexirest
24
25
 
25
26
  attrs.each do |attribute_name, attribute_value|
26
27
  attribute_name = attribute_name.to_sym
27
- if attribute_value.to_s[(/^(((19|20)\d\d[- \/.](0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9]))|((0[1-9]|1[012]|[1-9])[- \/.](0[1-9]|[12][0-9]|3[01]|[1-9])[- \/.](19|20)\d\d))$/)]
28
- @attributes[attribute_name] = Date.parse(attribute_value)
29
- elsif attribute_value.to_s[/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?))$/]
30
- @attributes[attribute_name] = DateTime.parse(attribute_value)
31
- else
32
- @attributes[attribute_name] = attribute_value
33
- end
28
+ @attributes[attribute_name] = parse_attribute_value(attribute_value)
34
29
  @dirty_attributes << attribute_name
35
30
  end
36
31
  end
@@ -6,6 +6,7 @@ require 'crack/xml'
6
6
  module Flexirest
7
7
 
8
8
  class Request
9
+ include AttributeParsing
9
10
  attr_accessor :post_params, :get_params, :url, :path, :headers, :method, :object, :body, :forced_url, :original_url
10
11
 
11
12
  def initialize(method, object, params = {})
@@ -448,11 +449,7 @@ module Flexirest
448
449
  end
449
450
  end
450
451
  else
451
- if v.to_s[/\d{4}\-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[+-]\d{2}:\d{2})/]
452
- object._attributes[k] = DateTime.parse(v)
453
- else
454
- object._attributes[k] = v
455
- end
452
+ object._attributes[k] = parse_attribute_value(v)
456
453
  end
457
454
  end
458
455
  object.clean! unless object_is_class?
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.2.16"
2
+ VERSION = "1.2.17"
3
3
  end
data/lib/flexirest.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/all'
2
2
  require "flexirest/version"
3
+ require "flexirest/attribute_parsing"
3
4
  require "flexirest/mapping"
4
5
  require "flexirest/caching"
5
6
  require "flexirest/logger"
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ class AttributeParsingExampleBase
4
+ include Flexirest::AttributeParsing
5
+
6
+ def test(v)
7
+ parse_attribute_value(v)
8
+ end
9
+ end
10
+
11
+
12
+ describe Flexirest::AttributeParsing do
13
+ let(:subject) { AttributeParsingExampleBase.new }
14
+
15
+ it "should parse datetimes" do
16
+ expect(subject.test("1980-12-24T00:00:00.000Z")).to be_a(DateTime)
17
+ end
18
+
19
+ it "should parse dates" do
20
+ expect(subject.test("1980-12-24")).to be_a(Date)
21
+ end
22
+
23
+ it "should return strings for string values" do
24
+ expect(subject.test("1980-12")).to eq("1980-12")
25
+ end
26
+
27
+ it "should return integers for integer values" do
28
+ expect(subject.test(1980)).to eq(1980)
29
+ end
30
+
31
+ it "should return floats for float values" do
32
+ expect(subject.test(1980.12)).to eq(1980.12)
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.16
4
+ version: 1.2.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-03 00:00:00.000000000 Z
11
+ date: 2016-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -256,6 +256,7 @@ files:
256
256
  - doc/Flexirest Internals.png
257
257
  - flexirest.gemspec
258
258
  - lib/flexirest.rb
259
+ - lib/flexirest/attribute_parsing.rb
259
260
  - lib/flexirest/base.rb
260
261
  - lib/flexirest/caching.rb
261
262
  - lib/flexirest/configuration.rb
@@ -276,6 +277,7 @@ files:
276
277
  - lib/flexirest/result_iterator.rb
277
278
  - lib/flexirest/validation.rb
278
279
  - lib/flexirest/version.rb
280
+ - spec/lib/attribute_parsing_spec.rb
279
281
  - spec/lib/base_spec.rb
280
282
  - spec/lib/caching_spec.rb
281
283
  - spec/lib/configuration_spec.rb
@@ -323,6 +325,7 @@ summary: This gem is for accessing REST services in a flexible way. ActiveResou
323
325
  Rails conventions, it doesn't have in-built caching and it's not as flexible in
324
326
  general.
325
327
  test_files:
328
+ - spec/lib/attribute_parsing_spec.rb
326
329
  - spec/lib/base_spec.rb
327
330
  - spec/lib/caching_spec.rb
328
331
  - spec/lib/configuration_spec.rb