restfully 0.8.0 → 0.8.1

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.
@@ -23,6 +23,8 @@ module Restfully
23
23
  request[:head] = sanitize_head(@session.default_headers).merge(
24
24
  build_head(request)
25
25
  )
26
+ origin_content_type = request[:head].delete('Origin-Content-Type')
27
+ request[:head]['Content-Type'] ||= origin_content_type if origin_content_type
26
28
 
27
29
  request[:uri] = @session.uri_to(path)
28
30
  if request[:query]
@@ -21,7 +21,7 @@ module Restfully
21
21
  notification
22
22
  }.map{|n|
23
23
  "application/vnd.fr.grid5000.api.#{n}+json"
24
- }.push(
24
+ }.unshift(
25
25
  "application/vnd.grid5000+json"
26
26
  )
27
27
  set :parser, ApplicationJson::JSONParser
@@ -2,8 +2,8 @@ module Restfully
2
2
  # This class represents a Resource, which can be accessed and manipulated
3
3
  # via HTTP methods.
4
4
  #
5
- # Some resources can be collection of other resources.
6
- # In that case the <tt>Restfully::Collection</tt> module is included in the <tt>Restfully::Resource</tt> class.
5
+ # Some resources can be collection of other resources.
6
+ # In that case the <tt>Restfully::Collection</tt> module is included in the <tt>Restfully::Resource</tt> class.
7
7
  # See the corresponding documentation for the list of additional methods that you can use on a collection resource.
8
8
  class Resource
9
9
  attr_reader :response, :request, :session
@@ -77,7 +77,7 @@ module Restfully
77
77
  raise Error, "Cannot reload the resource"
78
78
  end
79
79
  end
80
-
80
+
81
81
  build
82
82
  end
83
83
 
@@ -90,7 +90,7 @@ module Restfully
90
90
  def properties
91
91
  case props = media_type.property
92
92
  when Hash
93
- props.reject{|k,v|
93
+ props.reject{|k,v|
94
94
  # do not return keys used for internal use
95
95
  k.to_s =~ HIDDEN_PROPERTIES_REGEXP
96
96
  }
@@ -153,7 +153,7 @@ module Restfully
153
153
  "{...}"
154
154
  end
155
155
  end
156
-
156
+
157
157
  def pretty_print(pp)
158
158
  pp.text signature(false)
159
159
  pp.nest 2 do
@@ -164,7 +164,7 @@ module Restfully
164
164
  pp.breakable
165
165
  pp.text "#{relationships.join(", ")}"
166
166
  end
167
- end
167
+ end
168
168
  pp.breakable
169
169
  if collection?
170
170
  # display items
@@ -205,7 +205,7 @@ module Restfully
205
205
  'Accept' => link.type
206
206
  }).load(*args)
207
207
  end
208
-
208
+
209
209
  end
210
210
  # end
211
211
  self
@@ -220,20 +220,22 @@ module Restfully
220
220
  protected
221
221
  def extract_payload_from_args(args)
222
222
  options = args.extract_options!
223
- head = options.delete(:headers) || options.delete(:head)
223
+ head = options.delete(:headers) || options.delete(:head) || {}
224
+ head['Origin-Content-Type'] = response.head['Content-Type']
225
+
224
226
  query = options.delete(:query)
225
227
 
226
228
  payload = args.shift || options
227
-
229
+
228
230
  options = {
229
231
  :head => head, :query => query,
230
- :serialization => media_type.property.reject{|k,v|
232
+ :serialization => media_type.property.reject{|k,v|
231
233
  k !~ HIDDEN_PROPERTIES_REGEXP
232
234
  }
233
235
  }
234
-
236
+
235
237
  [payload, options]
236
238
  end
237
-
239
+
238
240
  end
239
241
  end
@@ -1,3 +1,3 @@
1
1
  module Restfully
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
@@ -73,7 +73,10 @@ describe Restfully::Resource do
73
73
  @session.should_receive(:post).with(
74
74
  @resource.uri,
75
75
  'some payload',
76
- :head => {'Content-Type' => 'text/plain'},
76
+ :head => {
77
+ 'Content-Type' => 'text/plain',
78
+ 'Origin-Content-Type' => "application/vnd.grid5000+json; charset=utf-8"
79
+ },
77
80
  :query => {:k1 => 'v1'},
78
81
  :serialization => {}
79
82
  )
@@ -88,7 +91,10 @@ describe Restfully::Resource do
88
91
  @session.should_receive(:post).with(
89
92
  @resource.uri,
90
93
  {:key => 'value'},
91
- :head => {'Content-Type' => 'text/plain'},
94
+ :head => {
95
+ 'Content-Type' => 'text/plain',
96
+ 'Origin-Content-Type' => "application/vnd.grid5000+json; charset=utf-8"
97
+ },
92
98
  :query => {:k1 => 'v1'},
93
99
  :serialization => {}
94
100
  )
@@ -115,7 +121,10 @@ describe Restfully::Resource do
115
121
  @session.should_receive(:put).with(
116
122
  @resource.uri,
117
123
  {:key => 'value'},
118
- :head => {'Content-Type' => 'text/plain'},
124
+ :head => {
125
+ 'Content-Type' => 'text/plain',
126
+ 'Origin-Content-Type' => "application/vnd.bonfire+xml; charset=utf-8"
127
+ },
119
128
  :query => {:k1 => 'v1'},
120
129
  :serialization => {"__type__"=>"network"}
121
130
  )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfully
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Cyril Rohr