Module: Nucleus::Adapters::V1::Heroku::Services
- Included in:
- Nucleus::Adapters::V1::Heroku
- Defined in:
- lib/nucleus/adapters/v1/heroku/services.rb
Instance Method Summary collapse
- #add_service(application_id, service_entity, plan_entity) ⇒ Object
- #change_service(application_id, service_id, plan_entity) ⇒ Object
- #installed_service(application_id, service_id) ⇒ Object
- #installed_services(application_id) ⇒ Object
- #remove_service(application_id, service_id) ⇒ Object
- #service(service_id) ⇒ Object
- #service_plan(service_id, plan_id) ⇒ Object
- #service_plans(service_id) ⇒ Object
- #services ⇒ Object
Instance Method Details
#add_service(application_id, service_entity, plan_entity) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 41 def add_service(application_id, service_entity, plan_entity) begin # make sure plan belongs to this service, throws 404 if no such plan # the service plan itself requires the name, e.g. 'sandbox' or the UUID service_plan(service_entity[:id], plan_entity[:id]) rescue Errors::AdapterResourceNotFoundError => e # convert to 422 raise Errors::SemanticAdapterRequestError, e. end # the plan to choose requires the UUID of the plan OR the combination of both names plan_id = service_plan_identifier(service_entity[:id], plan_entity[:id]) created = post("/apps/#{application_id}/addons", body: { plan: plan_id }).body to_nucleus_installed_service(created) end |
#change_service(application_id, service_id, plan_entity) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 57 def change_service(application_id, service_id, plan_entity) # make sure service is bound to the application assignment_id = raw_installed_service(application_id, service_id)[:id] begin # make sure plan belongs to this service, throws 404 if no such plan # the service plan itself requires the name, e.g. 'sandbox' or the UUID service_plan(service_id, plan_entity[:id]) rescue Errors::AdapterResourceNotFoundError => e # convert to 422 raise Errors::SemanticAdapterRequestError, e. end # the plan to choose requires the UUID of the plan OR the combination of both names plan_id = service_plan_identifier(service_id, plan_id) updated = patch("/apps/#{application_id}/addons/#{assignment_id}", body: { plan: plan_id }).body to_nucleus_installed_service(updated) end |
#installed_service(application_id, service_id) ⇒ Object
35 36 37 38 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 35 def installed_service(application_id, service_id) assigned_service = raw_installed_service(application_id, service_id) to_nucleus_installed_service(assigned_service) end |
#installed_services(application_id) ⇒ Object
30 31 32 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 30 def installed_services(application_id) get("/apps/#{application_id}/addons").body.collect { |service| to_nucleus_installed_service(service) } end |
#remove_service(application_id, service_id) ⇒ Object
75 76 77 78 79 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 75 def remove_service(application_id, service_id) # make sure service is bound to the application assignment_id = raw_installed_service(application_id, service_id)[:id] delete("/apps/#{application_id}/addons/#{assignment_id}") end |
#service(service_id) ⇒ Object
12 13 14 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 12 def service(service_id) to_nucleus_service(get("/addon-services/#{service_id}").body) end |
#service_plan(service_id, plan_id) ⇒ Object
25 26 27 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 25 def service_plan(service_id, plan_id) to_nucleus_plan(get("/addon-services/#{service_id}/plans/#{plan_id}").body) end |
#service_plans(service_id) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 17 def service_plans(service_id) load_plans(service_id).collect { |plan| to_nucleus_plan(plan) }.sort_by do |plan| # only compare the first cost, covers most cases and sorting for all costs would be far too complex plan[:costs][0][:price].first[:amount].to_f end end |
#services ⇒ Object
7 8 9 |
# File 'lib/nucleus/adapters/v1/heroku/services.rb', line 7 def services get('/addon-services').body.collect { |service| to_nucleus_service(service) } end |