class BananaBits::Client
Attributes
api_key[R]
email[R]
list_id[R]
Public Class Methods
new(email, options={})
click to toggle source
# 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
Public Instance Methods
delete()
click to toggle source
# File lib/banana_bits/client.rb, line 32 def delete gibbon_client.lists(list_id).members(hashed_email).delete end
subscribe(body={})
click to toggle source
# 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()
click to toggle source
# File lib/banana_bits/client.rb, line 24 def unsubscribe gibbon_client.lists(list_id).members(hashed_email).update( body: { status: "unsubscribed" } ) end
Private Instance Methods
check_for_missing_arguments!()
click to toggle source
# File lib/banana_bits/client.rb, line 68 def check_for_missing_arguments! missing = %i(email api_key list_id).select{ |meth| self.public_send(meth).nil? } if missing.any? msg = "Missing required options: #{missing.join(', ')}." raise BananaBits::Error.new(msg) end end
get_group(group_name)
click to toggle source
# File lib/banana_bits/client.rb, line 54 def get_group(group_name) groups = gibbon_client.lists(list_id).interest_categories.retrieve.body groups[:categories].select{ |g| g[:title].downcase == group_name.to_s.downcase }.first end
get_group_options(group_id=nil)
click to toggle source
# File lib/banana_bits/client.rb, line 59 def get_group_options(group_id=nil) if group_id options = gibbon_client.lists(list_id).interest_categories(group_id).interests.retrieve.body[:interests] options.inject({}) { |result, interest| result.merge "#{interest[:name]}" => interest[:id]} else {} end end
gibbon_client()
click to toggle source
# File lib/banana_bits/client.rb, line 38 def gibbon_client Gibbon::Request.new(api_key: api_key, symbolize_keys: true) end
group_options(group_name)
click to toggle source
TODO: Add functionality for adding and or pulling down groups
# File lib/banana_bits/client.rb, line 48 def group_options(group_name) group = get_group(group_name) group_id = group ? group[:id] : nil get_group_options(group_id) end
hashed_email()
click to toggle source
# File lib/banana_bits/client.rb, line 42 def hashed_email Digest::MD5.hexdigest email.downcase end