Class: BananaBits::Client

Inherits:
Object show all
Includes:
BananaBits::Concerns::Hashable
Defined in:
lib/banana_bits/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BananaBits::Concerns::Hashable

#remove_blank_values, #remove_blank_values!, #remove_blank_values_from_array, #remove_blank_values_from_array!, #symbolize_keys

Constructor Details

#initialize(email, options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
# File 'lib/banana_bits/client.rb', line 10

def initialize(email, options={})
  @email = email
  options = symbolize_keys(options)
  @api_key = BananaBits.configuration.api_key || options[:api_key]
  @list_id = BananaBits.configuration.list_id || options[:list_id]
  check_for_missing_arguments!
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/banana_bits/client.rb', line 8

def api_key
  @api_key
end

#emailObject (readonly)

Returns the value of attribute email.



8
9
10
# File 'lib/banana_bits/client.rb', line 8

def email
  @email
end

#list_idObject (readonly)

Returns the value of attribute list_id.



8
9
10
# File 'lib/banana_bits/client.rb', line 8

def list_id
  @list_id
end

Instance Method Details

#deleteObject



32
33
34
# File 'lib/banana_bits/client.rb', line 32

def delete
  gibbon_client.lists(list_id).members(hashed_email).delete
end

#subscribe(body = {}) ⇒ Object



18
19
20
21
22
# File 'lib/banana_bits/client.rb', line 18

def subscribe(body={})
  body.merge! email_address: email, status: 'subscribed'
  body = remove_blank_values!(body)
  gibbon_client.lists(list_id).members(hashed_email).upsert(body: body)
end

#unsubscribeObject



24
25
26
27
28
29
30
# File 'lib/banana_bits/client.rb', line 24

def unsubscribe
  gibbon_client.lists(list_id).members(hashed_email).update(
    body: {
      status: "unsubscribed"
    }
  )
end