Class: Mixmax

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mixmax.rb,
lib/mixmax/version.rb

Constant Summary collapse

VERSION =
"0.1.10"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Mixmax

Returns a new instance of Mixmax.



9
10
11
12
13
# File 'lib/mixmax.rb', line 9

def initialize(api_key)
  @headers = {
    'X-API-Token' => api_key, 'Content-Type' => 'application/json'
  }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/mixmax.rb', line 7

def headers
  @headers
end

Instance Method Details

#add_to_sequence(sequence_id, recipients:) ⇒ Object



37
38
39
# File 'lib/mixmax.rb', line 37

def add_to_sequence(sequence_id, recipients:)
  post "/v1/sequences/#{sequence_id}/recipients", query: recipients
end

#change_user_preferences(query: {}) ⇒ Object



45
46
47
# File 'lib/mixmax.rb', line 45

def change_user_preferences(query: {})
  patch '/v1/userpreferences/me', body: query
end

#remove_recipient_from_sequence(sequence_id, emails:) ⇒ Object



49
50
51
# File 'lib/mixmax.rb', line 49

def remove_recipient_from_sequence(sequence_id, emails:)
  post "/v1/sequences/#{sequence_id}/cancel", query: { emails: Array(emails) }
end

#sequence(sequence_id) ⇒ Object



29
30
31
# File 'lib/mixmax.rb', line 29

def sequence(sequence_id)
  get "/v1/sequences/#{sequence_id}"
end

#sequence_recipients(sequence_id) ⇒ Object



33
34
35
# File 'lib/mixmax.rb', line 33

def sequence_recipients(sequence_id)
  get "/v1/sequences/#{sequence_id}/recipients"
end

#sequences(query: {}, all: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mixmax.rb', line 17

def sequences(query: {}, all: false)
  sequences = []
  next_param = ''

  loop do
    response = get "/v1/sequences/#{next_param}", query: query
    sequences += response['results']
    return sequences unless response['hasNext'] && all
    next_param = "?next=#{response['next']}"
  end
end

#user_preferencesObject



41
42
43
# File 'lib/mixmax.rb', line 41

def user_preferences
  get '/v1/userpreferences/me'
end