francxk-httparty 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.1.4 2008-08-XX
2
+
3
+ * 1 major enhancements:
4
+ * Modified the management of allowedFormat and mime type to detect the right format
5
+
1
6
 
2
7
  == 0.1.3 2008-08-22
3
8
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{httparty}
3
- s.version = "0.1.3"
3
+ s.version = "0.1.4"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["John Nunemaker"]
@@ -18,7 +18,17 @@ module HTTParty
18
18
  base.extend ClassMethods
19
19
  end
20
20
 
21
- AllowedFormats = {:xml => 'text/xml', :json => 'application/json'}
21
+ # this is the format known by the module
22
+ AllowedFormats = [:xml, :json]
23
+
24
+ # for each mime types give the format found in AllowedFormat (that can be parsed)
25
+ MimeTypes = {
26
+ 'application/xml' => :xml,
27
+ 'application/atom+xml' => :xml,
28
+ 'application/rdf+xml' => :xml,
29
+ 'text/xml' => :xml,
30
+ 'application/json' => :json,
31
+ 'text/json' => :json, }
22
32
 
23
33
  module ClassMethods
24
34
  #
@@ -64,7 +74,7 @@ module HTTParty
64
74
  end
65
75
 
66
76
  def format(f)
67
- raise UnsupportedFormat, "Must be one of: #{AllowedFormats.keys.join(', ')}" unless AllowedFormats.key?(f)
77
+ raise UnsupportedFormat, "Must be one of: #{AllowedFormats.join(', ')}" unless AllowedFormats.include?(f)
68
78
  @format = f
69
79
  end
70
80
 
@@ -126,7 +136,7 @@ module HTTParty
126
136
  request.basic_auth(basic_auth[:username], basic_auth[:password]) if basic_auth
127
137
  response = http(uri).request(request)
128
138
 
129
- @format ||= format_from_mimetype(response['content-type'])
139
+ @format ||= format_from_mimetype(response['content-type'].split(';',2)[0])
130
140
 
131
141
  case response
132
142
  when Net::HTTPSuccess
@@ -157,9 +167,9 @@ module HTTParty
157
167
  end
158
168
 
159
169
  # Uses the HTTP Content-Type header to determine the format of the response
160
- # It compares the MIME type returned to the types stored in the AllowedFormats hash
170
+ # It compares the MIME type returned to the types stored in the MimeType hashto choose format (ie AloowedFormat)
161
171
  def format_from_mimetype(mimetype) #:nodoc:
162
- AllowedFormats.each { |k, v| return k if mimetype.include?(v) }
172
+ MimeTypes[mimetype]
163
173
  end
164
174
  end
165
175
  end
@@ -2,7 +2,7 @@ module HTTParty
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: francxk-httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker