Class: HorizonClient::Connection
- Inherits:
-
Object
- Object
- HorizonClient::Connection
- Defined in:
- lib/horizon_client.rb
Instance Method Summary collapse
- #get(path = '', params = {}) ⇒ Object
-
#initialize(url = nil) ⇒ Connection
constructor
A new instance of Connection.
- #post(path = '', body) ⇒ Object
- #url_prefix ⇒ Object
Constructor Details
#initialize(url = nil) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/horizon_client.rb', line 19 def initialize(url = nil) url ||= ENV['HORIZON_REST_URL'] @connection = Faraday.new url do |conn| conn.response :raise_error conn.response :xml, :content_type => /\bxml$/ conn.adapter Faraday.default_adapter end end |
Instance Method Details
#get(path = '', params = {}) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/horizon_client.rb', line 34 def get(path = '', params = {}) response = @connection.get path, params response.body rescue Faraday::ClientError => e raise ClientError.new(e) end |
#post(path = '', body) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/horizon_client.rb', line 42 def post(path = '', body) response = @connection.post do |req| req.url path req.headers['Content-Type'] = 'application/xml;charset=UTF-8' req.body = body end response.body rescue Faraday::ClientError => e raise ClientError.new(e) end |
#url_prefix ⇒ Object
30 31 32 |
# File 'lib/horizon_client.rb', line 30 def url_prefix @connection.url_prefix end |