Module: Rest

Defined in:
lib/rest/wrappers/base_wrapper.rb,
lib/rest.rb,
lib/rest/client.rb,
lib/rest/errors.rb,
lib/rest/version.rb,
lib/rest/wrappers/excon_wrapper.rb,
lib/rest/wrappers/typhoeus_wrapper.rb,
lib/rest/wrappers/rest_client_wrapper.rb,
lib/rest/wrappers/internal_client_wrapper.rb,
lib/rest/wrappers/net_http_persistent_wrapper.rb,
lib/rest/wrappers/internal_client/internal/mimes.rb,
lib/rest/wrappers/internal_client/internal_client.rb,
lib/rest/wrappers/internal_client/internal/payload.rb,
lib/rest/wrappers/internal_client/internal/request.rb,
lib/rest/wrappers/internal_client/internal/resource.rb,
lib/rest/wrappers/internal_client/internal/response.rb,
lib/rest/wrappers/internal_client/internal/exceptions.rb,
lib/rest/wrappers/internal_client/internal/raw_response.rb,
lib/rest/wrappers/internal_client/internal/abstract_response.rb

Overview

This module’s static methods are the entry point for using the REST client.

# GET
xml = InternalClient.get 'http://example.com/resource'
jpg = InternalClient.get 'http://example.com/resource', :accept => 'image/jpg'

# authentication and SSL
InternalClient.get 'https://user:[email protected]/private/resource'

# POST or PUT with a hash sends parameters as a urlencoded form body
InternalClient.post 'http://example.com/resource', :param1 => 'one'

# nest hash parameters
InternalClient.post 'http://example.com/resource', :nested => { :param1 => 'one' }

# POST and PUT with raw payloads
InternalClient.post 'http://example.com/resource', 'the post body', :content_type => 'text/plain'
InternalClient.post 'http://example.com/resource.xml', xml_doc
InternalClient.put 'http://example.com/resource.pdf', File.read('my.pdf'), :content_type => 'application/pdf'

# DELETE
InternalClient.delete 'http://example.com/resource'

# retreive the response http code and headers
res = InternalClient.get 'http://example.com/some.jpg'
res.code                    # => 200
res.headers[:content_type]  # => 'image/jpg'

# HEAD
InternalClient.head('http://example.com').headers

To use with a proxy, just set InternalClient.proxy to the proper http proxy:

InternalClient.proxy = "http://proxy.example.com/"

Or inherit the proxy from the environment:

InternalClient.proxy = ENV['http_proxy']

For live tests of InternalClient, try using rest-test.heroku.com, which echoes back information about the rest call:

>> InternalClient.put 'http://rest-test.heroku.com/resource', :foo => 'baz'
=> "PUT http://rest-test.heroku.com/resource with a 7 byte payload, content type application/x-www-form-urlencoded {\"foo\"=>\"baz\"}"

Defined Under Namespace

Modules: InternalClient, Wrappers Classes: BackingGem, BaseResponseWrapper, BaseWrapper, Client, ClientError, HttpError, InvalidResponseError, RestError, TimeoutError

Constant Summary collapse

VERSION =
"3.0.8"
@@logger =
Logger.new(STDOUT)
@@backing_gems =

setup metadata about backing gem options

{}

Class Method Summary collapse

Class Method Details

.backing_gemsObject



46
47
48
# File 'lib/rest/client.rb', line 46

def self.backing_gems
  @@backing_gems
end

.loggerObject



24
25
26
# File 'lib/rest/client.rb', line 24

def self.logger()
  @@logger
end

.logger=(logger) ⇒ Object



20
21
22
# File 'lib/rest/client.rb', line 20

def self.logger=(logger)
  @@logger = logger
end

.ruby_majorObject



2
3
4
# File 'lib/rest.rb', line 2

def self.ruby_major
  RUBY_VERSION.split('.')[0].to_i
end

.ruby_minorObject



5
6
7
# File 'lib/rest.rb', line 5

def self.ruby_minor
  RUBY_VERSION.split('.')[1].to_i
end