diff --git a/lib/sf.rb b/lib/sf.rb index f98e5c8..027a1ab 100644 --- a/lib/sf.rb +++ b/lib/sf.rb @@ -11,6 +11,7 @@ require "sf/session_type" require "sf/track" require "sf/presenter" +require "sf/sponsorship" module Sf class << self def client diff --git a/lib/sf/sponsorship.rb b/lib/sf/sponsorship.rb new file mode 100644 index 0000000..78ff628 --- /dev/null +++ b/lib/sf/sponsorship.rb @@ -0,0 +1,40 @@ +class Sf::Sponsorship + include Sf::Base + attr_reader :sobject + attr_accessor :sponsor + + def initialize(sobject=nil) + @sobject = sobject.nil? ? Restforce::SObject.new(sobject_type: 'EventSponsorship__c') : sobject + end + + def method_missing(method_name, *args, &block) + @sobject.send(method_name, *args, &block) + end + + def respond_to_missing?(method_name, include_private = false) + @sobject.respond_to?(method_name, include_private) || super + end + + def attrs_from_sponsor + attrs = {} + attrs["cms_sponsor_id__c"] = self.sponsor.id + attrs["cms_sponsor_name__c"] = self.sponsor.sponsor_name + attrs["event__c"] = self.sponsor.sf_event_id + attrs["logo_url__c"] = self.sponsor.image + attrs["sponsor__c"] = self.sponsor.sf_id unless self.sponsor.sf_id.blank? + attrs["sponsorship_type__c"] = self.sponsor.sponsorship_type.try(:humanize) + attrs + end + + def create_from_sponsor + Sf.client.create!("EventSponsorship__c", self.attrs_from_sponsor) if self.sponsor.present? + end + + def update_from_sponsor + attrs = self.attrs_from_sponsor + attrs["Id"] = self.Id + Sf.client.update!("EventSponsorship__c", attrs) if self.sponsor.present? + end +end + + diff --git a/lib/sf/version.rb b/lib/sf/version.rb index 59ef1c2..8be5feb 100644 --- a/lib/sf/version.rb +++ b/lib/sf/version.rb @@ -1,3 +1,3 @@ module Sf - VERSION = "0.1.8" + VERSION = "0.1.9" end