Class: ActiveRestClient::Connection
- Inherits:
- 
      Object
      
        - Object
- ActiveRestClient::Connection
 
- Defined in:
- lib/active_rest_client/connection.rb
Instance Attribute Summary collapse
- 
  
    
      #base_url  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute base_url. 
- 
  
    
      #session  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute session. 
Instance Method Summary collapse
- #delete(path, headers = {}) ⇒ Object
- #get(path, headers = {}) ⇒ Object
- #headers ⇒ Object
- 
  
    
      #initialize(base_url)  ⇒ Connection 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Connection. 
- #make_safe_request(path, &block) ⇒ Object
- #post(path, data, headers = {}) ⇒ Object
- #put(path, data, headers = {}) ⇒ Object
- #reconnect ⇒ Object
Constructor Details
#initialize(base_url) ⇒ Connection
Returns a new instance of Connection.
| 11 12 13 14 | # File 'lib/active_rest_client/connection.rb', line 11 def initialize(base_url) @base_url = base_url @session = new_session end | 
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
| 9 10 11 | # File 'lib/active_rest_client/connection.rb', line 9 def base_url @base_url end | 
#session ⇒ Object
Returns the value of attribute session.
| 9 10 11 | # File 'lib/active_rest_client/connection.rb', line 9 def session @session end | 
Instance Method Details
#delete(path, headers = {}) ⇒ Object
| 66 67 68 69 70 71 72 73 | # File 'lib/active_rest_client/connection.rb', line 66 def delete(path, headers={}) make_safe_request(path) do @session.delete(path) do |req| req.headers = req.headers.merge(headers) sign_request(req) end end end | 
#get(path, headers = {}) ⇒ Object
| 37 38 39 40 41 42 43 44 | # File 'lib/active_rest_client/connection.rb', line 37 def get(path, headers={}) make_safe_request(path) do @session.get(path) do |req| req.headers = req.headers.merge(headers) sign_request(req) end end end | 
#headers ⇒ Object
| 20 21 22 | # File 'lib/active_rest_client/connection.rb', line 20 def headers @session.headers end | 
#make_safe_request(path, &block) ⇒ Object
| 24 25 26 27 28 29 30 31 32 33 34 35 | # File 'lib/active_rest_client/connection.rb', line 24 def make_safe_request(path, &block) block.call rescue Faraday::Error::TimeoutError raise ActiveRestClient::TimeoutException.new("Timed out getting #{full_url(path)}") rescue Faraday::Error::ConnectionFailed begin reconnect block.call rescue Faraday::Error::ConnectionFailed raise ActiveRestClient::ConnectionFailedException.new("Unable to connect to #{full_url(path)}") end end | 
#post(path, data, headers = {}) ⇒ Object
| 56 57 58 59 60 61 62 63 64 | # File 'lib/active_rest_client/connection.rb', line 56 def post(path, data, headers={}) make_safe_request(path) do @session.post(path) do |req| req.headers = req.headers.merge(headers) req.body = data sign_request(req) end end end | 
#put(path, data, headers = {}) ⇒ Object
| 46 47 48 49 50 51 52 53 54 | # File 'lib/active_rest_client/connection.rb', line 46 def put(path, data, headers={}) make_safe_request(path) do @session.put(path) do |req| req.headers = req.headers.merge(headers) req.body = data sign_request(req) end end end | 
#reconnect ⇒ Object
| 16 17 18 | # File 'lib/active_rest_client/connection.rb', line 16 def reconnect @session = new_session end |