Class: SpreeKlaviyo::SubscribePresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree_klaviyo/subscribe_presenter.rb

Constant Summary collapse

SUBSCRIBED =
'SUBSCRIBED'.freeze
UNSUBSCRIBED =
'UNSUBSCRIBED'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(email:, list_id:, type: 'profile-subscription-bulk-create-job', subscribed: true) ⇒ SubscribePresenter

Returns a new instance of SubscribePresenter.



6
7
8
9
10
11
# File 'app/presenters/spree_klaviyo/subscribe_presenter.rb', line 6

def initialize(email:, list_id:, type: 'profile-subscription-bulk-create-job', subscribed: true)
  @email = email
  @list_id = list_id
  @type = type
  @subscribed = subscribed
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/presenters/spree_klaviyo/subscribe_presenter.rb', line 13

def call
  {
    data: {
      type: @type,
      attributes: {
        profiles: {
          data: [
            {
              "type": 'profile',
              "attributes": {
                email: @email,
                "subscriptions": {
                  "email": {
                    "marketing": {
                      "consent": @subscribed ? SUBSCRIBED : UNSUBSCRIBED
                    }
                  }
                }
              }
            }
          ]
        }
      },
      relationships: {
        list: {
          data: {
            type: 'list',
            id: @list_id
          }
        }
      }
    }
  }
end