Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

license

  • Loading branch information...
commit 258594b4e3960edb271eff26ec1086620e243a58 1 parent 9175884
Guilherme Silveira guilhermesilveira authored
17 LICENSE
View
@@ -0,0 +1,17 @@
+/***
+ * Copyright (c) 2009 Caelum - www.caelum.com.br/opensource
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
17 lib/restfulie/client/request_execution.rb
View
@@ -82,6 +82,9 @@ def add_basic_request_headers(req)
req.add_field("Accept", @accepts) unless @accepts.nil?
end
+ # parses a get response.
+ # if the result code is 301, redirect
+ # otherwise, parses an ok response
def parse_get_response(res)
code = res.code
@@ -90,30 +93,26 @@ def parse_get_response(res)
end
+ # parses a successful get response.
+ # parses the entity and add extra (response related) fields.
def parse_get_ok_response(res, code)
result = parse_get_entity(res, code)
add_extra_fields(result, res)
result
end
+ # add etag, last_modified and web_response fields to the resulting object
def add_extra_fields(result,res)
result.etag = res['Etag'] unless res['Etag'].nil?
result.last_modified = res['Last-Modified'] unless res['Last-Modified'].nil?
result.web_response = res
end
- def type_for(content_type)
- if Restfulie::MediaType.supports? content_type
- Restfulie::MediaType.media_type(content_type)
- else
- Restfulie::MediaType::DefaultMediaTypeDecoder
- end
- end
-
+ # returns an entity for a specific response
def parse_get_entity(res, code)
if code=="200"
content_type = res.content_type
- type = type_for(content_type)
+ type = Restfulie::MediaType.type_for(content_type)
if content_type[-3,3]=="xml"
result = type.from_xml res.body
elsif content_type[-4,4]=="json"
9 lib/restfulie/media_type.rb
View
@@ -18,6 +18,15 @@ def to_s
module MediaType
+ # returns the decoder type for a specific content type
+ def self.type_for(content_type)
+ if Restfulie::MediaType.supports? content_type
+ Restfulie::MediaType.media_type(content_type)
+ else
+ Restfulie::MediaType::DefaultMediaTypeDecoder
+ end
+ end
+
# TODO removethis nasty method
def self.rendering_type(name, type)
Restfulie::MediaType.media_types[name] || Type.new(name,type)
2  spec/media_type_spec.rb
View
@@ -131,4 +131,6 @@ def verify(all, expected)
end
+ type_for deve devolver o default ou o registradfo
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.