flexirest 1.2.16 → 1.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Rakefile +2 -1
- data/lib/flexirest/attribute_parsing.rb +15 -0
- data/lib/flexirest/base.rb +2 -7
- data/lib/flexirest/request.rb +2 -5
- data/lib/flexirest/version.rb +1 -1
- data/lib/flexirest.rb +1 -0
- data/spec/lib/attribute_parsing_spec.rb +34 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74460a02097196ff9ac4e73815ad1be63f1664dd
|
4
|
+
data.tar.gz: 6b138a264aeb07a1012ccfbfbca944f0074f27bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd6868bc4b2de02129bb7078fdd5742a32246ad7275af9d9811dc6f2c2ed005ead6bcc243eff491e6240f05852614dad1899ce529526e21a9c2a6ceb497081cd
|
7
|
+
data.tar.gz: 94548faeb9a21ce22b6227ef3f3ccf100357f090b71a177b393a893e19c37b7c8113a16f148fe5f26e6750ac5020a2b5b13e6e3a67b7416b7e09343c6ea8ac44
|
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -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
|
data/lib/flexirest/base.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/flexirest/request.rb
CHANGED
@@ -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
|
-
|
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?
|
data/lib/flexirest/version.rb
CHANGED
data/lib/flexirest.rb
CHANGED
@@ -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.
|
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-
|
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
|