No commit activity in last 3 years
No release in over 3 years
SendWithUs integration
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 2.0.11.beta
 Project Readme

Spree SendWithUs

SendWithUs mailer you can use in Spree! Say what?!

Code Climate Test Coverage Gem Version

Installation

Add spree_sendwithus to your Gemfile:

# Rubygems
gem 'spree_sendwithus'

# Direct from Github
gem 'spree_sendwithus', github: 'freerunningtech/spree_sendwithus'

Bundle your dependencies and run the installation generator:

bundle install

Add send_with_us.rb in config/initializers with the following:

SendWithUs::Api.configure do |config|
  config.api_key = ENV["SEND_WITH_US_API_KEY"]
  config.debug = true
end

If you want to globally configure the email service provider SendWithUs will use, say for sending staging emails to something like mailtrap.io, then simply add the following to an initializer:

Spree::SendWithUs::Base.configure do |config|
  config.esp_account = ENV['SEND_WITH_US_ESP_ACCOUNT']
end

Now you can configure any of your mailers to use SendWithUs by making them a subclass of Spree::SendWithUsMailer::Base. For example:

# app/mailers/spree/quality_control_mailer.rb

class Spree::QualityControlMailer < Spree::SendWithUsMailer::Base
  default recipient_name: "Quality Control",
          recipient_address: "quality@freerunningtech.com",
          from_name: "Quality Control",
          from_address: "quality@freerunningtech.com"

  def reprint(original, reprint)
    assign(:original, order_data(Spree::Order.find(original)))
    assign(:reprint, order_data(Spree::Order.find(reprint)))

    mail(
      email_id: 'SEND_WITH_US_TEMPLATE_ID',
      esp_account: 'SEND_WITH_US_ESP_API_ID' # Optional
    )
  end

  private
  def order_data(order)
    {
      url: spree.admin_order_url(order),
      number: order.number
    }
  end
end

The mailer will work with delayed job or without:

# Delayed
Spree::QualityControlMailer.delay.reprint(1, 2)

# Inline
Spree::QualityControlMailer.reprint(1, 2).deliver

Also, the default URL host will be pulled from config.action_mailer.default_url_options so there's no need for any extra configuration! You're welcome!

RSpec

Have spree_sendwithus mailers? Want to do some testing with RSpec? Don't want to hit the API?! Then look no further! Just add the following to your spec_helper.rb and bask in the glory that is mocking!

require 'spree_sendwithus/rspec_support'

Testing

Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.

bundle
bundle exec rake test_app
bundle exec rspec spec

Copyright (c) 2014 FreeRunning Technologies, released under the New BSD License