Class: BananaBits::Client
- Includes:
- BananaBits::Concerns::Hashable
- Defined in:
- lib/banana_bits/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#list_id ⇒ Object
readonly
Returns the value of attribute list_id.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(email, options = {}) ⇒ Client
constructor
A new instance of Client.
- #subscribe(body = {}) ⇒ Object
- #unsubscribe ⇒ Object
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, ={}) @email = email = symbolize_keys() @api_key = BananaBits.configuration.api_key || [:api_key] @list_id = BananaBits.configuration.list_id || [:list_id] check_for_missing_arguments! end |
Instance Attribute Details
#api_key ⇒ Object (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 |
#email ⇒ Object (readonly)
Returns the value of attribute email.
8 9 10 |
# File 'lib/banana_bits/client.rb', line 8 def email @email end |
#list_id ⇒ Object (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
#delete ⇒ Object
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 |
#unsubscribe ⇒ Object
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 |