Class: HDeploy::APIClient
- Inherits:
-
Object
- Object
- HDeploy::APIClient
- Includes:
- Singleton
- Defined in:
- lib/hdeploy/apiclient.rb
Instance Method Summary collapse
- #delete(uri) ⇒ Object
- #get(url) ⇒ Object
-
#initialize ⇒ APIClient
constructor
A new instance of APIClient.
- #put(uri, data) ⇒ Object
Constructor Details
#initialize ⇒ APIClient
Returns a new instance of APIClient.
8 9 10 11 12 13 14 15 |
# File 'lib/hdeploy/apiclient.rb', line 8 def initialize @conf = Conf.instance @c = Curl::Easy.new() @c.http_auth_types = :basic @c.username = @conf.api['http_user'] @c.password = @conf.api['http_password'] end |
Instance Method Details
#delete(uri) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/hdeploy/apiclient.rb', line 31 def delete(uri) @c.url = @config.conf['global']['endpoint'] + uri @c.http_delete raise "response code for #{url} was not 200 : #{@c.response_code} - #{@c.body_str}" unless @c.response_code == 200 return @c.body_str end |
#get(url) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/hdeploy/apiclient.rb', line 17 def get(url) @c.url = @conf.api['endpoint'] + url @c.perform raise "response code for #{url} was not 200 : #{@c.response_code}" unless @c.response_code == 200 return @c.body_str end |
#put(uri, data) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/hdeploy/apiclient.rb', line 24 def put(uri,data) @c.url = @config.api['endpoint'] + uri @c.http_put(data) raise "response code for #{url} was not 200 : #{@c.response_code} - #{@c.body_str}" unless @c.response_code == 200 return @c.body_str end |