rest 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest (2.0.1)
4
+ rest (2.0.2)
5
5
  net-http-persistent
6
6
  rest-client (>= 0.3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- excon (0.15.4)
12
- ffi (1.1.0)
11
+ excon (0.16.3)
12
+ ffi (1.1.5)
13
13
  mime-types (1.19)
14
- minitest (3.2.0)
14
+ minitest (3.5.0)
15
15
  net-http-persistent (2.7)
16
- quicky (0.0.1)
16
+ quicky (0.1.1)
17
17
  rake (0.9.2.2)
18
18
  rest-client (1.6.7)
19
19
  mime-types (>= 1.16)
20
- test-unit (2.5.1)
20
+ test-unit (2.5.2)
21
21
  typhoeus (0.4.2)
22
22
  ffi (~> 1.0)
23
23
  mime-types (~> 1.18)
24
- uber_config (0.0.5)
24
+ uber_config (0.0.6)
25
25
 
26
26
  PLATFORMS
27
27
  ruby
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ Rake::RDocTask.new do |rdoc|
16
16
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
17
17
 
18
18
  rdoc.rdoc_dir = 'doc'
19
- rdoc.title = "iron_mq #{version}"
19
+ rdoc.title = "rest #{version}"
20
20
  rdoc.rdoc_files.include('README*')
21
21
  rdoc.rdoc_files.include('lib/**/*.rb')
22
22
  end
@@ -11,6 +11,14 @@ module Rest
11
11
 
12
12
  require_relative 'wrappers/base_wrapper'
13
13
 
14
+ def self.logger=(logger)
15
+ @logger = logger
16
+ end
17
+
18
+ def self.logger()
19
+ @logger
20
+ end
21
+
14
22
  class Client
15
23
 
16
24
  attr_accessor :options, :logger, :gem
@@ -18,9 +26,9 @@ module Rest
18
26
  # - :gem => specify gem explicitly
19
27
  #
20
28
  def initialize(options={})
21
- @logger = Logger.new(STDOUT)
22
- @logger.level=Logger::INFO
23
29
  @options = options
30
+ @logger = Logger.new(STDOUT)
31
+ Rest.logger = @logger
24
32
 
25
33
  @gem = options[:gem] if options[:gem]
26
34
 
@@ -1,3 +1,3 @@
1
1
  module Rest
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
@@ -13,6 +13,14 @@ module Rest
13
13
  class NetHttpPersistentResponseWrapper < BaseResponseWrapper
14
14
  def initialize(response)
15
15
  @response = response
16
+
17
+ if response.header['content-encoding'].eql?('gzip')
18
+ Rest.logger.debug 'GZIPPED'
19
+ sio = StringIO.new( response.body )
20
+ gz = Zlib::GzipReader.new( sio )
21
+ page = gz.read()
22
+ @body = page
23
+ end
16
24
  end
17
25
 
18
26
  def code
@@ -20,6 +28,11 @@ module Rest
20
28
  end
21
29
 
22
30
  def body
31
+ @body || @response.body
32
+ end
33
+
34
+ # In case for some reason you want the unencoded body
35
+ def body_raw
23
36
  @response.body
24
37
  end
25
38
 
@@ -79,7 +92,11 @@ module Rest
79
92
  post = Net::HTTP::Get.new fix_path(uri.request_uri)
80
93
  add_headers(post, req_hash, default_headers)
81
94
  response = http.request uri, post
82
- @client.logger.debug response.class.name
95
+ if @client.logger.debug?
96
+ @client.logger.debug "Response class: #{response.class.name}"
97
+ @client.logger.debug "Response headers: #{response.header.to_hash.inspect}"
98
+ end
99
+
83
100
  r = NetHttpPersistentResponseWrapper.new(response)
84
101
  case response
85
102
  when Net::HTTPClientError, Net::HTTPServerError
@@ -92,13 +109,13 @@ module Rest
92
109
  # @client.logger.debug "moved to #{response['location']}"
93
110
  # response = get(response['location'], req_hash, {limit: options[:limit]-1})
94
111
  #end
95
- #rescue Net::HTTPClientError, Net::HTTPServerError => ex
96
- # raise NetHttpPersistentExceptionWrapper.new(ex)
97
- #rescue Net::HTTPServerError => ex
98
- # if ex.code == 404
99
- # return NetHttpPersistentResponseWrapper.new(ex)
100
- # end
101
- # raise NetHttpPersistentExceptionWrapper.new(ex)
112
+ #rescue Net::HTTPClientError, Net::HTTPServerError => ex
113
+ # raise NetHttpPersistentExceptionWrapper.new(ex)
114
+ #rescue Net::HTTPServerError => ex
115
+ # if ex.code == 404
116
+ # return NetHttpPersistentResponseWrapper.new(ex)
117
+ # end
118
+ # raise NetHttpPersistentExceptionWrapper.new(ex)
102
119
  end
103
120
  r
104
121
  end
@@ -12,8 +12,7 @@ class TestBase < Test::Unit::TestCase
12
12
 
13
13
  def setup
14
14
  puts 'setup'
15
- @rest = Rest::Client.new(:gem => :net_http_persistent)
16
- @rest.logger.level = Logger::DEBUG
15
+ @rest = Rest::Client.new(:gem => :net_http_persistent, :log_level=>Logger::DEBUG)
17
16
  @request_bin = "http://requestb.in/13t6hs51"
18
17
 
19
18
  end
@@ -47,19 +47,6 @@ class TestRest < TestBase
47
47
  end
48
48
 
49
49
  def test_gets
50
- @token = "abctoken"
51
- headers = {
52
- 'Content-Type' => 'application/json',
53
- 'Authorization' => "OAuth #{@token}",
54
- 'User-Agent' => "someagent"
55
- }
56
- body = {"foo" => "bar"}
57
- response = @rest.get("#{bin}?param1=x")
58
-
59
- # params as hash
60
- response = @rest.get("#{bin}?x=y#frag", :params => {:param2 => "abc"})
61
- response = @rest.get("#{bin}", :params => {param3: "xyz"})
62
- response = @rest.get("#{bin}")
63
50
 
64
51
  response = @rest.get("http://rest-test.iron.io/code/200")
65
52
  assert response.code == 200
@@ -70,6 +57,7 @@ class TestRest < TestBase
70
57
  end
71
58
 
72
59
  def test_404
60
+ puts 'test_404'
73
61
  begin
74
62
  response = @rest.get("http://rest-test.iron.io/code/404")
75
63
  assert false, "shouldn't get here"
@@ -86,6 +74,7 @@ class TestRest < TestBase
86
74
  end
87
75
 
88
76
  def test_400
77
+ puts 'test_400'
89
78
  begin
90
79
  response = @rest.get("http://rest-test.iron.io/code/400")
91
80
  assert false, "shouldn't get here"
@@ -141,5 +130,17 @@ class TestRest < TestBase
141
130
 
142
131
  end
143
132
 
133
+ def test_gzip
134
+
135
+ options = {}
136
+ url = "http://api.stackexchange.com/2.1/users?order=desc&sort=reputation&site=stackoverflow"
137
+ rest = Rest::Client.new
138
+
139
+ res = rest.get(url, options)
140
+
141
+ puts res.body
142
+ assert res.body.include?("items")
143
+ end
144
+
144
145
  end
145
146
 
@@ -9,19 +9,16 @@ class TestTemp < TestBase
9
9
 
10
10
  end
11
11
 
12
- def test_500
13
- puts '500'
14
- begin
15
- puts 'in block'
16
- response = @rest.get("http://rest-test.iron.io/code/500")
17
- assert false, "shouldn't get here"
18
- rescue => ex
19
- p ex
20
- assert ex.is_a?(Rest::HttpError)
21
- assert ex.response
22
- assert ex.response.body
23
- assert ex.code == 500
24
- end
12
+ def test_gzip
13
+
14
+ options = {}
15
+ url = "http://api.stackexchange.com/2.1/users?order=desc&sort=reputation&site=stackoverflow"
16
+ rest = Rest::Client.new
17
+
18
+ res = rest.get(url, options)
19
+
20
+ puts res.body
21
+ assert res.body.include?("items")
25
22
  end
26
23
  end
27
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client