Skip to content

Commit

Permalink
added sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
ij committed Aug 19, 2014
1 parent 1a29231 commit b54c7d4
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/sf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
require "sf/reg_event"
require "sf/reg_registration"
require "sf/reg_item"
require "sf/session"
require "sf/session_type"
require "sf/track"
require "sf/presenter"
module Sf
class << self
def client
Expand Down
32 changes: 32 additions & 0 deletions lib/sf/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,44 @@ module Sf
module Base
def self.included(base)
base.extend(ClassMathods)
def update(args={})
unless self.Id.blank?
params = {'Id' => self.Id}
args.map {|k,v| params[k] = v}
Sf.client.update!(self.sobject.attributes[:type], params)
end
end
end

module ClassMathods
def build_collection(models)
models.map { |model| new(model) }
end

def class_name
self.new.sobject[:sobject_type]
end

def find(id)
new Sf.client.find(self.class_name, id)
end

def find_by_name(name)
sobject = where({Name: name}).first
find(sobject.Id) unless sobject.blank?
end

def find_by(args = {})
sobject = where(args).first
find(sobject.Id) unless sobject.blank?
end

def where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select Id, Name from #{self.class_name} where #{where}")
build_collection sobjects unless sobjects.blank?
end

end

end
Expand Down
23 changes: 23 additions & 0 deletions lib/sf/presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Sf::Presenter
include Sf::Base
attr_reader :sobject

def initialize(sobject=nil)
@sobject = sobject.nil? ? Restforce::SObject.new(sobject_type: 'EventPresenter__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 where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select Id, Name, cms_presenter_id__c from #{self.class_name} where #{where}")
build_collection sobjects unless sobjects.blank?
end

end
80 changes: 80 additions & 0 deletions lib/sf/session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class Sf::Session
include Sf::Base
attr_reader :sobject
attr_accessor :proposal

def initialize(sobject=nil)
@sobject = sobject.nil? ? Restforce::SObject.new(sobject_type: 'EventSession__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 create_from_proposal
Sf.client.create!('EventSession__c', proposal_attrs)
end

def proposal_attrs
sf_event = Sf::RegEvent.find_by_code(self.proposal.meeting_config.event_code)
attrs = {}
attrs['event__c'] = sf_event.Id
attrs['Name'] = self.proposal.session_title[0..79]
attrs['title__c'] = self.proposal.session_title
attrs['abstract__c'] = self.proposal.abstract
attrs['cms_proposal_id__c'] = self.proposal.id
attrs['submitter_email__c'] = self.proposal.submitter_email
attrs['submitter_phone__c'] = self.proposal.submitter_phone
attrs['cms_proposal_id__c'] = self.proposal.id
if session_type_id = self.proposal.session_type_id
sf_session_type = Sf::SessionType.find_by(cms_session_type_id__c: session_type_id)
attrs['session_type__c'] = sf_session_type.Id unless sf_session_type.blank?
end
if primary_track_id = self.proposal.primary_track_id
sf_primary_track = Sf::Track.find_by(cms_track_id__c: primary_track_id)
attrs['primary_track_id__c'] = sf_primary_track.Id unless sf_primary_track.blank?
end
if secondary_track_id = self.proposal.secondary_track_id
sf_secondary_track = Sf::Track.find_by(cms_track_id__c: secondary_track_id)
attrs['secondary_track_id__c'] = sf_secondary_track.Id unless sf_secondary_track.blank?
end
attrs['timestamp__c'] = Time.now.iso8601
meeting = self.proposal.meeting_config.meeting
if meeting.present?
attrs['cms_meeting_id__c'] = meeting.id
end
attrs
end

def timestamp
self.timestamp__c.try(:to_datetime)
end

def ready_to_publish?
required_attrs = %w(title__c abstract__c timestamp__c start_time__c date__c end_time__c)
ready = true
required_attrs.each do |attr|
if attr.blank?
ready = false
break
end
end
ready
end

def self.by_event_code(code)
event = Sf::RegEvent.find_by(code__c: code)
self.where(event__c: event.Id) unless event.blank?
end

def self.where(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobjects = Sf.client.query("select Id, Name, title__c, primary_track_id__r.Name, session_type__r.Name, start_time__c, room_id__r.Name, cms_session_id__c from EventSession__c where #{where}")
build_collection sobjects unless sobjects.blank?
end
end

18 changes: 18 additions & 0 deletions lib/sf/session_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Sf::SessionType
include Sf::Base
attr_reader :sobject, :sesstion_type
def initialize(sobject=nil)
@sobject = sobject.nil? ? Restforce::SObject.new(sobject_type: 'EventSessionType__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


end

17 changes: 17 additions & 0 deletions lib/sf/track.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Sf::Track
include Sf::Base
attr_reader :sobject
attr_accessor :track

def initialize(sobject=nil)
@sobject = sobject.nil? ? Restforce::SObject.new(sobject_type: 'EventTrack__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
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.0.4"
VERSION = "0.1.4"
end

0 comments on commit b54c7d4

Please sign in to comment.