sawyer 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sawyer.rb +1 -1
- data/lib/sawyer/resource.rb +6 -6
- data/lib/sawyer/serializer.rb +10 -4
- data/test/agent_test.rb +21 -1
- data/test/resource_test.rb +3 -2
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c9a99c50756921f097b19c3d4a42ef54cfdf0d8
|
4
|
+
data.tar.gz: 93540df1ca29c6aa1fed7a383602fb109839409d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de8890ee3174ea4dd745c3cb9ab64fd66d496cda4cb5b35501963a4883066f426b7389b73ffae29b44b0ac1efaeb3fc2f512f7d4e440410d1474c494eb3f0a1
|
7
|
+
data.tar.gz: 10ae9c4b564272abf48abccbc0817bc2e8545275377ccb0bcfa796bec68494a66fc7ace234b92bf1b7e79a7f3480dc9265dc79a24294ffc347d2455d76a6592d
|
data/lib/sawyer.rb
CHANGED
data/lib/sawyer/resource.rb
CHANGED
@@ -83,11 +83,11 @@ module Sawyer
|
|
83
83
|
elsif attr_name && @_fields.include?(attr_name.to_sym)
|
84
84
|
value = @attrs[attr_name.to_sym]
|
85
85
|
case suffix
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
when nil
|
87
|
+
@_metaclass.send(:attr_accessor, attr_name)
|
88
|
+
value
|
89
|
+
when ATTR_PREDICATE then !!value
|
90
|
+
end
|
91
91
|
elsif suffix.nil? && SPECIAL_METHODS.include?(attr_name)
|
92
92
|
instance_variable_get "@_#{attr_name}"
|
93
93
|
elsif attr_name && !@_fields.include?(attr_name.to_sym)
|
@@ -141,7 +141,7 @@ module Sawyer
|
|
141
141
|
|
142
142
|
def marshal_load(dumped)
|
143
143
|
@attrs, @_fields, @_rels = *dumped.shift(3)
|
144
|
+
@_metaclass = (class << self; self; end)
|
144
145
|
end
|
145
146
|
end
|
146
147
|
end
|
147
|
-
|
data/lib/sawyer/serializer.rb
CHANGED
@@ -58,7 +58,7 @@ module Sawyer
|
|
58
58
|
#
|
59
59
|
# Returns a decoded Object.
|
60
60
|
def decode(data)
|
61
|
-
return nil if data.nil? || data.empty?
|
61
|
+
return nil if data.nil? || data.strip.empty?
|
62
62
|
decode_object(@load.call(data))
|
63
63
|
end
|
64
64
|
|
@@ -100,9 +100,15 @@ module Sawyer
|
|
100
100
|
|
101
101
|
def decode_hash_value(key, value)
|
102
102
|
if time_field?(key, value)
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
if value.is_a?(String)
|
104
|
+
begin
|
105
|
+
Time.parse(value)
|
106
|
+
rescue ArgumentError
|
107
|
+
value
|
108
|
+
end
|
109
|
+
elsif value.is_a?(Integer) || value.is_a?(Float)
|
110
|
+
Time.at(value)
|
111
|
+
else
|
106
112
|
value
|
107
113
|
end
|
108
114
|
elsif value.is_a?(Hash)
|
data/test/agent_test.rb
CHANGED
@@ -127,6 +127,9 @@ module Sawyer
|
|
127
127
|
:published_at => nil,
|
128
128
|
:updated_at => "An invalid date",
|
129
129
|
:pub_date => time,
|
130
|
+
:subscribed_at => time.to_i,
|
131
|
+
:lost_at => time.to_f,
|
132
|
+
:first_date => false,
|
130
133
|
:validate => true
|
131
134
|
}
|
132
135
|
data = [data.merge(:foo => [data])]
|
@@ -145,6 +148,9 @@ module Sawyer
|
|
145
148
|
assert_equal "An invalid date", decoded[:updated_at]
|
146
149
|
assert_equal time, decoded[:pub_date], "Did not parse pub_date as Time"
|
147
150
|
assert_equal true, decoded[:validate]
|
151
|
+
assert_equal time, decoded[:subscribed_at], "Did not parse subscribed_at as Time"
|
152
|
+
assert_equal time, decoded[:lost_at], "Did not parse lost_at as Time"
|
153
|
+
assert_equal false, decoded[:first_date], "Parsed first_date"
|
148
154
|
decoded = decoded[:foo]
|
149
155
|
end
|
150
156
|
end
|
@@ -176,6 +182,20 @@ module Sawyer
|
|
176
182
|
Marshal.load(Marshal.dump(res))
|
177
183
|
end
|
178
184
|
end
|
185
|
+
|
186
|
+
def test_blank_response_doesnt_raise
|
187
|
+
@stubs.get "/a/" do |env|
|
188
|
+
assert_equal "foo.com", env[:url].host
|
189
|
+
[200, { "Content-Type" => "application/json" }, " "]
|
190
|
+
end
|
191
|
+
|
192
|
+
agent = Sawyer::Agent.new "http://foo.com/a/" do |conn|
|
193
|
+
conn.adapter :test, @stubs
|
194
|
+
end
|
195
|
+
|
196
|
+
assert_nothing_raised do
|
197
|
+
assert_equal 200, agent.root.status
|
198
|
+
end
|
199
|
+
end
|
179
200
|
end
|
180
201
|
end
|
181
|
-
|
data/test/resource_test.rb
CHANGED
@@ -166,8 +166,9 @@ module Sawyer
|
|
166
166
|
|
167
167
|
def test_handle_marshal_dump
|
168
168
|
assert_nothing_raised do
|
169
|
-
|
170
|
-
Marshal.dump
|
169
|
+
dump = Marshal.dump(Resource.new(@agent, :a => 1))
|
170
|
+
resource = Marshal.load(dump)
|
171
|
+
assert_equal 1, resource.a
|
171
172
|
end
|
172
173
|
end
|
173
174
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sawyer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rick Olson
|
@@ -9,40 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0.8'
|
21
|
-
- - <
|
21
|
+
- - "<"
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '0.10'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - ~>
|
28
|
+
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '0.8'
|
31
|
-
- - <
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.10'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: addressable
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.3.5
|
41
41
|
type: :runtime
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.3.5
|
48
48
|
description:
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- LICENSE.md
|
56
56
|
- README.md
|
57
57
|
- Rakefile
|
58
|
-
- sawyer.
|
58
|
+
- lib/sawyer.rb
|
59
59
|
- lib/sawyer/agent.rb
|
60
60
|
- lib/sawyer/link_parsers/hal.rb
|
61
61
|
- lib/sawyer/link_parsers/simple.rb
|
@@ -63,17 +63,17 @@ files:
|
|
63
63
|
- lib/sawyer/resource.rb
|
64
64
|
- lib/sawyer/response.rb
|
65
65
|
- lib/sawyer/serializer.rb
|
66
|
-
-
|
67
|
-
- test/agent_test.rb
|
68
|
-
- test/helper.rb
|
69
|
-
- test/relation_test.rb
|
70
|
-
- test/resource_test.rb
|
71
|
-
- test/response_test.rb
|
66
|
+
- sawyer.gemspec
|
72
67
|
- script/bootstrap
|
73
68
|
- script/console
|
74
69
|
- script/package
|
75
70
|
- script/release
|
76
71
|
- script/test
|
72
|
+
- test/agent_test.rb
|
73
|
+
- test/helper.rb
|
74
|
+
- test/relation_test.rb
|
75
|
+
- test/resource_test.rb
|
76
|
+
- test/response_test.rb
|
77
77
|
homepage: https://github.com/lostisland/sawyer
|
78
78
|
licenses:
|
79
79
|
- MIT
|
@@ -84,17 +84,17 @@ require_paths:
|
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- -
|
92
|
+
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: 1.3.5
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.2.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 2
|
100
100
|
summary: Secret User Agent of HTTP
|