Class: Rhoconnect::EndpointHelpers
- Inherits:
-
Object
- Object
- Rhoconnect::EndpointHelpers
- Defined in:
- lib/rhoconnect/endpoints.rb
Class Method Summary collapse
- .authenticate(content_type, body) ⇒ Object
- .create(content_type, body) ⇒ Object
- .delete(content_type, body) ⇒ Object
- .on_cud(action, content_type, body) ⇒ Object
- .query(content_type, body) ⇒ Object
- .update(content_type, body) ⇒ Object
Class Method Details
.authenticate(content_type, body) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/rhoconnect/endpoints.rb', line 5 def self.authenticate(content_type, body) code, params = 200, parse_params(content_type, body) if Rhoconnect.configuration.authenticate code = 401 unless Rhoconnect.configuration.authenticate.call(params) end [code, {'Content-Type' => 'text/plain'}, [code == 200 ? params['login'] : ""]] end |
.create(content_type, body) ⇒ Object
46 47 48 |
# File 'lib/rhoconnect/endpoints.rb', line 46 def self.create(content_type, body) self.on_cud(:create, content_type, body) end |
.delete(content_type, body) ⇒ Object
54 55 56 |
# File 'lib/rhoconnect/endpoints.rb', line 54 def self.delete(content_type, body) self.on_cud(:delete, content_type, body) end |
.on_cud(action, content_type, body) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rhoconnect/endpoints.rb', line 35 def self.on_cud(action, content_type, body) params = parse_params(content_type, body) object_id = "" code, error = get_rhoconnect_resource(params['resource'], action) do |klass| object_id = klass.send("rhoconnect_receive_#{action}".to_sym, params['partition'], params['attributes']) object_id = object_id.to_s if object_id end [code, {'Content-Type' => "text/plain"}, [error || object_id]] end |
.query(content_type, body) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rhoconnect/endpoints.rb', line 13 def self.query(content_type, body) params = parse_params(content_type, body) action, c_type, result, records = :rhoconnect_query, 'application/json', {}, [] # Call resource rhoconnect_query class method code, error = get_rhoconnect_resource(params['resource'], action) do |klass| records = klass.send(action, params['partition']) end if code == 200 # Serialize records into hash of hashes records.each do |record| result[record.id.to_s] = record.normalized_attributes end result = result.to_json else result = error c_type = 'text/plain' # Log warning if something broke warn error end [code, {'Content-Type' => c_type}, [result]] end |
.update(content_type, body) ⇒ Object
50 51 52 |
# File 'lib/rhoconnect/endpoints.rb', line 50 def self.update(content_type, body) self.on_cud(:update, content_type, body) end |