spree_sendwithus 2.0.11.1 → 2.0.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 850b7ac80790aca791f3d9eeda74ed44732cbd28
4
- data.tar.gz: 3af2cadc05bfe6f711ef005c35f21eec19942990
3
+ metadata.gz: 1f0a71a42a0dcd0028ccdd3cbc877fd797d32b5a
4
+ data.tar.gz: 85d4d07d7ec496a39b0685db8dbbd53e3abe5715
5
5
  SHA512:
6
- metadata.gz: 54939c0fb1a2da26f20d6cbdef1644abb70c9c82d4b2a3f4978780acf15546dc75fd009f5ee3cc0cae2335bd77001e155c6745c53c93662ac8de2f18b9b68325
7
- data.tar.gz: 9e39d176bd5bb2e8482ebd82049b4b691aaac00eccfe59daf66a9b3cd0165df9e17d006188d78e67f3b2b7e82227f50a43a5ff10011a01cb842220391c810d6f
6
+ metadata.gz: f54433b26fe7755bdb5ebe043f21ad526b61ab27956fee446db2d5088832675e629050c0755e5b18e14376a4b9710b2c4a666cc5ca76f2f85a6b69c8265594cc
7
+ data.tar.gz: 20baf37b7ca485bdcfe435354b89654b6f08fad17fafa892e0c2793502cf92ed8d8ed3dcf05644c51a46da42705da90542f71a3cbdb25dd7d39a558ae4bae286
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --order random
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'pry-rails'
5
+ gem 'pry-byebug'
6
+ end
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2014 FreeRunning Technologies
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ Spree SendWithUs
2
+ ================
3
+
4
+ SendWithUs mailer you can use in Spree! Say what?!
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add spree_sendwithus to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'spree_sendwithus', github: 'freerunningtech/spree_sendwithus'
13
+ ```
14
+
15
+ Bundle your dependencies and run the installation generator:
16
+
17
+ ```shell
18
+ bundle install
19
+ ```
20
+
21
+ Add `send_with_us.rb` in `config/initializers` with the following:
22
+
23
+ ```ruby
24
+ SendWithUs::Api.configure do |config|
25
+ config.api_key = ENV["SEND_WITH_US_API_KEY"]
26
+ config.debug = true
27
+ end
28
+ ```
29
+
30
+ Now you can configure any of your mailers to use SendWithUs by making them a subclass of `Spree::SendWithUsMailer::Base`. For example:
31
+
32
+ ```ruby
33
+ # app/mailers/spree/quality_control_mailer.rb
34
+
35
+ class Spree::QualityControlMailer < Spree::SendWithUsMailer::Base
36
+ default recipient_name: "Quality Control",
37
+ recipient_address: "quality@freerunningtech.com",
38
+ from_name: "Quality Control",
39
+ from_address: "quality@freerunningtech.com"
40
+
41
+ def reprint(original, reprint)
42
+ assign(:original, order_data(Spree::Order.find(original)))
43
+ assign(:reprint, order_data(Spree::Order.find(reprint)))
44
+
45
+ mail(email_id: "SEND_WITH_US_TEMPLATE_ID")
46
+ end
47
+
48
+ private
49
+ def order_data(order)
50
+ {
51
+ url: spree.admin_order_url(order),
52
+ number: order.number
53
+ }
54
+ end
55
+ end
56
+ ```
57
+
58
+ The mailer will work with delayed job or without:
59
+
60
+ ```ruby
61
+ # Delayed
62
+ Spree::QualityControlMailer.delay.reprint(1, 2)
63
+
64
+ # Inline
65
+ Spree::QualityControlMailer.reprint(1, 2).deliver
66
+ ```
67
+
68
+ 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!
69
+
70
+ Testing
71
+ -------
72
+
73
+ Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.
74
+
75
+ ```shell
76
+ bundle
77
+ bundle exec rake test_app
78
+ bundle exec rspec spec
79
+ ```
80
+
81
+ Copyright (c) 2014 FreeRunning Technologies, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => [:spec]
10
+
11
+ desc 'Generates a dummy app for testing'
12
+ task :test_app do
13
+ ENV['LIB_NAME'] = 'spree_sendwithus'
14
+ Rake::Task['extension:test_app'].invoke
15
+ end
data/Versionfile ADDED
@@ -0,0 +1 @@
1
+ '2.0.x' => { branch: '2-0-stable' }
@@ -0,0 +1,29 @@
1
+ module SpreeSendwithus
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_sendwithus'
6
+
7
+ config.autoload_paths += %W(#{config.root}/lib)
8
+
9
+ # use rspec for tests
10
+ config.generators do |g|
11
+ g.test_framework :rspec
12
+ end
13
+
14
+ initializer "sendwithus_mailer.set_configs" do |app|
15
+ ActiveSupport.on_load(:spree_sendwithus_mailer) do
16
+ include AbstractController::UrlFor
17
+ extend AbstractController::Railties::RoutesHelpers.with(app.routes)
18
+ include app.routes.mounted_helpers
19
+
20
+ if defined?(Delayed::DelayMail)
21
+ extend Delayed::DelayMail
22
+ end
23
+
24
+ options = app.config.action_mailer
25
+ send(:default_url_options=, options.default_url_options)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ module Spree
2
+ module SendWithUsMailer
3
+ class Base
4
+ class_attribute :defaults
5
+ class_attribute :default_url_options
6
+
7
+ self.defaults = {}.freeze
8
+
9
+ class << self
10
+ def default(value = nil)
11
+ self.defaults = defaults.merge(value).freeze if value
12
+ defaults
13
+ end
14
+
15
+ def mailer_methods
16
+ methods = public_instance_methods - superclass.public_instance_methods
17
+
18
+ # Reject route helper methods.
19
+ methods.reject{ |m| m.to_s.end_with?("_url", "_path") }
20
+ end
21
+
22
+ def method_missing(method_name, *args)
23
+ if mailer_methods.include?(method_name.to_sym)
24
+ new(method_name, *args).message
25
+ else
26
+ super(method_name, *args)
27
+ end
28
+ end
29
+
30
+ def respond_to?(symbol, include_private = false)
31
+ super || mailer_methods.include?(symbol)
32
+ end
33
+ end
34
+
35
+ attr_reader :message
36
+
37
+ def initialize(method_name, *args)
38
+ @message = Spree::SendWithUs::Message.new
39
+ self.send(method_name, *args)
40
+ end
41
+
42
+ def mail(params = {})
43
+ @message.merge!(self.class.defaults.merge(params))
44
+ end
45
+
46
+ def assign(key, value)
47
+ @message.assign(key, value)
48
+ end
49
+
50
+ ActiveSupport.run_load_hooks(:spree_sendwithus_mailer, self)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,48 @@
1
+ require 'send_with_us'
2
+
3
+ module Spree
4
+ module SendWithUs
5
+ class Message
6
+ attr_reader :to, :from, :email_id, :email_data, :cc, :bcc
7
+
8
+ def initialize
9
+ @email_data = {}
10
+ @to = {}
11
+ @from = {}
12
+ @cc = []
13
+ @bcc = []
14
+ end
15
+
16
+ def assign(key, value)
17
+ @email_data.merge!(key.to_sym => value)
18
+ end
19
+
20
+ def merge!(params = {})
21
+ params.each_pair do |key, value|
22
+ case key
23
+ when :email_id
24
+ @email_id = value
25
+ when :recipient_name
26
+ @to.merge!(name: value)
27
+ when :recipient_address
28
+ @to.merge!(address: value)
29
+ when :from_name
30
+ @from.merge!(name: value)
31
+ when :from_address
32
+ @from.merge!(address: value)
33
+ when :reply_to
34
+ @from.merge!(reply_to: value)
35
+ when :cc
36
+ @cc.concat(value)
37
+ when :bcc
38
+ @bcc.concat(value)
39
+ end
40
+ end
41
+ end
42
+
43
+ def deliver
44
+ ::SendWithUs::Api.new.send_with(@email_id, @to, @email_data, @from, @cc, @bcc)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,6 @@
1
+ require 'send_with_us'
2
+
3
+ require 'spree_core'
4
+ require 'spree_sendwithus/mailer'
5
+ require 'spree_sendwithus/message'
6
+ require 'spree_sendwithus/engine'
data/script/rails ADDED
@@ -0,0 +1,7 @@
1
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+
3
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
4
+ ENGINE_PATH = File.expand_path('../../lib/spree_sendwithus/engine', __FILE__)
5
+
6
+ require 'rails/all'
7
+ require 'rails/engine/commands'
@@ -0,0 +1,60 @@
1
+ require 'rails_helper'
2
+
3
+ describe Spree::SendWithUsMailer::Base do
4
+ class DummyMailer < Spree::SendWithUsMailer::Base
5
+ def test; end;
6
+ end
7
+
8
+ subject { DummyMailer }
9
+ it { is_expected.to respond_to(:test) }
10
+
11
+ it "raises an undefined method error when method is missing" do
12
+ expect{ DummyMailer.blargh }.to raise_error NoMethodError
13
+ end
14
+
15
+ describe "::new" do
16
+ subject { DummyMailer.test }
17
+ it "creates an new message" do
18
+ expect(subject).to be_a Spree::SendWithUs::Message
19
+ end
20
+ end
21
+
22
+ describe "::default" do
23
+ it { should respond_to(:default) }
24
+ describe "setting a default" do
25
+ subject { DummyMailer.default({hello: "world"}) }
26
+ it { is_expected.to eq Hash[hello: "world"] }
27
+ end
28
+ end
29
+
30
+ describe "::mailer_methods" do
31
+ subject { DummyMailer.mailer_methods }
32
+ it { is_expected.to eq [:test] }
33
+ end
34
+
35
+ describe "#mail" do
36
+ class MailerWithMail < Spree::SendWithUsMailer::Base
37
+ def test
38
+ mail email_id: "template_1234"
39
+ end
40
+ end
41
+
42
+ subject { MailerWithMail.test }
43
+ it "merges the values from mail into the message" do
44
+ expect(subject.email_id).to eq "template_1234"
45
+ end
46
+ end
47
+
48
+ describe "#assign" do
49
+ class MailerWithAssign < Spree::SendWithUsMailer::Base
50
+ def test
51
+ assign :user, "john"
52
+ end
53
+ end
54
+
55
+ subject { MailerWithAssign.test }
56
+ it "sets the (key, value) pair on the message" do
57
+ expect(subject.email_data).to eq Hash[user: "john"]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,94 @@
1
+ require 'spree_sendwithus'
2
+
3
+ describe Spree::SendWithUs::Message do
4
+ subject { Spree::SendWithUs::Message.new }
5
+
6
+ it { is_expected.to respond_to(:email_id, :to, :from, :cc, :bcc, :deliver) }
7
+ it { is_expected.not_to respond_to(:email_id=, :to=, :from=, :cc=, :bcc=) }
8
+
9
+ describe "initialization" do
10
+ it "creates an empty email_data on initialization" do
11
+ expect(subject.email_data).to be_empty
12
+ end
13
+ end
14
+
15
+ describe "#assign" do
16
+ let(:message) { Spree::SendWithUs::Message.new }
17
+
18
+ it "adds (key,value) pairs to email_data hash" do
19
+ message.assign(:user, {name: "Richard", email: "richard@example.com"})
20
+
21
+ expect(message.email_data).to eq Hash[
22
+ user: {name: "Richard", email: "richard@example.com"}
23
+ ]
24
+
25
+ message.assign(:url, "http://test.example.com")
26
+ expect(message.email_data).to eq Hash[
27
+ user: {name: "Richard", email: "richard@example.com"},
28
+ url: "http://test.example.com"
29
+ ]
30
+ end
31
+
32
+ it "symbolizes the keys" do
33
+ message.assign("company", "FreeRunning Tech")
34
+ expect(message.email_data).to have_key(:company)
35
+ end
36
+ end
37
+
38
+ describe "#merge!" do
39
+ let(:message) { Spree::SendWithUs::Message.new }
40
+ let(:params) { Hash[
41
+ email_id: "template_1234",
42
+ recipient_name: "John",
43
+ recipient_address: "john@example.com",
44
+ from_name: "Jared",
45
+ from_address: "jared@example.com",
46
+ reply_to: "gregor@example.com",
47
+ cc: ["sean@example.com"],
48
+ bcc: ["clarke@example.com", "kyria@example.com"]
49
+ ] }
50
+
51
+ before do
52
+ message.merge!(params)
53
+ end
54
+
55
+ subject { message }
56
+
57
+ it "contains the expected email_id" do
58
+ expect(subject.email_id).to eq "template_1234"
59
+ end
60
+ it "contains the expected to hash" do
61
+ expect(subject.to).to eq Hash[
62
+ name: "John",
63
+ address: "john@example.com"
64
+ ]
65
+ end
66
+ it "contains the expected from hash" do
67
+ expect(subject.from).to eq Hash[
68
+ name: "Jared",
69
+ address: "jared@example.com",
70
+ reply_to: "gregor@example.com"
71
+ ]
72
+ end
73
+ it "contains the expected cc array" do
74
+ expect(subject.cc).to match_array ["sean@example.com"]
75
+ end
76
+ it "contains the expected bcc array" do
77
+ expect(subject.bcc).to match_array [
78
+ "clarke@example.com",
79
+ "kyria@example.com"
80
+ ]
81
+ end
82
+ end
83
+
84
+ describe "#deliver" do
85
+ let(:api_double) { double("api") }
86
+
87
+ it "calls the send_with_us gem" do
88
+ allow(SendWithUs::Api).to receive(:new).and_return(api_double)
89
+ expect(api_double).to receive(:send_with)
90
+
91
+ subject.deliver
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require 'spec_helper'
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
11
+
12
+ config.use_transactional_fixtures = true
13
+
14
+ config.infer_spec_type_from_file_location!
15
+ end
@@ -0,0 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter 'spec'
4
+ add_filter 'vendor/bundle'
5
+ add_group 'Libraries', 'lib'
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec
10
+ config.color = true
11
+
12
+ config.fail_fast = ENV['FAIL_FAST'] || false
13
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+ Gem::Specification.new do |s|
3
+ s.platform = Gem::Platform::RUBY
4
+ s.name = 'spree_sendwithus'
5
+ s.version = '2.0.11.2'
6
+ s.summary = 'SendWithUs integration'
7
+ s.required_ruby_version = '>= 1.9.3'
8
+
9
+ s.author = 'FreeRunning Technologies'
10
+ s.email = 'contact@freerunningtech.com'
11
+ s.homepage = 'http://www.freerunningtech.com'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
15
+ s.require_paths = ["lib"]
16
+
17
+ s.add_dependency 'spree_core', '~> 2.0.11.beta'
18
+ s.add_dependency 'send_with_us', '~> 1.1.4'
19
+
20
+ s.add_development_dependency 'rspec-rails', '~> 3.0.0'
21
+ s.add_development_dependency 'simplecov'
22
+ s.add_development_dependency 'sqlite3'
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_sendwithus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11.1
4
+ version: 2.0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FreeRunning Technologies
@@ -85,7 +85,24 @@ email: contact@freerunningtech.com
85
85
  executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
- files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - Versionfile
96
+ - lib/spree_sendwithus.rb
97
+ - lib/spree_sendwithus/engine.rb
98
+ - lib/spree_sendwithus/mailer.rb
99
+ - lib/spree_sendwithus/message.rb
100
+ - script/rails
101
+ - spec/lib/spree_sendwithus/mailer_spec.rb
102
+ - spec/lib/spree_sendwithus/message_spec.rb
103
+ - spec/rails_helper.rb
104
+ - spec/spec_helper.rb
105
+ - spree_sendwithus.gemspec
89
106
  homepage: http://www.freerunningtech.com
90
107
  licenses: []
91
108
  metadata: {}