Class: RestClientHelper
- Inherits:
-
Object
- Object
- RestClientHelper
- Defined in:
- lib/cloudscale/rest/rest_client_helper.rb
Overview
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #load_token(token) ⇒ Object
- #removeLinks(hash, key) ⇒ Object
- #uri(entity) ⇒ Object
- #uri_with_params(entity, params) ⇒ Object
- #uriWithId(entity, id) ⇒ Object
Class Method Details
.load_entity_id(entity) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 43 def self.load_entity_id(entity) if (entity != nil && entity["links"].is_a?(Array)) entity["links"].each { | link | if (link["rel"] == "self") return link["href"][link["href"].rindex('/') + 1, link["href"].length] end } end end |
.load_entity_ref(entity) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 53 def self.load_entity_ref(entity) if (entity != nil && entity["links"].is_a?(Array)) entity["links"].each { | link | if (link["rel"] == "self") return link end } end end |
Instance Method Details
#load_token(token) ⇒ Object
9 10 11 12 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 9 def load_token(token) db = FSDB::Database.new("#{File.dirname(__FILE__)}/../store/plugin/") return db[token] end |
#removeLinks(hash, key) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 63 def removeLinks(hash, key) if (hash.key?(key)) hash.tap { | x | x.delete(key) } end end |
#uri(entity) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 14 def uri(entity) if (!endpoint.to_s.end_with? '/') @endpoint << '/' end String::new(@endpoint + entity) end |
#uri_with_params(entity, params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 21 def uri_with_params(entity, params) if (!endpoint.to_s.end_with? '/') @endpoint << '/' end uri = String::new(@endpoint + entity) if (params.is_a?(Hash)) uri << '?' params.each { | key, value| uri += key.to_s + '=' + value.to_s + '&' } end return uri end |
#uriWithId(entity, id) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cloudscale/rest/rest_client_helper.rb', line 36 def uriWithId(entity, id) if (!endpoint.to_s.end_with? '/') @endpoint << '/' end String::new(@endpoint + entity + '/' + id.to_s) end |