Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Ioannis/sf
base: main
Choose a base ref
...
head repository: Internet2-TSG/sf
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Jun 28, 2022

  1. Copy the full SHA
    0161b74 View commit details

Commits on Jun 29, 2022

  1. Copy the full SHA
    c8bac97 View commit details

Commits on Jun 30, 2022

  1. Copy the full SHA
    a4cfd3a View commit details
  2. Copy the full SHA
    a6f2277 View commit details
  3. increased the version to 0.1.66

    ij committed Jun 30, 2022
    Copy the full SHA
    f66ec9e View commit details
  4. Copy the full SHA
    369124c View commit details
  5. Copy the full SHA
    baebfb8 View commit details

Commits on Jul 2, 2022

  1. reformatted, no other changes

    ij committed Jul 2, 2022
    Copy the full SHA
    dd60973 View commit details
  2. Sf.client.query('select ') returns nil instead of [] now, so added li…

    …ne to return [] when the query result is nil
    ij committed Jul 2, 2022
    Copy the full SHA
    5c9a7b1 View commit details
  3. increased the version to 0.1.69

    ij committed Jul 2, 2022
    Copy the full SHA
    c299f2c View commit details

Commits on Aug 8, 2022

  1. Copy the full SHA
    8228720 View commit details

Commits on Oct 5, 2022

  1. Copy the full SHA
    56cc729 View commit details

Commits on Oct 11, 2022

  1. added RegEvent#active_since

    ij committed Oct 11, 2022
    Copy the full SHA
    339235e View commit details

Commits on Oct 14, 2022

  1. updated session.rb for new cfp app

    ij committed Oct 14, 2022
    Copy the full SHA
    2830590 View commit details
  2. increased the version

    ij committed Oct 14, 2022
    Copy the full SHA
    8709e31 View commit details

Commits on Oct 20, 2022

  1. Copy the full SHA
    6bbcc42 View commit details
  2. Copy the full SHA
    ce06d40 View commit details
  3. Copy the full SHA
    45766e9 View commit details

Commits on Oct 24, 2022

  1. Updated README

    ij committed Oct 24, 2022
    Copy the full SHA
    b18d6fd View commit details

Commits on Jan 6, 2023

  1. Copy the full SHA
    9dc1700 View commit details

Commits on Aug 30, 2023

  1. Copy the full SHA
    114ad77 View commit details

Commits on Feb 6, 2024

  1. Copy the full SHA
    a063a63 View commit details
Showing with 1,109 additions and 1,043 deletions.
  1. +12 −2 README.md
  2. +34 −31 lib/sf.rb
  3. +109 −107 lib/sf/account.rb
  4. +13 −14 lib/sf/base.rb
  5. +164 −161 lib/sf/contact.rb
  6. +34 −31 lib/sf/contact_affiliation.rb
  7. +51 −46 lib/sf/opportunity.rb
  8. +20 −17 lib/sf/presenter.rb
  9. +103 −90 lib/sf/reg_event.rb
  10. +36 −34 lib/sf/reg_meeting.rb
  11. +42 −40 lib/sf/reg_meeting_option_association.rb
  12. +43 −41 lib/sf/reg_option.rb
  13. +36 −34 lib/sf/reg_rate.rb
  14. +205 −193 lib/sf/reg_registration.rb
  15. +39 −37 lib/sf/service_institution.rb
  16. +98 −102 lib/sf/session.rb
  17. +51 −48 lib/sf/sponsorship.rb
  18. +3 −1 lib/sf/version.rb
  19. +16 −14 sf.gemspec
14 changes: 12 additions & 2 deletions README.md
@@ -9,7 +9,7 @@ Add the sf gem to your application's Gemfile:
For example,

```
gem 'sf', :git => 'git+ssh://github.internet2.edu/Internet2-TSG/sf.git', :tag => 'v0.1.34'
gem 'sf', :git => 'git+ssh://github.internet2.edu/Internet2-TSG/sf.git', :tag => 'v0.1.66'
```

And then execute:
@@ -28,7 +28,17 @@ In the hosting application, a configuration file, for example
security_token: xxxxxxxxxxxxx
client_id: xxxxxxxxxxxxxxxxxxxx
client_secret: xxxxxxxxxxxxxx
api_version: '24.0'
api_version: '41.0'
```
Or
```
host: <%= ENV["SF_HOST"] %>
username: <%= ENV["SF_USERNAME"] %>
password: <%= ENV["SF_PASSWORD"] %>
security_token: <%= ENV["SF_SECURITY_TOKEN"] %>
client_id: <%= ENV["SF_CLIENT_ID"] %>
client_secret: <%= ENV["SF_CLIENT_SECRET"] %>
api_version: <%= ENV["SF_API_VERSION"] %>
```

Please refer to [https://github.com/ejholmes/restforce](https://github.com/ejholmes/restforce) for the detail.
65 changes: 34 additions & 31 deletions lib/sf.rb
@@ -1,38 +1,41 @@
require "restforce"
require "sf/version"
require "sf/base"
require "sf/account"
require "sf/contact"
require "sf/contact_affiliation"
require "sf/reg_event"
require "sf/reg_meeting"
require "sf/reg_option"
require "sf/reg_rate"
require "sf/reg_registration"
require "sf/reg_item"
require "sf/reg_meeting_option_association.rb"
require "sf/session"
require "sf/session_type"
require "sf/track"
require "sf/presenter"
require "sf/sponsorship"
require "sf/room"
require "sf/venue"
require "sf/opportunity"
require "sf/service_institution"
require "sf/report"
# frozen_string_literal: true

require 'restforce'
require 'sf/version'
require 'sf/base'
require 'sf/account'
require 'sf/contact'
require 'sf/contact_affiliation'
require 'sf/reg_event'
require 'sf/reg_meeting'
require 'sf/reg_option'
require 'sf/reg_rate'
require 'sf/reg_registration'
require 'sf/reg_item'
require 'sf/reg_meeting_option_association'
require 'sf/session'
require 'sf/session_type'
require 'sf/track'
require 'sf/presenter'
require 'sf/sponsorship'
require 'sf/room'
require 'sf/venue'
require 'sf/opportunity'
require 'sf/service_institution'
require 'sf/report'
module Sf
class << self
def client
if @client.nil?
if File.exist?("#{::Rails.root.to_s}/config/restforce.yml")
sfdc_auth_config = YAML.load(ERB.new(File.read("#{::Rails.root.to_s}/config/restforce.yml")).result)
@client = Restforce.new :host => sfdc_auth_config['host'],
:username => sfdc_auth_config['username'],
:password => sfdc_auth_config['password'],
:security_token => sfdc_auth_config['security_token'],
:client_id => sfdc_auth_config['client_id'],
:client_secret => sfdc_auth_config['client_secret']
if File.exist?("#{::Rails.root}/config/restforce.yml")
sfdc_auth_config = YAML.safe_load(ERB.new(File.read("#{::Rails.root}/config/restforce.yml")).result)
@client = Restforce.new host: sfdc_auth_config['host'],
username: sfdc_auth_config['username'],
password: sfdc_auth_config['password'],
security_token: sfdc_auth_config['security_token'],
client_id: sfdc_auth_config['client_id'],
client_secret: sfdc_auth_config['client_secret'],
api_version: sfdc_auth_config['api_version'] || '41.0'
end
else
@client
216 changes: 109 additions & 107 deletions lib/sf/account.rb
@@ -1,123 +1,125 @@
class Sf::Account
include Sf::Base
# frozen_string_literal: true

FIELDS = ['Id', 'Name', 'Member_Type__c', 'Member_Category__c', 'MOU_Participant__c', 'Member_Join_Date__c', 'Status__c', 'Website', 'InCommon_Participant__c', 'InCommon_Participation__c', 'iMIS_ID__c', 'Membership_Status__c']
FIELDS_SELECT_STR = FIELDS.join(', ')
MEMBER_TYPES = ['R&E Network Member', 'University Member', 'Industry Member', 'Affiliate Member']
MEMBER_TYPES_STR = MEMBER_TYPES.map{|v| "\'#{v}\'"}.join(', ')
module Sf
class Account
include Sf::Base

def initialize(account=nil)
@account = account
end
FIELDS = %w[Id Name Member_Type__c Member_Category__c MOU_Participant__c Member_Join_Date__c
Status__c Website InCommon_Participant__c InCommon_Participation__c iMIS_ID__c Membership_Status__c].freeze
FIELDS_SELECT_STR = FIELDS.join(', ')
MEMBER_TYPES = ['R&E Network Member', 'University Member', 'Industry Member', 'Affiliate Member'].freeze
MEMBER_TYPES_STR = MEMBER_TYPES.map { |v| "\'#{v}\'" }.join(', ')

def update(args={})
params = {Id: self.Id}
args.map {|k,v| params[k] = v}
end
def initialize(account = nil)
@account = account
end

def contacts
Sf::Contact.where({AccountId: self.Id, Status__c: 'Active'})
end
def update(args = {})
params = { Id: self.Id }
args.map { |k, v| params[k] = v }
end

def method_missing(method_name, *args, &block)
@account.send(method_name, *args, &block)
end
def contacts
Sf::Contact.where({ AccountId: self.Id, Status__c: 'Active' })
end

def respond_to_missing?(method_name, include_private = false)
@account.respond_to?(method_name, include_private) || super
end
def method_missing(method_name, *args, &block)
@account.send(method_name, *args, &block)
end

def inc_execs
Sf::Contact.inc_execs_for(self.Id)
end
def respond_to_missing?(method_name, include_private = false)
@account.respond_to?(method_name, include_private) || super
end

def inc_part_since_year
if self.InCommon_Participant__c
start_date = start_dates_by_subscription["InCommon Participation"]
start_date.split("-")[0] if start_date
def inc_execs
Sf::Contact.inc_execs_for(self.Id)
end
end

# Class Methods
def self.find(id)
new Sf.client.find("Account", id)
end
def inc_part_since_year
if self.InCommon_Participant__c
start_date = start_dates_by_subscription['InCommon Participation']
start_date.split('-')[0] if start_date
end
end

def self.find_by(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobject = Sf.client.query("select #{FIELDS_SELECT_STR} from Account where #{where}").first
if sobject.present?
new sobject
# Class Methods
def self.find(id)
new Sf.client.find('Account', id)
end
end

def self.intl_partners
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where MOU_Participant__c = true order by Name")
end
def self.find_by(args = {})
where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ')
sobject = Sf.client.query("select #{FIELDS_SELECT_STR} from Account where #{where}").first
new sobject if sobject.present?
end

def self.members
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where Membership_Status__c = true order by Name")
end
def self.intl_partners
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where MOU_Participant__c = true order by Name")
end

def self.all
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account order by Name")
end
def self.members
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where Membership_Status__c = true order by Name")
end

def self.all
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account order by Name")
end

def self.community_orgs
build_collection Sf.client.query(
"select #{FIELDS_SELECT_STR} from Account
def self.community_orgs
build_collection Sf.client.query(
"select #{FIELDS_SELECT_STR} from Account
where Name='Internet2' or InCommon_Participant__c = true
or Membership_Status__c = true
or MOU_Participant__c = true
order by Name"
)
end
)
end

def self.incommon_participants
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true order by Name")
end
def self.incommon_participants
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true order by Name")
end

def self.internet2
i2 = find_by({Name: "Internet2", Status__c: "Active"})
find i2.Id
end
def self.internet2
i2 = find_by({ Name: 'Internet2', Status__c: 'Active' })
find i2.Id
end

def self.member?(account_id)
members.map(&:Id).include?(account_id)
end
def self.member?(account_id)
members.map(&:Id).include?(account_id)
end

def self.inc_part?(account_id)
incommon_participants.map(&:Id).include?(account_id)
end
def self.inc_part?(account_id)
incommon_participants.map(&:Id).include?(account_id)
end

def self.intl_partner?(account_id)
intl_partners.map(&:Id).include?(account_id)
end
def self.intl_partner?(account_id)
intl_partners.map(&:Id).include?(account_id)
end

# Accounts with a closed won opportunity but not yet the "InCommon Control" check box is checked.
def self.inc_parts_to_be
acct_ids = Sf::Opportunity.inc_participations(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c != true and Id in (#{accts_str})")
# Accounts with a closed won opportunity but not yet the "InCommon Control" check box is checked.
def self.inc_parts_to_be
acct_ids = Sf::Opportunity.inc_participations(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map { |v| "\'#{v}\'" }.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c != true and Id in (#{accts_str})")
end
end
end

def self.inc_certs_to_be
acct_ids = Sf::Opportunity.cert_subscribers(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true and Id in (#{accts_str})")
def self.inc_certs_to_be
acct_ids = Sf::Opportunity.cert_subscribers(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map { |v| "\'#{v}\'" }.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true and Id in (#{accts_str})")
end
end
end

def self.active_inc_parts(service_name)
today = Date.today.strftime('%Y-%m-%d')
sobjects = Sf.client.query("select
def self.active_inc_parts(service_name)
today = Date.today.strftime('%Y-%m-%d')
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
@@ -127,11 +129,11 @@ def self.active_inc_parts(service_name)
and (Service_End_Date__c = null or Service_End_Date__c > #{today})
and (Service_Start_Date__c = null or Service_Start_Date__c < #{today})
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r))
end

def self.cert_service_subscribers
sobjects = Sf.client.query("select
def self.cert_service_subscribers
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
@@ -141,21 +143,21 @@ def self.cert_service_subscribers
and Service_End_Date__c = null
and (Type_of_Support__c = 'Subscriber' or Type_of_Support__c = 'subscriber_parent')
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r))
end

private
private

def subscriptions
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end
def subscriptions
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end

# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions.each {|s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c}
start_dates
# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions&.each { |s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c }
start_dates
end
end

end