Skip to content
This repository
Browse code

license

  • Loading branch information...
commit 258594b4e3960edb271eff26ec1086620e243a58 1 parent 9175884
Guilherme Silveira guilhermesilveira authored
17 LICENSE
... ... @@ -0,0 +1,17 @@
  1 +/***
  2 + * Copyright (c) 2009 Caelum - www.caelum.com.br/opensource
  3 + * All rights reserved.
  4 + *
  5 + * Licensed under the Apache License, Version 2.0 (the "License");
  6 + * you may not use this file except in compliance with the License.
  7 + * You may obtain a copy of the License at
  8 + *
  9 + * http://www.apache.org/licenses/LICENSE-2.0
  10 + *
  11 + * Unless required by applicable law or agreed to in writing, software
  12 + * distributed under the License is distributed on an "AS IS" BASIS,
  13 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 + * See the License for the specific language governing permissions and
  15 + * limitations under the License.
  16 + */
  17 +
17 lib/restfulie/client/request_execution.rb
@@ -82,6 +82,9 @@ def add_basic_request_headers(req)
82 82 req.add_field("Accept", @accepts) unless @accepts.nil?
83 83 end
84 84
  85 + # parses a get response.
  86 + # if the result code is 301, redirect
  87 + # otherwise, parses an ok response
85 88 def parse_get_response(res)
86 89
87 90 code = res.code
@@ -90,30 +93,26 @@ def parse_get_response(res)
90 93
91 94 end
92 95
  96 + # parses a successful get response.
  97 + # parses the entity and add extra (response related) fields.
93 98 def parse_get_ok_response(res, code)
94 99 result = parse_get_entity(res, code)
95 100 add_extra_fields(result, res)
96 101 result
97 102 end
98 103
  104 + # add etag, last_modified and web_response fields to the resulting object
99 105 def add_extra_fields(result,res)
100 106 result.etag = res['Etag'] unless res['Etag'].nil?
101 107 result.last_modified = res['Last-Modified'] unless res['Last-Modified'].nil?
102 108 result.web_response = res
103 109 end
104 110
105   - def type_for(content_type)
106   - if Restfulie::MediaType.supports? content_type
107   - Restfulie::MediaType.media_type(content_type)
108   - else
109   - Restfulie::MediaType::DefaultMediaTypeDecoder
110   - end
111   - end
112   -
  111 + # returns an entity for a specific response
113 112 def parse_get_entity(res, code)
114 113 if code=="200"
115 114 content_type = res.content_type
116   - type = type_for(content_type)
  115 + type = Restfulie::MediaType.type_for(content_type)
117 116 if content_type[-3,3]=="xml"
118 117 result = type.from_xml res.body
119 118 elsif content_type[-4,4]=="json"
9 lib/restfulie/media_type.rb
@@ -18,6 +18,15 @@ def to_s
18 18
19 19 module MediaType
20 20
  21 + # returns the decoder type for a specific content type
  22 + def self.type_for(content_type)
  23 + if Restfulie::MediaType.supports? content_type
  24 + Restfulie::MediaType.media_type(content_type)
  25 + else
  26 + Restfulie::MediaType::DefaultMediaTypeDecoder
  27 + end
  28 + end
  29 +
21 30 # TODO removethis nasty method
22 31 def self.rendering_type(name, type)
23 32 Restfulie::MediaType.media_types[name] || Type.new(name,type)
2  spec/media_type_spec.rb
@@ -131,4 +131,6 @@ def verify(all, expected)
131 131
132 132 end
133 133
  134 + type_for deve devolver o default ou o registradfo
  135 +
134 136 end

0 comments on commit 258594b

Please sign in to comment.
Something went wrong with that request. Please try again.