Class: MicroservicesEngine::Connection
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MicroservicesEngine::Connection
- Defined in:
- app/models/microservices_engine/connection.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.get(resource, path, params = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/models/microservices_engine/connection.rb', line 8 def self.get(resource, path, params = {}) conn = Connection.find_by(object: resource.to_s) # Does :abc match "abc"? if conn.present? conn.get path, params else raise ArgumentError, "Unknown resource #{resource}" end end |
Instance Method Details
#get(path, params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/microservices_engine/connection.rb', line 16 def get(path, params = {}) # Example use: # (connection object for FieldTrip).get([123223, public_trip_stops], {active_only: true}) # => queries endpoint: uri/123223/public_trip_stops # => endpoint finds all FieldTrip objects that are active (param flag) # => returns the response if the request was a success # Assumption: url is followed by a `/` uri = URI.parse(url + path.join('/')) uri.query = URI.encode_www_form(params) res = Net::HTTP.get_response(uri) if res.is_a? Net::HTTPSuccess res.body else raise ArgumentError, res.body end end |