Skip to content

Commit

Permalink
Ruby 1.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
iced committed Jan 14, 2013
1 parent 48537b7 commit 6ac24da
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 39 deletions.
28 changes: 15 additions & 13 deletions Gemfile.lock
@@ -1,37 +1,39 @@
PATH
remote: .
specs:
rest (2.1.0)
rest (2.2.0)
net-http-persistent
rest-client (>= 0.3.0)

GEM
remote: https://rubygems.org/
specs:
excon (0.16.3)
ffi (1.1.5)
ethon (0.5.7)
ffi (~> 1.2.0)
mime-types (~> 1.18)
excon (0.16.10)
ffi (1.2.1)
mime-types (1.19)
minitest (3.5.0)
minitest (4.4.0)
net-http-persistent (2.8)
quicky (0.1.1)
rake (0.9.2.2)
quicky (0.4.0)
rake (10.0.3)
rest-client (1.6.7)
mime-types (>= 1.16)
test-unit (2.5.2)
typhoeus (0.4.2)
ffi (~> 1.0)
mime-types (~> 1.18)
uber_config (0.0.6)
test-unit (2.5.3)
typhoeus (0.5.4)
ethon (~> 0.5.7)
uber_config (1.0.5)

PLATFORMS
ruby

DEPENDENCIES
excon
minitest
quicky
quicky (>= 0.4.0)
rake
rest!
test-unit
typhoeus
typhoeus (>= 0.5.4)
uber_config
2 changes: 1 addition & 1 deletion lib/rest.rb
@@ -1 +1 @@
require_relative 'rest/client'
require 'rest/client'
17 changes: 11 additions & 6 deletions lib/rest/client.rb
@@ -1,15 +1,20 @@
if RUBY_VERSION.split('.')[1].to_i == 8
require 'rubygems'
gem 'json'
end

require 'json'
require 'logger'

# This is a simple wrapper that can use different http clients depending on what's installed.
# The purpose of this is so that users who can't install binaries easily (like windoze users)
# can have fallbacks that work.

require_relative 'errors'
require 'rest/errors'

module Rest

require_relative 'wrappers/base_wrapper'
require 'rest/wrappers/base_wrapper'

def self.logger=(logger)
@logger = logger
Expand Down Expand Up @@ -39,15 +44,15 @@ def initialize(options={})
end

if @gem == :excon
require_relative 'wrappers/excon_wrapper'
require 'rest/wrappers/excon_wrapper'
@wrapper = Rest::Wrappers::ExconWrapper.new(self)
@logger.debug "Using excon gem."
elsif @gem == :typhoeus
require_relative 'wrappers/typhoeus_wrapper'
require 'rest/wrappers/typhoeus_wrapper'
@wrapper = Rest::Wrappers::TyphoeusWrapper.new
@logger.debug "Using typhoeus gem."
elsif @gem == :net_http_persistent
require_relative 'wrappers/net_http_persistent_wrapper'
require 'rest/wrappers/net_http_persistent_wrapper'
@wrapper = Rest::Wrappers::NetHttpPersistentWrapper.new(self)
@logger.debug "Using net-http-persistent gem."
else
Expand Down Expand Up @@ -129,7 +134,7 @@ def perform_op(method, req_hash, options={}, &blk)

pow = (4 ** (current_retry)) * 100 # milliseconds
#puts 'pow=' + pow.to_s
s = Random.rand * pow
s = rand * pow
#puts 's=' + s.to_s
sleep_secs = 1.0 * s / 1000.0
#puts 'sleep for ' + sleep_secs.to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/rest/version.rb
@@ -1,3 +1,3 @@
module Rest
VERSION = "2.1.1"
VERSION = "2.2.0"
end
3 changes: 2 additions & 1 deletion lib/rest/wrappers/base_wrapper.rb
Expand Up @@ -53,4 +53,5 @@ def headers
end

# we need it for post_file, ok as gem already depends on it
require_relative 'rest_client_wrapper'
require 'rest/wrappers/rest_client_wrapper'

6 changes: 3 additions & 3 deletions lib/rest/wrappers/typhoeus_wrapper.rb
Expand Up @@ -36,10 +36,10 @@ class TyphoeusWrapper < BaseWrapper
def default_typhoeus_options
req_hash = {}
# todo: should change this timeout to longer if it's for posting file
req_hash[:connect_timeout] = 5000
req_hash[:connecttimeout] = 5000
req_hash[:timeout] = 10000
req_hash[:follow_location] = true
req_hash[:max_redirects] = 2
req_hash[:followlocation] = true
req_hash[:maxredirs] = 2
req_hash
end

Expand Down
6 changes: 3 additions & 3 deletions rest.gemspec
Expand Up @@ -15,16 +15,16 @@ Gem::Specification.new do |gem|
gem.version = Rest::VERSION

gem.required_rubygems_version = ">= 1.3.6"
gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
gem.required_ruby_version = Gem::Requirement.new(">= 1.8")
gem.add_runtime_dependency "rest-client", ">= 0.3.0"
gem.add_runtime_dependency "net-http-persistent"

gem.add_development_dependency "test-unit"
gem.add_development_dependency "minitest"
gem.add_development_dependency "rake"
gem.add_development_dependency "uber_config"
gem.add_development_dependency "typhoeus"
gem.add_development_dependency "quicky"
gem.add_development_dependency "typhoeus", ">= 0.5.4"
gem.add_development_dependency "quicky", ">= 0.4.0"
gem.add_development_dependency "excon"

end
Expand Down
4 changes: 3 additions & 1 deletion test/test_base.rb
@@ -1,4 +1,3 @@
gem 'test-unit'
require 'test/unit'
require 'yaml'
begin
Expand All @@ -16,6 +15,9 @@ def setup

end

def test_fake
end

ALL_OPS = [:get, :put, :post, :delete]


Expand Down
3 changes: 1 addition & 2 deletions test/test_performance.rb
@@ -1,9 +1,8 @@
gem 'test-unit'
require 'test/unit'
require 'yaml'
require 'quicky'

require_relative 'test_base'
require 'test_base'

class TestPerformance < TestBase
def setup
Expand Down
9 changes: 4 additions & 5 deletions test/test_rest.rb
@@ -1,9 +1,8 @@
# Put config.yml file in ~/Dropbox/configs/ironmq_gem/test/config.yml

gem 'test-unit'
require 'test/unit'
require 'yaml'
require_relative 'test_base'
require 'test_base'

class TestRest < TestBase
def setup
Expand All @@ -17,11 +16,11 @@ def test_basics
p response.code
assert response.code == 200
p response.body
assert response.body.include?("Social Coding")
assert response.body.include?("Explore GitHub")
end

def test_backoff
response = @rest.get("http://rest-test.iron.io/code/503?switch_after=3&switch_to=200")
response = @rest.get("http://rest-test.iron.io/code/503?switch_after=2&switch_to=200")
p response
p response.code
assert response.tries == 3
Expand Down Expand Up @@ -159,7 +158,7 @@ def test_post_with_headers
end

def test_form_post
r = @rest.post("http://google.com/search", :params=>{q: "Rick Astley"})
r = @rest.post("http://google.com/search", :params=>{:q => "Rick Astley"})
p r
end

Expand Down
5 changes: 2 additions & 3 deletions test/tmp.rb
@@ -1,7 +1,6 @@
gem 'test-unit'
require 'test/unit'
require 'yaml'
require_relative 'test_base'
require 'test_base'

class TestTemp < TestBase
def setup
Expand All @@ -11,7 +10,7 @@ def setup


def test_form_post
r = @rest.post("http://google.com/search", :params=>{q: "Rick Astley"})
r = @rest.post("http://google.com/search", :params=>{:q => "Rick Astley"})
p r
end

Expand Down

0 comments on commit 6ac24da

Please sign in to comment.