Skip to content

Instantly share code, notes, and snippets.

@aamax
Last active August 29, 2015 14:25
Show Gist options
  • Save aamax/c7c4a3098a4009e7c357 to your computer and use it in GitHub Desktop.
Save aamax/c7c4a3098a4009e7c357 to your computer and use it in GitHub Desktop.
curl -i -H "Accept: application/json" -X POST -H "Content-Type: application/json" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
I've also tried changing the json to html
curl -i -H "Accept: application/html" -X POST -H "Content-Type: application/json" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
curl -i -H "Accept: application/html" -X POST -H "Content-Type: application/html" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
curl -i -H "Accept: application/json" -X POST -H "Content-Type: application/html" -H "X-API-EMAIL:user@example.com" -H "X-API-TOKEN:tokengoeshere" http://127.0.0.1:3000/api/v1/send_vendor_list
Started POST "/api/v1/send_vendor_list" for 127.0.0.1 at 2015-07-16 17:09:17 -0600
Processing by Api::V1::VendorsController#send_vendor_list as JSON
Can't verify CSRF token authenticity
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT 1 [["email", "user@example.com"]]
(0.3ms) BEGIN
SQL (0.4ms) UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5 [["last_sign_in_at", "2015-07-16 23:06:25.405924"], ["current_sign_in_at", "2015-07-16 23:09:17.905224"], ["sign_in_count", 138], ["updated_at", "2015-07-16 23:09:17.913882"], ["id", 302]]
(3.3ms) COMMIT
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 LIMIT 1 [["email", "user2@example.com"]]
DEPRECATION WARNING: Passing a nested array to Active Record finder methods is deprecated and will be removed. Flatten your array before using it for 'IN' conditions. (called from send_vendor_list at /Users/allenmaxwell/source/bhg/bhg-tablet/app/controllers/api/v1/vendors_controller.rb:78)
DEPRECATION WARNING: `#deliver` is deprecated and will be removed in Rails 5. Use `#deliver_now` to deliver immediately or `#deliver_later` to deliver through Active Job. (called from send_vendor_list at /Users/allenmaxwell/source/bhg/bhg-tablet/app/controllers/api/v1/vendors_controller.rb:79)
DEPRECATION WARNING: Passing a nested array to Active Record finder methods is deprecated and will be removed. Flatten your array before using it for 'IN' conditions. (called from send_vendor_list at /Users/allenmaxwell/source/bhg/bhg-tablet/app/mailers/user_mailer.rb:9)
Vendor Load (0.6ms) SELECT "vendors".* FROM "vendors" WHERE "vendors"."id" IN (1, 2, 3, 3, 4, 5, 6, 7) ORDER BY "vendors"."category" ASC
Rendered user_mailer/send_vendor_list.html.erb within layouts/mailer (26.4ms)
UserMailer#send_vendor_list: processed outbound mail in 50.6ms
Sent mail to user@example.com (2564.1ms)
Return-Path: <tablet@bhghome.com>
Date: Thu, 16 Jul 2015 17:09:17 -0600
From: tablet@bhghome.com
To: user@example.com
Message-ID: <55a8399ef_117fc3ffe74cc9ce83824b@Allens-MacBook-Pro.local.mail>
Subject: subject line goes here
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<html>
<body>
Hi! <p></p>
Please find below a list of vendors that I recommend to my clients. I've created a list especially for you and hope it is helpful.
<p></p>
Warm Regards,<br/> <br/>
&nbsp;&nbsp;&nbsp;USER
</body>
</html>
Completed 500 Internal Server Error in 2669ms (ActiveRecord: 5.3ms)
ActionView::MissingTemplate (Missing template api/v1/vendors/send_vendor_list, application/send_vendor_list with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/allenmaxwell/source/bhg/bhg-tablet/app/views"
* "/Users/allenmaxwell/.rvm/gems/ruby-2.2.0@tablet_app/gems/devise-3.5.1/app/views"
):
actionview (4.2.1) lib/action_view/path_set.rb:46:in `find'
actionview (4.2.1) lib/action_view/lookup_context.rb:121:in `find'
actionview (4.2.1) lib/action_view/renderer/abstract_renderer.rb:18:in `find_template'
actionview (4.2.1) lib/action_view/renderer/template_renderer.rb:40:in `determine_template'
actionview (4.2.1) lib/action_view/renderer/template_renderer.rb:8:in `render'
actionview (4.2.1) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.1) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.1) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.1) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.1) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.1) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.1) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (4.2.1) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/allenmaxwell/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.1) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:43:in `render'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:505:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_process_action_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.1) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.1) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.1) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.1) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.1) lib/action_controller/metal.rb:237:in `block in action'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `call'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:43:in `serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.1) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.1) lib/action_dispatch/routing/route_set.rb:819:in `call'
bullet (4.14.7) lib/bullet/rack.rb:12:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.1) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call'
activerecord (4.2.1) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.1) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:776:in `_run_call_callbacks'
activesupport (4.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.1) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
railties (4.2.1) lib/rails/engine.rb:518:in `call'
railties (4.2.1) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
puma (2.11.3) lib/puma/server.rb:507:in `handle_request'
puma (2.11.3) lib/puma/server.rb:375:in `process_client'
puma (2.11.3) lib/puma/server.rb:262:in `block in run'
puma (2.11.3) lib/puma/thread_pool.rb:104:in `call'
puma (2.11.3) lib/puma/thread_pool.rb:104:in `block in spawn_thread'
Rendered /Users/allenmaxwell/.rvm/gems/ruby-2.2.0@tablet_app/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (49.8ms)
Rendered /Users/allenmaxwell/.rvm/gems/ruby-2.2.0@tablet_app/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (14.0ms)
Rendered /Users/allenmaxwell/.rvm/gems/ruby-2.2.0@tablet_app/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.3ms)
Rendered /Users/allenmaxwell/.rvm/gems/ruby-2.2.0@tablet_app/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb within rescues/layout (134.2ms)
Cannot render console with content type application/htmlAllowed content types: [#<Mime::Type:0x007ffce097fb28 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x007ffce097f420 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x007ffce096da40 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]
# path to file: views/api/v1/vendors/send_vendor_list.html.erb
Hi! <p></p>
Please find below a list of vendors that I recommend to my clients. I've created a list especially for you and hope it is helpful.
<p></p>
Warm Regards,<br/> <br/>
&nbsp;&nbsp;&nbsp;<%= @from_user.full_name %>
<p></p>
<hr>
<p></p>
# path to file: mailers/user_mailer.rb
class UserMailer < ApplicationMailer
default from: "tablet@bhghome.com",
return_path: 'tablet@bhghome.com'
def send_vendor_list(from_user, to_user, subject, vendorIDs)
@from_user = from_user
@to_address = to_user
@subject = subject
@vendors = Vendor.where(id: [vendorIDs.split(',')])
mail(to: @from_user.email, subject: @subject)
end
end
# path to file: controllers/api/v1/vendor_controller.rb
module Api
module V1
class VendorsController < ApplicationController
respond_to :json
def send_vendor_list
# params with vendor id list
# destination email address
# subject line
# email body
# send email to destination address with list of vendors
@from_user = User.find_by_email('allen.maxwell@bhghome.com')
@to_address = 'aamax@xmission.com'
@subject = 'subject line goes here'
@vendors = Vendor.where(id: ["1,2,3,3,4,5,6,7".split(',')])
UserMailer.send_vendor_list(current_user, 'aamax@xmission.com', 'subject line goes here', "1,2,3,3,4,5,6,7").deliver
{result: "success"}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment