Skip to content

Commit

Permalink
added sponsorship
Browse files Browse the repository at this point in the history
  • Loading branch information
ij committed Sep 2, 2014
1 parent 55c713c commit 49fc65a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/sf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "sf/session_type"
require "sf/track"
require "sf/presenter"
require "sf/sponsorship"
module Sf
class << self
def client
Expand Down
40 changes: 40 additions & 0 deletions lib/sf/sponsorship.rb
Original file line number Diff line number Diff line change
@@ -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


2 changes: 1 addition & 1 deletion lib/sf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Sf
VERSION = "0.1.8"
VERSION = "0.1.9"
end

0 comments on commit 49fc65a

Please sign in to comment.