Class: Spree::SendWithUs::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/spree_sendwithus/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessage

Returns a new instance of Message.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spree_sendwithus/message.rb', line 9

def initialize
  @email_data = {}
  @to = {}
  @from = {}
  @cc = []
  @bcc = []
  @files = []
   = Base. || ""
  @tags = []
  @locale = I18n.default_locale.to_s
end

Instance Attribute Details

#bccObject (readonly)

Returns the value of attribute bcc.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def bcc
  @bcc
end

#ccObject (readonly)

Returns the value of attribute cc.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def cc
  @cc
end

#email_dataObject (readonly)

Returns the value of attribute email_data.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def email_data
  @email_data
end

#email_idObject (readonly)

Returns the value of attribute email_id.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def email_id
  @email_id
end

#esp_accountObject (readonly)

Returns the value of attribute esp_account.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def 
  
end

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def files
  @files
end

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def from
  @from
end

#localeObject (readonly)

Returns the value of attribute locale.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def locale
  @locale
end

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def tags
  @tags
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/spree_sendwithus/message.rb', line 6

def to
  @to
end

Instance Method Details

#assign(key, value) ⇒ Object



21
22
23
# File 'lib/spree_sendwithus/message.rb', line 21

def assign(key, value)
  @email_data.merge!(key.to_sym => value)
end

#deliverObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/spree_sendwithus/message.rb', line 56

def deliver
  ::SendWithUs::Api.new.send_email(
    @email_id,
    @to,
    {
      data: @email_data,
      from: @from,
      cc: @cc,
      bcc: @bcc,
      esp_account: ,
      files: @files,
      tags: @tags,
      locale: @locale
    }
  )
end

#merge!(params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/spree_sendwithus/message.rb', line 25

def merge!(params = {})
  params.each_pair do |key, value|
    case key
    when :email_id
      @email_id = value
    when :recipient_name
      @to.merge!(name: value)
    when :recipient_address
      @to.merge!(address: value)
    when :from_name
      @from.merge!(name: value)
    when :from_address
      @from.merge!(address: value)
    when :reply_to
      @from.merge!(reply_to: value)
    when :cc
      @cc.concat(value)
    when :bcc
      @bcc.concat(value)
    when :files
      @files.concat(value)
    when :esp_account
       = value
    when :tags
      @tags = value
    when :locale
      @locale = value
    end
  end
end