wrest 1.4.2-universal-java-1.6 → 1.5.0-universal-java-1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +19 -0
- data/README.rdoc +24 -5
- data/bin/rdoc +16 -0
- data/lib/wrest/async_request/event_machine_backend.rb +2 -2
- data/lib/wrest/async_request/thread_backend.rb +2 -2
- data/lib/wrest/async_request.rb +1 -1
- data/lib/wrest/caching.rb +1 -1
- data/lib/wrest/components/container.rb +2 -2
- data/lib/wrest/components/mutators.rb +5 -5
- data/lib/wrest/components/translators/content_types.rb +2 -1
- data/lib/wrest/components/translators/json.rb +9 -1
- data/lib/wrest/components/translators/txt.rb +31 -0
- data/lib/wrest/components/translators/xml.rb +8 -0
- data/lib/wrest/components/translators.rb +4 -3
- data/lib/wrest/components.rb +2 -2
- data/lib/wrest/core_ext/hash.rb +1 -1
- data/lib/wrest/core_ext/string.rb +1 -1
- data/lib/wrest/curl/response.rb +11 -3
- data/lib/wrest/curl.rb +12 -12
- data/lib/wrest/http_shared/standard_headers.rb +1 -0
- data/lib/wrest/http_shared/standard_tokens.rb +1 -0
- data/lib/wrest/http_shared.rb +3 -3
- data/lib/wrest/multipart.rb +0 -2
- data/lib/wrest/native/response.rb +9 -1
- data/lib/wrest/native.rb +10 -10
- data/lib/wrest/test.rb +1 -1
- data/lib/wrest/uri/builders.rb +42 -0
- data/lib/wrest/uri.rb +63 -63
- data/lib/wrest/version.rb +1 -1
- data/lib/wrest/xml_mini.rb +0 -2
- data/lib/wrest.rb +22 -30
- metadata +39 -48
- data/bin/wrest.compiled.rbc +0 -78
- data/bin/wrest_shell.rbc +0 -642
data/CHANGELOG
CHANGED
@@ -2,6 +2,25 @@ Features under the section marked 'Current' are completed but pending release as
|
|
2
2
|
|
3
3
|
Features under a numbered section are complete and available in the Wrest gem.
|
4
4
|
|
5
|
+
== 1.5.0
|
6
|
+
* Introducing content type text/plain - pull request by buchin
|
7
|
+
|
8
|
+
== 1.4.7
|
9
|
+
* Switch to using multi_json to manage Json backend to play nice with Rails 3.1.
|
10
|
+
|
11
|
+
== 1.4.6
|
12
|
+
* Bump Builder dependency to allow both Builder 2.x and 3.x to be used
|
13
|
+
|
14
|
+
== 1.4.5
|
15
|
+
* GH#107 alias :deserialize :deserialise
|
16
|
+
|
17
|
+
== 1.4.4
|
18
|
+
* GH#105 Reduce Rubgems version requirements to 1.3.x or greater from > 1.5
|
19
|
+
|
20
|
+
== 1.4.3
|
21
|
+
* GH#104 Allow default headers to be added to the uri that are then used for all requests
|
22
|
+
* GH#31 Add explicit API for cookies
|
23
|
+
|
5
24
|
== 1.4.2
|
6
25
|
* GH#102 Code and gemspec mismatch for json-jruby
|
7
26
|
|
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
= Wrest 1.
|
1
|
+
= Wrest 1.5.0
|
2
2
|
|
3
|
-
(c) Copyright 2009-2011 {Sidu Ponnappa}[http://blog.sidu.in]. All Rights Reserved.
|
3
|
+
(c) Copyright 2009-2011 {Sidu Ponnappa}[http://blog.sidu.in]. All Rights Reserved.
|
4
|
+
|
5
|
+
{CI Status:}[http://ci.c42.in/projects/wrest] http://ci.c42.in/projects/wrest.png
|
4
6
|
|
5
7
|
Wrest is a ruby REST/HTTP client library which
|
6
8
|
|
@@ -58,7 +60,7 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
|
|
58
60
|
:results=> '3',
|
59
61
|
:start => '1'
|
60
62
|
).deserialise_using(
|
61
|
-
Wrest::Translators::Xml
|
63
|
+
Wrest::Components::Translators::Xml
|
62
64
|
)
|
63
65
|
* Basic HTTP auth and URI extensions using Wrest::Uri#[]
|
64
66
|
|
@@ -86,6 +88,8 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
|
|
86
88
|
:image => UploadIO.new(File.open(file_path), "image/png", file_path),
|
87
89
|
:key => imgur_key
|
88
90
|
).deserialise
|
91
|
+
|
92
|
+
Note: To enable Multipart support, you'll have to explicitly require 'wrest/multipart', which depends on the multipart-post gem.
|
89
93
|
|
90
94
|
==== DELETE
|
91
95
|
|
@@ -188,6 +192,8 @@ Note: The current implementation of asynchronous requests is currently in alpha
|
|
188
192
|
|
189
193
|
=== Other useful stuff
|
190
194
|
|
195
|
+
==== Hash container with ActiveResource-like semantics
|
196
|
+
|
191
197
|
Allows any class to hold an attributes hash, somewhat like ActiveResource. It also supports several extensions to this base fuctionality such as support for typecasting attribute values. See examples/twitter.rb and examples/wow_realm_status.rb for more samples.
|
192
198
|
|
193
199
|
Example:
|
@@ -209,10 +215,23 @@ Example:
|
|
209
215
|
kai_wren.energy # => #<Chi:0x113af8c @count="1024">
|
210
216
|
kai_wren.teacher # => 'Viss'
|
211
217
|
|
218
|
+
==== Opt-out of core extensions
|
219
|
+
|
220
|
+
Uncomfortable with extending <tt>String</tt> to add <tt>to_uri</tt>? Simply do
|
221
|
+
gem "wrest", :require => "wrest_no_ext"
|
222
|
+
in your Gemfile. You can now do <tt>Uri.new('http://localhost')</tt> to build Uris.
|
223
|
+
|
212
224
|
=== Logging
|
213
225
|
|
214
226
|
The Wrest logger can be set and accessed through Wrest.logger and is configured by default to log to STDOUT. If you're using Wrest in a Rails application, you can configure logging by adding a config/initializers/wrest.rb file with the following contents :
|
215
|
-
Wrest.logger =
|
227
|
+
Wrest.logger = Rails.logger
|
228
|
+
|
229
|
+
=== Json Backend
|
230
|
+
|
231
|
+
Wrest uses the multi_json gem to manage Json backends, allowing it to play nice with Rails 3.1. To change the backend used, you can do the following:
|
232
|
+
MultiJson.engine = :json_gem
|
233
|
+
|
234
|
+
For more information, look up the {multi_json}[http://github.com/intridea/multi_json] documentation.
|
216
235
|
|
217
236
|
=== Build
|
218
237
|
|
@@ -242,7 +261,7 @@ You can launch the interactive Wrest shell by running bin/wrest if you have the
|
|
242
261
|
|
243
262
|
=== Testing
|
244
263
|
|
245
|
-
Start the Sinatra test server for functional test.
|
264
|
+
Start the Sinatra test server for functional test. The dependencies for the test app are managed separately by a Gemfile under spec/sample_app.
|
246
265
|
rake -f spec/sample_app/Rakefile # runs on port 3000
|
247
266
|
|
248
267
|
Start a memcached daemon/process on port 11211
|
data/bin/rdoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rdoc' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
|
+
|
16
|
+
load Gem.bin_path('rdoc', 'rdoc')
|
data/lib/wrest/async_request.rb
CHANGED
@@ -12,7 +12,7 @@ module Wrest
|
|
12
12
|
module AsyncRequest
|
13
13
|
# Loads Wrest eventmachine backend alongwith eventmachine gem
|
14
14
|
def self.enable_em
|
15
|
-
require "
|
15
|
+
require "wrest/async_request/event_machine_backend"
|
16
16
|
end
|
17
17
|
|
18
18
|
# Assign default backend to be used for asynchronous request. Default is to use threads
|
data/lib/wrest/caching.rb
CHANGED
@@ -11,7 +11,7 @@ module Wrest
|
|
11
11
|
module Caching
|
12
12
|
# Loads the Memcached caching back-end and the Dalli gem
|
13
13
|
def self.enable_memcached
|
14
|
-
require "
|
14
|
+
require "wrest/caching/memcached"
|
15
15
|
end
|
16
16
|
|
17
17
|
# Configures Wrest to cache all requests. This will use a Ruby Hash.
|
@@ -12,8 +12,8 @@ module Wrest
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
require "
|
16
|
-
require "
|
15
|
+
require "wrest/components/container/typecaster"
|
16
|
+
require "wrest/components/container/alias_accessors"
|
17
17
|
|
18
18
|
module Wrest::Components
|
19
19
|
|
@@ -32,9 +32,9 @@ module Wrest
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
require "
|
36
|
-
require "
|
37
|
-
require "
|
38
|
-
require "
|
39
|
-
require "
|
35
|
+
require "wrest/core_ext/hash"
|
36
|
+
require "wrest/components/mutators/base"
|
37
|
+
require "wrest/components/mutators/xml_simple_type_caster"
|
38
|
+
require "wrest/components/mutators/xml_mini_type_caster"
|
39
|
+
require "wrest/components/mutators/camel_to_snake_case"
|
40
40
|
|
@@ -14,7 +14,8 @@ module Wrest
|
|
14
14
|
'application/xml' => Wrest::Components::Translators::Xml,
|
15
15
|
'text/xml' => Wrest::Components::Translators::Xml,
|
16
16
|
'application/json' => Wrest::Components::Translators::Json,
|
17
|
-
'text/javascript' => Wrest::Components::Translators::Json
|
17
|
+
'text/javascript' => Wrest::Components::Translators::Json,
|
18
|
+
'text/plain' => Wrest::Components::Translators::Txt
|
18
19
|
}
|
19
20
|
end
|
20
21
|
end
|
@@ -13,13 +13,21 @@ module Wrest
|
|
13
13
|
module Translators::Json
|
14
14
|
extend self
|
15
15
|
|
16
|
-
def deserialise(response,options = {})
|
16
|
+
def deserialise(response, options = {})
|
17
17
|
ActiveSupport::JSON.decode(response.body)
|
18
18
|
end
|
19
19
|
|
20
|
+
def deserialize(response, options = {})
|
21
|
+
deserialise(response, options)
|
22
|
+
end
|
23
|
+
|
20
24
|
def serialise(hash, options = {})
|
21
25
|
hash.to_json(options)
|
22
26
|
end
|
27
|
+
|
28
|
+
def serialize(hash, options = {})
|
29
|
+
serialise(hash, options)
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright 2009 Sidu Ponnappa
|
2
|
+
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
7
|
+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
8
|
+
# See the License for the specific language governing permissions and limitations under the License.
|
9
|
+
module Wrest
|
10
|
+
module Components::Translators
|
11
|
+
module Txt
|
12
|
+
extend self
|
13
|
+
|
14
|
+
def deserialise(response,options={})
|
15
|
+
response.body
|
16
|
+
end
|
17
|
+
|
18
|
+
def deserialize(response, options = {})
|
19
|
+
deserialise(response, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def serialise(hash, options = {})
|
23
|
+
hash.inspect
|
24
|
+
end
|
25
|
+
|
26
|
+
def serialize(hash, options = {})
|
27
|
+
serialise(hash, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -19,9 +19,17 @@ module Wrest
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def deserialize(response, options = {})
|
23
|
+
deserialise(response, options)
|
24
|
+
end
|
25
|
+
|
22
26
|
def serialise(hash, options = {})
|
23
27
|
hash.to_xml(options)
|
24
28
|
end
|
29
|
+
|
30
|
+
def serialize(hash, options = {})
|
31
|
+
serialise(hash, options)
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -23,6 +23,7 @@ module Wrest
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
require "
|
27
|
-
require "
|
28
|
-
require "
|
26
|
+
require "wrest/components/translators/txt"
|
27
|
+
require "wrest/components/translators/xml"
|
28
|
+
require "wrest/components/translators/json"
|
29
|
+
require "wrest/components/translators/content_types"
|
data/lib/wrest/components.rb
CHANGED
data/lib/wrest/core_ext/hash.rb
CHANGED
data/lib/wrest/curl/response.rb
CHANGED
@@ -37,12 +37,20 @@ module Wrest #:nodoc:
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def deserialise(options = {})
|
40
|
-
|
40
|
+
@deserialised_body ||= deserialise_using(Wrest::Components::Translators.lookup(content_type),options)
|
41
41
|
end
|
42
|
-
|
43
|
-
def
|
42
|
+
|
43
|
+
def deserialize(options = {})
|
44
|
+
deserialise(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def deserialise_using(translator, options={})
|
44
48
|
translator.deserialise(@http_response,options)
|
45
49
|
end
|
50
|
+
|
51
|
+
def deserialize_using(options = {})
|
52
|
+
deserialise_using(options)
|
53
|
+
end
|
46
54
|
|
47
55
|
def code
|
48
56
|
@http_response.status
|
data/lib/wrest/curl.rb
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
# See the License for the specific language governing permissions and limitations under the License.
|
9
9
|
|
10
10
|
begin
|
11
|
-
gem 'patron', '~> 0.4
|
11
|
+
gem 'patron', '~> 0.4'
|
12
12
|
rescue Gem::LoadError => e
|
13
|
-
Wrest.logger.debug "Patron ~> 0.4.
|
13
|
+
Wrest.logger.debug "Patron ~> 0.4.x not found. Patron is necessary to use libcurl. To install Patron run `sudo gem install patron` (patron is not available on JRuby, but you shouldn't need it anyway)."
|
14
14
|
raise e
|
15
15
|
end
|
16
16
|
require 'patron'
|
@@ -39,13 +39,13 @@ module Patron #:nodoc:
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
require "
|
43
|
-
require "
|
44
|
-
require "
|
45
|
-
require "
|
46
|
-
require "
|
47
|
-
require "
|
48
|
-
require "
|
49
|
-
require "
|
50
|
-
require "
|
51
|
-
# require "
|
42
|
+
require "wrest/curl/response"
|
43
|
+
require "wrest/curl/request"
|
44
|
+
require "wrest/curl/get"
|
45
|
+
require "wrest/curl/put"
|
46
|
+
require "wrest/curl/post"
|
47
|
+
require "wrest/curl/delete"
|
48
|
+
require "wrest/curl/options"
|
49
|
+
require "wrest/curl/post_multipart"
|
50
|
+
require "wrest/curl/put_multipart"
|
51
|
+
# require "wrest/curl/session"
|
data/lib/wrest/http_shared.rb
CHANGED
@@ -14,9 +14,9 @@ module Wrest
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
require "
|
18
|
-
require "
|
19
|
-
require "
|
17
|
+
require "wrest/http_shared/headers"
|
18
|
+
require "wrest/http_shared/standard_headers"
|
19
|
+
require "wrest/http_shared/standard_tokens"
|
20
20
|
|
21
21
|
# Set up a shorter convenience API for constants
|
22
22
|
Wrest::H = Wrest::HttpShared::StandardHeaders
|
data/lib/wrest/multipart.rb
CHANGED
@@ -50,7 +50,6 @@ module Wrest
|
|
50
50
|
# This implementation of asynchronous post_multipart is currently in alpha. Hence, it should not be used in production.
|
51
51
|
def post_multipart_async(parameters = {}, headers = {}, &block)
|
52
52
|
(@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PostMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
|
53
|
-
nil
|
54
53
|
end
|
55
54
|
|
56
55
|
# Makes a multipart/form-data encoded PUT request to this URI. This is a convenience API
|
@@ -66,7 +65,6 @@ module Wrest
|
|
66
65
|
# This implementation of asynchronous put_multipart is currently in alpha. Hence, it should not be used in production.
|
67
66
|
def put_multipart_async(parameters = {}, headers = {}, &block)
|
68
67
|
(@options[:asynchronous_backend] || Wrest::AsyncRequest.default_backend).execute(Http::PutMultipart.new(self, parameters, headers, block ? @options.merge(:callback_block => block) : @options))
|
69
|
-
nil
|
70
68
|
end
|
71
69
|
end
|
72
70
|
|
@@ -74,13 +74,21 @@ module Wrest #:nodoc:
|
|
74
74
|
|
75
75
|
|
76
76
|
def deserialise(options = {})
|
77
|
-
|
77
|
+
@deserialised_body ||= deserialise_using(Wrest::Components::Translators.lookup(@http_response.content_type),options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def deserialize(options = {})
|
81
|
+
deserialise(options)
|
78
82
|
end
|
79
83
|
|
80
84
|
def deserialise_using(translator,options = {})
|
81
85
|
translator.deserialise(@http_response,options)
|
82
86
|
end
|
83
87
|
|
88
|
+
def deserialize_using(options = {})
|
89
|
+
deserialise_using(options)
|
90
|
+
end
|
91
|
+
|
84
92
|
# Gives a hash of the response headers. The keys of the hash are case-insensitive.
|
85
93
|
def headers
|
86
94
|
return @headers if @headers
|
data/lib/wrest/native.rb
CHANGED
@@ -18,16 +18,16 @@ module Wrest
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
require "
|
22
|
-
require "
|
23
|
-
require "
|
24
|
-
require "
|
25
|
-
require "
|
26
|
-
require "
|
27
|
-
require "
|
28
|
-
require "
|
29
|
-
require "
|
30
|
-
require "
|
21
|
+
require "wrest/native/connection_factory"
|
22
|
+
require "wrest/native/response"
|
23
|
+
require "wrest/native/redirection"
|
24
|
+
require "wrest/native/request"
|
25
|
+
require "wrest/native/get"
|
26
|
+
require "wrest/native/put"
|
27
|
+
require "wrest/native/post"
|
28
|
+
require "wrest/native/delete"
|
29
|
+
require "wrest/native/options"
|
30
|
+
require "wrest/native/session"
|
31
31
|
|
32
32
|
# default to using Native libs
|
33
33
|
Wrest::Http = Wrest::Native
|
data/lib/wrest/test.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "
|
1
|
+
require "wrest/test/request_patches"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Wrest
|
2
|
+
class Uri
|
3
|
+
# Contains methods that depend on Uri#clone to build
|
4
|
+
# new Uris configured in particular ways.
|
5
|
+
module Builders
|
6
|
+
# Returns a Uri object that uses threads to perform asynchronous requests.
|
7
|
+
def using_threads
|
8
|
+
clone(:asynchronous_backend => Wrest::AsyncRequest::ThreadBackend.new)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns a Uri object that uses eventmachine to perform asynchronous requests.
|
12
|
+
# Remember to do Wrest::AsyncRequest.enable_em first so that
|
13
|
+
# EventMachine is available for use.
|
14
|
+
def using_em
|
15
|
+
clone(:asynchronous_backend => Wrest::AsyncRequest::EventMachineBackend.new)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a Uri object that uses hash for caching responses.
|
19
|
+
def using_hash
|
20
|
+
clone(:cache_store => {})
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns a Uri object that uses memcached for caching responses.
|
24
|
+
# Remember to do Wrest::AsyncRequest.enable_memcached first so that
|
25
|
+
# memcached is available for use.
|
26
|
+
def using_memcached
|
27
|
+
clone(:cache_store => Wrest::Caching::Memcached.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Disables using the globally configured cache for GET requests
|
31
|
+
# made using the Uri returned by this method.
|
32
|
+
def disable_cache
|
33
|
+
clone(:disable_cache => true)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sets the specified string as the cookie for the Uri
|
37
|
+
def using_cookie(cookie_string)
|
38
|
+
clone(:default_headers => {Wrest::H::Cookie => cookie_string})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|