wrest 2.1.7 → 2.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 091ff99d9b7472c8cfcf9a27a0ea15b265109c4e
4
- data.tar.gz: 79e6ef34679174763066b807603f1bbf6dac011d
3
+ metadata.gz: 69a30e75377430e134d3be264b50b1e97e823152
4
+ data.tar.gz: f721a616192a527d21afa74c0adba3dd3dfd5b41
5
5
  SHA512:
6
- metadata.gz: cbb24475f771990b01557028d14b779d1c456b0b15e271974e5542929694fb2fa39e8137851de5870b9f8ad4090965fc3f095d47e7a40b27e3fd75162d1ec8d8
7
- data.tar.gz: 0306fa8fba478fbfb0404d1fbefa3c4d69adf0c9391941c27035f38b45129544e98aecb1f6a7a51ad4fabfd2bf9d5671e0f3b067073364e0320a15f6348e540a
6
+ metadata.gz: 94db9fae0c8540e80497fb182b2d8634fbc6fdc8e7fd374fe13931b348244513ffaab8128c76369a92b2fb45bd018cbd7817d6529fc80b4ad5077f085fb47165
7
+ data.tar.gz: 1e411d00090ff33e317774678a9072b20689862f3e2879715f4b5d95baea7b90459a52d7a0e00e21a85b9ac9922d55305018dcf83d99c21ca0eca04e2d83a4ce
data/CHANGELOG CHANGED
@@ -2,6 +2,9 @@ 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
+ == 2.1.9
6
+ * Switch to using concurrent-ruby
7
+
5
8
  == 2.1.6
6
9
  * Logging payload by default
7
10
 
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  [![Build Status](https://travis-ci.org/c42/wrest.svg?branch=master)](https://travis-ci.org/c42/wrest)
2
2
 
3
- # Wrest 2.1.4
3
+ # Wrest 2.1.9
4
4
 
5
5
  (c) Copyright 2009-2016 [Sidu Ponnappa](http://twitter.com/ponnappa). All Rights Reserved.
6
6
 
7
7
  Wrest is a ruby REST/HTTP client library which
8
8
 
9
9
  * Allows you to use Net::HTTP
10
- * Allows you to pick your Ruby: use 2.x.x, JRuby 1.7.6 (and higher), JRuby 9.0.0.0.pre2
10
+ * Allows you to pick your Ruby: use 2.x.x, JRuby 9.x.x
11
11
  * Supports RFC 2616 based [caching](https://github.com/kaiwren/wrest/blob/caching/Caching.markdown)
12
12
  * Async http calls using Threads (reliable only on JRuby) or EventMachine
13
13
  * Allows you to quickly build object oriented wrappers around any web service
@@ -37,15 +37,15 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
37
37
  * Timeout support
38
38
 
39
39
  ```
40
- 'https://api.github.com/repos/c42/wrest/issues'.to_uri.get(:timeout => 5).body
40
+ 'https://api.github.com/repos/c42/wrest/issues'.to_uri.get(timeout: 5).body
41
41
  ```
42
42
 
43
43
  * Redirect support
44
44
 
45
45
  ```
46
- 'http://google.com'.to_uri(:follow_redirects => false).get
46
+ 'http://google.com'.to_uri(follow_redirects: false).get
47
47
 
48
- 'http://google.com'.to_uri(:follow_redirects_limit => 1).get
48
+ 'http://google.com'.to_uri(follow_redirects_limit: 1).get
49
49
  ```
50
50
 
51
51
  :follow_redirects_limit defaults to 5 if not specified.
@@ -56,7 +56,7 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
56
56
  ActiveSupport::XmlMini.backend = 'REXML'
57
57
 
58
58
  'http://twitter.com/statuses/public_timeline.xml'.to_uri.get.deserialise(
59
- :xpath => '//user/name/text()'
59
+ xpath: '//user/name/text()'
60
60
  )
61
61
  ```
62
62
 
@@ -64,8 +64,8 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
64
64
 
65
65
  ```
66
66
  'api.openweathermap.org/data/2.5/weather'.to_uri.get(
67
- :lat => 35,
68
- :lon => 139
67
+ lat: 35,
68
+ lon: 139
69
69
  ).deserialise_using(
70
70
  Wrest::Components::Translators::Xml
71
71
  )
@@ -74,10 +74,16 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
74
74
  * Basic HTTP auth and URI extensions using Wrest::Uri#[]
75
75
 
76
76
  ```
77
- base_uri = 'https://api.del.icio.us/v1'.to_uri(:username => 'kaiwren', :password => 'fupupp1es')
77
+ base_uri = 'https://api.del.icio.us/v1'.to_uri(username: 'kaiwren', password: 'fupupp1es')
78
78
  bookmarks = base_uri['/posts/get'].get.deserialise
79
79
  ```
80
80
 
81
+ * Detailed debugging and logging (NOT FOR USE IN PRODUCTION! SEE API DOCS!)
82
+
83
+ ```
84
+ 'https://api.github.com/repos/c42/wrest/issues'.to_uri(detailed_http_logging: $stdout).get.deserialize
85
+ ```
86
+
81
87
  #### POST
82
88
 
83
89
  * Regular, vanilla Post with a body and headers
@@ -90,12 +96,12 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
90
96
 
91
97
  ```
92
98
  'https://api.del.icio.us/v1/posts/add'.to_uri(
93
- :username => 'kaiwren', :password => 'fupupp1es'
99
+ username: 'kaiwren', password: 'fupupp1es'
94
100
  ).post_form(
95
- :url => 'http://blog.sidu.in/search/label/ruby',
96
- :description => 'The Ruby related posts on my blog!',
97
- :extended => "All posts tagged with 'ruby'",
98
- :tags => 'ruby hacking'
101
+ url: 'http://blog.sidu.in/search/label/ruby',
102
+ description: 'The Ruby related posts on my blog!',
103
+ extended: "All posts tagged with 'ruby'",
104
+ tags: 'ruby hacking'
99
105
  )
100
106
  ```
101
107
 
@@ -103,8 +109,8 @@ For Facebook, Twitter, Delicious, GitHub and other API examples, see http://gith
103
109
 
104
110
  ```
105
111
  'http://imgur.com/api/upload.xml'.to_uri.post_multipart(
106
- :image => UploadIO.new(File.open(file_path), "image/png", file_path),
107
- :key => imgur_key
112
+ image: UploadIO.new(File.open(file_path), "image/png", file_path),
113
+ key: imgur_key
108
114
  ).deserialise
109
115
  ```
110
116
 
@@ -116,13 +122,14 @@ To delete a resource:
116
122
 
117
123
  ```
118
124
  'https://api.del.icio.us/v1/posts/delete'.to_uri(
119
- :username => 'kaiwren',
120
- :password => 'fupupp1es'
125
+ username: 'kaiwren',
126
+ password: 'fupupp1es'
121
127
  ).delete(
122
- :url => 'http://c2.com'
128
+ url: 'http://c2.com'
123
129
  )
124
130
  ```
125
131
 
132
+
126
133
  ### Caching
127
134
 
128
135
  Wrest supports caching with the following pluggable back-ends:
@@ -199,7 +206,7 @@ To explicitly disable caching for specific requests:
199
206
  You can define a set of callbacks that are invoked based on the http codes of the responses to any requests on a given uri.
200
207
 
201
208
  ```
202
- "http://google.com".to_uri(:callback => {
209
+ "http://google.com".to_uri(callback: {
203
210
  200 => lambda {|response| Wrest.logger.info "Ok." },
204
211
  400..499 => lambda {|response| Wrest.logger.error "Invalid. #{response.body}"},
205
212
  300..302 => lambda {|response| Wrest.logger.debug "Redirected. #{response.message}" }
@@ -339,6 +346,13 @@ The response log consists of request type that generated the response (POST), ha
339
346
 
340
347
  The thread id, request hash and connection hashes are used to track requests and their corresponding responses when using asynchronous requests and/or http connection pooling.
341
348
 
349
+ Detailed http debug logging can be turned on like so (DO NOT USE IN PRODUCTION! SEE API DOCS.):
350
+
351
+ ```
352
+ 'https://api.github.com/repos/c42/wrest/issues'.to_uri(detailed_http_logging: $stdout).get.deserialize
353
+ ```
354
+
355
+
342
356
  ### Json Backend
343
357
 
344
358
  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:
@@ -375,7 +389,7 @@ You can launch the interactive Wrest shell by running bin/wrest if you have the
375
389
 
376
390
  ```
377
391
  $ wrest
378
- >> y 'http://twitter.com/statuses/public_timeline.json'.to_uri(:timeout => 5).get.deserialise
392
+ >> y 'http://twitter.com/statuses/public_timeline.json'.to_uri(timeout: 5).get.deserialise
379
393
  ```
380
394
 
381
395
  ### Testing
@@ -11,56 +11,16 @@ module Wrest
11
11
  module AsyncRequest
12
12
  class ThreadPool
13
13
  def initialize(number_of_threads)
14
- @threads = []
15
- @number_of_threads = number_of_threads
16
- @queue = Queue.new
14
+ @pool = Concurrent::FixedThreadPool.new(number_of_threads)
17
15
  end
18
16
 
19
17
  def execute_eventually(request)
20
- initialize_thread_pool if @threads.empty?
21
- @queue.push(request)
18
+ @pool.post { request.invoke }
22
19
  nil
23
20
  end
24
21
 
25
22
  def join_pool_threads!
26
- @threads.each do |thread|
27
- thread.join if thread.alive?
28
- end
29
- end
30
-
31
- private
32
- def initialize_thread_pool
33
- halt_on_sigint
34
- halt_on_int
35
- main_thread = Thread.current
36
- @threads = @number_of_threads.times.map do |i|
37
- Thread.new do |thread|
38
- while request = @queue.pop
39
- request.invoke
40
- end
41
- end
42
- end
43
- end
44
-
45
- def halt_on_sigint
46
- trap('SIGINT') do
47
- halt
48
- end
49
- end
50
-
51
- def halt_on_int
52
- trap('INT') do
53
- halt
54
- end
55
- end
56
-
57
- def halt
58
- unless @threads.empty?
59
- Wrest.logger.debug "Wrest: Shutting down ThreadPool..."
60
- @threads.each(&:terminate)
61
- Wrest.logger.debug "Wrest: Halted ThreadPool, continuing with shutdown."
62
- end
63
- Process.exit
23
+ @pool.wait_for_termination
64
24
  end
65
25
  end
66
26
  end
@@ -13,7 +13,7 @@ module Wrest::Native
13
13
  # or Wrest::Native::Get etc. instead.
14
14
  class Request
15
15
  attr_reader :http_request, :uri, :body, :headers, :username, :password, :follow_redirects,
16
- :follow_redirects_limit, :follow_redirects_count, :timeout, :connection, :parameters,
16
+ :follow_redirects_limit, :follow_redirects_count, :timeout, :connection, :parameters,
17
17
  :cache_store, :verify_mode, :options, :ca_path
18
18
  # Valid tuples for the options are:
19
19
  # :username => String, defaults to nil
@@ -25,10 +25,10 @@ module Wrest::Native
25
25
  # For example, if you set this to 1, the very first redirect
26
26
  # will raise the exception.
27
27
  # :follow_redirects_count => Integer, defaults to 0. This is a count of the hops made to
28
- # get to this request and increases by one for every redirect
28
+ # get to this request and increases by one for every redirect
29
29
  # until the follow_redirects_limit is hit. You should never set
30
30
  # this option yourself.
31
- # :timeout => The period, in seconds, after which a Timeout::Error is raised
31
+ # :timeout => The period, in seconds, after which a Timeout::Error is raised
32
32
  # in the event of a connection failing to open. Defaulted to 60 by Uri#create_connection.
33
33
  # :connection => The HTTP Connection object to use. This is how a keep-alive connection can be
34
34
  # used for multiple requests.
@@ -38,7 +38,7 @@ module Wrest::Native
38
38
  # eg: { <response code> => lambda { |response| some_operation } }
39
39
  # The following options are Net::HTTP specific config options
40
40
  # :detailed_http_logging => nil/$stdout/$stderr or File/Logger/IO object. Defaults to nil (recommended).
41
- # *WARNING* : detailed_http_logging causes a serious security hole. Never use it in production code.
41
+ # *WARNING* : detailed_http_logging causes a serious security hole. Never use it in production code.
42
42
  # :verify_mode => The verification mode to be used for Net::HTTP https connections. Defaults to OpenSSL::SSL::VERIFY_PEER
43
43
  # :ca_path => The path to the certificates
44
44
  def initialize(wrest_uri, http_request_klass, parameters = {}, body = nil, headers = {}, options = {})
@@ -65,20 +65,20 @@ module Wrest::Native
65
65
 
66
66
  # Makes a request, runs the appropriate callback if any and
67
67
  # returns a Wrest::Native::Response.
68
- #
68
+ #
69
69
  # Data about the request is and logged to Wrest.logger
70
70
  # The log entry contains the following information:
71
71
  #
72
72
  # <- indicates a request
73
73
  # -> indicates a response
74
74
  #
75
- # The type of request is mentioned in caps, followed by a hash
75
+ # The type of request is mentioned in caps, followed by a hash
76
76
  # uniquely identifying a particular request/response pair.
77
77
  # In a multi-process or multi-threaded scenario, this can be used
78
78
  # to identify request-response pairs.
79
79
  #
80
80
  # The request hash is followed by a connection hash; requests using the
81
- # same connection (effectively a keep-alive connection) will have the
81
+ # same connection (effectively a keep-alive connection) will have the
82
82
  # same connection hash.
83
83
  #
84
84
  # This is followed by the response code, the payload size and the time taken.
@@ -89,15 +89,13 @@ module Wrest::Native
89
89
  http_request.basic_auth username, password unless username.nil? || password.nil?
90
90
 
91
91
  prefix = "#{http_request.method} #{self.hash} #{@connection.hash} #{Thread.current.object_id}"
92
-
92
+
93
93
  Wrest.logger.debug "<- (#{prefix}) #{@uri.protocol}://#{@uri.host}:#{@uri.port}#{@http_request.path}"
94
94
  Wrest.logger.debug "<- Body: #{@body}"
95
95
  time = Benchmark.realtime { response = Wrest::Native::Response.new( do_request ) }
96
- Wrest.logger.debug "-> (#{prefix}) %d %s (%d bytes %.2fs)" % [response.code, response.message, response.body ? response.body.length : 0, time]
97
- Wrest.logger.debug "#{response.body}"
98
96
 
99
97
  execute_callback_if_any(response)
100
-
98
+
101
99
  @follow_redirects ? response.follow(@options) : response
102
100
  rescue Timeout::Error => e
103
101
  raise Wrest::Exceptions::Timeout.new(e)
@@ -111,7 +109,7 @@ module Wrest::Native
111
109
  request_klass.new(parameters.empty? ? "#{uri.uri_path}" : "#{uri.uri_path}?#{parameters.to_query}", headers)
112
110
  end
113
111
  end
114
-
112
+
115
113
  #:nodoc:
116
114
  def do_request
117
115
  @connection.request(@http_request, @body)
data/lib/wrest/version.rb CHANGED
@@ -8,5 +8,5 @@
8
8
  # See the License for the specific language governing permissions and limitations under the License.
9
9
 
10
10
  module Wrest
11
- VERSION = "2.1.7"
11
+ VERSION = "2.1.9"
12
12
  end
data/lib/wrest.rb CHANGED
@@ -15,6 +15,7 @@ require 'base64'
15
15
  require 'logger'
16
16
  require 'benchmark'
17
17
  require 'multi_json'
18
+ require 'concurrent'
18
19
  require 'active_support'
19
20
  require 'active_support/core_ext/string'
20
21
  require 'active_support/core_ext/hash'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.7
4
+ version: 2.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sidu Ponnappa
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-22 00:00:00.000000000 Z
12
+ date: 2017-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -95,9 +95,37 @@ dependencies:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '1.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: concurrent-ruby
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: json
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.0'
98
126
  description: Wrest is a fluent, easy-to-use, object oriented Ruby HTTP/REST client
99
127
  library with support for RFC2616 HTTP caching, multiple HTTP backends and async
100
- calls using EventMachine. It runs on CRuby and JRuby.
128
+ calls. It runs on CRuby and JRuby and is in production use at substantial scale.
101
129
  email:
102
130
  - sidu@c42.in
103
131
  executables:
@@ -201,7 +229,7 @@ requirements:
201
229
  (and should be unneccessary) on jruby.
202
230
  - To use eventmachine as a parallel backend, install the 'eventmachine' gem.
203
231
  rubyforge_project: wrest
204
- rubygems_version: 2.4.5.1
232
+ rubygems_version: 2.6.8
205
233
  signing_key:
206
234
  specification_version: 4
207
235
  summary: Wrest is a fluent, object oriented HTTP client library for 2.x.x, JRuby 1.7.6