sawyer 0.5.3 → 0.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea76751fcf6274b2f73f762bf677f0cce3853f66
4
- data.tar.gz: d38ab2bdb51b5444cdec30b6091679cd67f805d2
3
+ metadata.gz: f6de3df7914dedda29d5d502b9adb7b6df07eb2e
4
+ data.tar.gz: 26b8e89d2c2555949081f5229dac86394399a421
5
5
  SHA512:
6
- metadata.gz: 6ea0e68b367d3cfe2f5d77501f4f6b26f8f246a5b04205ccb7a5e2c3a514f48b7880f3aed7829c8169a7984affbe1afa08d93b05e0d8e282d7b41c57562ca46e
7
- data.tar.gz: cd211dfe87d81e4f4acfea027d904c1a11e2b03a10e2732e2abb7156f4568bfc8b57368e035556647f8ca2cbe79f31d8f59e50258432cbbba09442e2cfbd6abb
6
+ metadata.gz: 5efb922a2238670effddd63acea45632d784317708446c5e6c858acb9600c6a85fa71b6002591514b0059f46d96392b7423dfeadff6b2e82fd9446b696d55de9
7
+ data.tar.gz: efaffd42000f611e68a7c59364a6b4d0f1b3df0ed9709550e432a8dea5159293d127d1265f06eb9694257077b663ac968e76f1bf9fcb389a47767d7ccb96dffd
@@ -1,5 +1,5 @@
1
1
  module Sawyer
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
 
4
4
  class Error < StandardError; end
5
5
  end
@@ -17,7 +17,7 @@ module Sawyer
17
17
  inline_links = data.keys.select {|k| k.to_s[LINK_REGEX] }
18
18
  inline_links.each do |key|
19
19
  rel_name = key.to_s == 'url' ? 'self' : key.to_s.gsub(LINK_REGEX, '')
20
- links[rel_name.to_sym] = data.delete(key)
20
+ links[rel_name.to_sym] = data[key]
21
21
  end
22
22
 
23
23
  return data, links
@@ -38,9 +38,17 @@ module Sawyer
38
38
  def keys
39
39
  @map.keys
40
40
  end
41
+ def to_hash
42
+ pairs = @map.map do |k, v|
43
+ [(k.to_s + "_url").to_sym, v.href]
44
+ end
45
+ Hash[pairs]
46
+ end
47
+ alias :to_h :to_hash
41
48
 
42
49
  def inspect
43
- %(#<#{self.class}: #{@map.keys.inspect}>)
50
+ hash = to_hash
51
+ hash.respond_to?(:pretty_inspect) ? hash.pretty_inspect : hash.inspect
44
52
  end
45
53
  end
46
54
 
@@ -4,6 +4,7 @@ module Sawyer
4
4
  attr_reader :_agent, :_rels, :_fields
5
5
  attr_reader :attrs
6
6
  alias to_hash attrs
7
+ alias to_h attrs
7
8
 
8
9
  # Initializes a Resource with the given data.
9
10
  #
@@ -115,11 +116,25 @@ module Sawyer
115
116
  end
116
117
  end
117
118
 
119
+ def inspect
120
+ to_attrs.respond_to?(:pretty_inspect) ? to_attrs.pretty_inspect : to_attrs.inspect
121
+ end
122
+
118
123
  # private
119
124
  def to_yaml_properties
120
125
  [:@attrs, :@_fields, :@_rels]
121
126
  end
122
127
 
128
+ def to_attrs
129
+ hash = self.attrs.clone
130
+ hash.keys.each do |k|
131
+ if hash[k].is_a?(Sawyer::Resource)
132
+ hash[k] = hash[k].to_attrs
133
+ end
134
+ end
135
+ hash
136
+ end
137
+
123
138
  def marshal_dump
124
139
  [@attrs, @_fields, @_rels]
125
140
  end
@@ -161,5 +161,14 @@ module Sawyer
161
161
  assert_equal 204, rel.put.status
162
162
  assert_equal 204, rel.delete.status
163
163
  end
164
+
165
+ def test_map_inspect
166
+ map = Sawyer::Relation::Map.new
167
+ hash = {:href => '/users/1', :method => 'post'}
168
+ rel = Sawyer::Relation.from_link(nil, :self, hash)
169
+ map << rel
170
+
171
+ assert_equal "{:self_url=>\"/users/1\"}\n", map.inspect
172
+ end
164
173
  end
165
174
  end
@@ -122,6 +122,12 @@ module Sawyer
122
122
  assert_equal hash, res.attrs
123
123
  end
124
124
 
125
+ def test_to_h
126
+ res = Resource.new @agent, :a => 1
127
+ hash = {:a => 1 }
128
+ assert_equal hash, res.to_h
129
+ end
130
+
125
131
  def test_handle_hash_notation_with_string_key
126
132
  res = Resource.new @agent, :a => 1
127
133
  assert_equal 1, res['a']
@@ -142,12 +148,12 @@ module Sawyer
142
148
 
143
149
  assert_equal '/', res.rels[:self].href
144
150
  assert_kind_of Resource, res.user
145
- assert !res.fields.include?(:url)
151
+ assert_equal '/', res.url
146
152
  assert_equal 1, res.user.id
147
153
  assert_equal '/users/1', res.user.rels[:self].href
148
- assert !res.user.fields.include?(:url)
154
+ assert_equal '/users/1', res.user.url
149
155
  assert_equal '/users/1/followers', res.user.rels[:followers].href
150
- assert !res.user.fields.include?(:followers_url)
156
+ assert_equal '/users/1/followers', res.user.followers_url
151
157
  end
152
158
 
153
159
  def test_handle_yaml_dump
@@ -164,5 +170,10 @@ module Sawyer
164
170
  Marshal.dump(res)
165
171
  end
166
172
  end
173
+
174
+ def test_inspect
175
+ resource = Resource.new @agent, :a => 1
176
+ assert_equal "{:a=>1}\n", resource.inspect
177
+ end
167
178
  end
168
179
  end
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.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Olson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-21 00:00:00.000000000 Z
12
+ date: 2014-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday