From 7992cf4b52328da7fcc620041f53eeccc06d277d Mon Sep 17 00:00:00 2001 From: Jen Young Date: Wed, 13 Sep 2017 10:34:36 -0700 Subject: [PATCH] Add methods for updating and deleting API apps --- app/controllers/apps_controller.rb | 34 +++++++++++++++++++++++++++++ app/controllers/signs_controller.rb | 2 +- app/views/apps/create.html.erb | 0 app/views/apps/update.html.erb | 0 app/views/signs/index.html.erb | 19 ++++++++++++++++ config/routes.rb | 3 +++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/views/apps/create.html.erb create mode 100644 app/views/apps/update.html.erb diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index 4454f9f..51b9a68 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -8,6 +8,40 @@ def info end def list + app_list = client.get_api_apps :page => 2 + + render json: app_list + end + + def create + + white_labeling = { + "primary_button_color":"#778899", + "primary_button_text_color":"#ffffff" + } + + app = client.create_api_app( + :name => params[:app_name], + :domain => 'www.rubyonrails.com', + :white_labeling_options => white_labeling.to_json + ) + + render json: app end + def update + app = client.update_api_app( + :name => params[:app_name], + :client_id => params[:client_id] + ) + + render json: app + end + + def delete + client.delete_api_app :client_id => params[:client_id] + + flash[:notice] = "App deleted!" + redirect_to root_path + end end diff --git a/app/controllers/signs_controller.rb b/app/controllers/signs_controller.rb index a50f04e..4239510 100644 --- a/app/controllers/signs_controller.rb +++ b/app/controllers/signs_controller.rb @@ -41,7 +41,7 @@ def send_request :name => 'Jen', :order => 0 } - ], + ], # :form_fields_per_document => [ # [ # { diff --git a/app/views/apps/create.html.erb b/app/views/apps/create.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/apps/update.html.erb b/app/views/apps/update.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/signs/index.html.erb b/app/views/signs/index.html.erb index 757bebb..d595a39 100644 --- a/app/views/signs/index.html.erb +++ b/app/views/signs/index.html.erb @@ -67,6 +67,25 @@ Hello API event received
  • <%= link_to 'List API Apps', apps_list_path %>
  • +
  • + <%= form_tag("/apps/create", method: "get") do %> + <%= text_field_tag(:app_name, nil, :placeholder => 'App Name') %> + <%= submit_tag("Create API App") %> + <% end %> +
  • +
  • + <%= form_tag("/apps/update", method: "get") do %> + <%= text_field_tag(:client_id, nil, :placeholder => 'Client ID') %> + <%= text_field_tag(:app_name, nil, :placeholder => 'App Name') %> + <%= submit_tag("Update API App") %> + <% end %> +
  • +
  • + <%= form_tag("/apps/delete", method: "get") do %> + <%= text_field_tag(:client_id, nil, :placeholder => 'Client ID') %> + <%= submit_tag("Delete API App") %> + <% end %> +
  • diff --git a/config/routes.rb b/config/routes.rb index d747dcd..0c2a1d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,4 +34,7 @@ get '/apps/info' => 'apps#info' get '/apps/list' => 'apps#list' + get '/apps/create' => 'apps#create' + get '/apps/update' => 'apps#update' + get '/apps/delete' => 'apps#delete' end