afc_salesforce 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/README.md +1 -0
  8. data/Rakefile +6 -0
  9. data/afc_salesforce.gemspec +40 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/afc_salesforce.rb +56 -0
  13. data/lib/afc_salesforce/account.rb +61 -0
  14. data/lib/afc_salesforce/additional_income.rb +12 -0
  15. data/lib/afc_salesforce/ahc_realtor.rb +0 -0
  16. data/lib/afc_salesforce/asset.rb +13 -0
  17. data/lib/afc_salesforce/base.rb +11 -0
  18. data/lib/afc_salesforce/borrower.rb +36 -0
  19. data/lib/afc_salesforce/configuration.rb +16 -0
  20. data/lib/afc_salesforce/forms/agent_referral.rb +50 -0
  21. data/lib/afc_salesforce/forms/long_purchase.rb +56 -0
  22. data/lib/afc_salesforce/forms/long_refinance.rb +56 -0
  23. data/lib/afc_salesforce/forms/short_lead.rb +48 -0
  24. data/lib/afc_salesforce/lead.rb +31 -0
  25. data/lib/afc_salesforce/models/account.rb +267 -0
  26. data/lib/afc_salesforce/models/ahc_realtor.rb +67 -0
  27. data/lib/afc_salesforce/models/asset.rb +35 -0
  28. data/lib/afc_salesforce/models/base.rb +17 -0
  29. data/lib/afc_salesforce/models/concerns/type_setter.rb +23 -0
  30. data/lib/afc_salesforce/models/contact.rb +152 -0
  31. data/lib/afc_salesforce/models/income.rb +25 -0
  32. data/lib/afc_salesforce/models/lead.rb +118 -0
  33. data/lib/afc_salesforce/tools.rb +4 -0
  34. data/lib/afc_salesforce/tools/utilities.rb +45 -0
  35. data/lib/afc_salesforce/tools/validation.rb +18 -0
  36. data/lib/afc_salesforce/tools/validation/rule/email.rb +58 -0
  37. data/lib/afc_salesforce/tools/validation/rule/instance_of.rb +36 -0
  38. data/lib/afc_salesforce/tools/validation/rule/length.rb +52 -0
  39. data/lib/afc_salesforce/tools/validation/rule/matches.rb +44 -0
  40. data/lib/afc_salesforce/tools/validation/rule/not_empty.rb +32 -0
  41. data/lib/afc_salesforce/tools/validation/rule/not_nil.rb +32 -0
  42. data/lib/afc_salesforce/tools/validation/rule/numeric.rb +32 -0
  43. data/lib/afc_salesforce/tools/validation/rule/phone.rb +51 -0
  44. data/lib/afc_salesforce/tools/validation/rule/regular_expression.rb +33 -0
  45. data/lib/afc_salesforce/tools/validation/validator.rb +128 -0
  46. data/lib/afc_salesforce/version.rb +3 -0
  47. metadata +194 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e768c92706638383120f1a7722c63675f21244b8
4
+ data.tar.gz: ee5f3bf779bb49689fe65a92423e87b525549cc1
5
+ SHA512:
6
+ metadata.gz: 5ce372b9c6846645309d931b9a0e76cd9df20ba83d7ee5fd88180902bd2ea8f918fd702d10aa918a5e9419f4e2d5c0ef01e564b9d703e6bd75a4e1bf296971e0
7
+ data.tar.gz: c553e5d3c96746197d89807f7d6bad29e54ed9b48e6c0beaec3c2a634b632d1b53bddeeacc75672d244801eaaa110ff06f39c01456c48e7c8085046acae1db93
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at donavan.white@americanfinancing.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in afc-salesforce.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Gem for connecting to SalesForce (Not for production use)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'afc_salesforce/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "afc_salesforce"
8
+ spec.version = AFCSalesforce::VERSION
9
+ spec.authors = ["Donavan White"]
10
+ spec.email = ["donavan.white@americanfinancing.net"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = %q{Salesforce Library for the AFC Salesforce Instance}
14
+ spec.description = %q{Ruby lib for handling the connection to REST endpoints on any Sandbox and Production Salesforce}
15
+ spec.homepage = "https://www.americanfinancing.net"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.14"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "simplecov", "~> 0.14"
37
+ spec.add_development_dependency "factory_girl", "~> 4.8"
38
+ spec.add_runtime_dependency 'restforce', '~> 2.5', '>= 2.5.3'
39
+ spec.add_dependency "json", "~> 1.7"
40
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "afc/salesforce"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ require 'time'
2
+ require 'json'
3
+ require 'restforce'
4
+
5
+ require_relative 'afc_salesforce/configuration'
6
+
7
+ require_relative 'afc_salesforce/tools/utilities'
8
+ require_relative 'afc_salesforce/tools/validation'
9
+ require_relative 'afc_salesforce/tools/validation/rule/email'
10
+ require_relative 'afc_salesforce/tools/validation/rule/length'
11
+ require_relative 'afc_salesforce/tools/validation/rule/matches'
12
+ require_relative 'afc_salesforce/tools/validation/rule/not_empty'
13
+ require_relative 'afc_salesforce/tools/validation/rule/not_nil'
14
+ require_relative 'afc_salesforce/tools/validation/rule/numeric'
15
+ require_relative 'afc_salesforce/tools/validation/rule/phone'
16
+ require_relative 'afc_salesforce/tools/validation/rule/regular_expression'
17
+ require_relative 'afc_salesforce/tools/validation/rule/instance_of'
18
+
19
+ require_relative 'afc_salesforce/models/concerns/type_setter'
20
+ require_relative 'afc_salesforce/models/base'
21
+ require_relative 'afc_salesforce/models/account'
22
+ require_relative 'afc_salesforce/models/asset'
23
+ require_relative 'afc_salesforce/models/contact'
24
+ require_relative 'afc_salesforce/models/income'
25
+ require_relative 'afc_salesforce/models/lead'
26
+
27
+ require_relative 'afc_salesforce/base'
28
+ require_relative 'afc_salesforce/account'
29
+ require_relative 'afc_salesforce/additional_income'
30
+ require_relative 'afc_salesforce/asset'
31
+ require_relative 'afc_salesforce/borrower'
32
+ require_relative 'afc_salesforce/lead'
33
+
34
+ require_relative 'afc_salesforce/forms/long_purchase'
35
+ require_relative 'afc_salesforce/forms/long_refinance'
36
+ require_relative 'afc_salesforce/forms/short_lead'
37
+
38
+ require_relative 'afc_salesforce/version'
39
+
40
+ module AFCSalesforce
41
+ class << self
42
+ attr_accessor :configuration
43
+ end
44
+
45
+ def self.configuration
46
+ @configuration ||= Configuration.new
47
+ end
48
+
49
+ def self.reset
50
+ @configuration = Configuration.new
51
+ end
52
+
53
+ def self.configure
54
+ yield(configuration)
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ module AFCSalesforce
2
+ class Account < Base
3
+ attr_accessor :phone, :email, :street, :zip, :state, :city, :loan_type, :purchase_date,
4
+ :property_address, :property_city, :property_state, :property_zip, :property_type, :program_type, :last_appraisal__c,
5
+ :loan_purpose, :property_bedroom_count, :property_acre_count, :property_bathroom_count, :property_price, :property_close_date, :is_escrowed,
6
+ :property_down_payment, :realtor_email, :realtor_name, :realtor_phone, :source, :endorser, :realtor_sign_up_date,
7
+ :initial_purchase_price, :date_of_purchase, :refinance_loan_type, :approximate_value, :date_of_last_appraisal,
8
+ :appraised_value, :square_feet, :first_mortgage_payment, :first_mortgage_balance, :first_mortgage_interest_rate,
9
+ :monthly_taxes, :monthly_insurance, :name, :hoa_dues, :is_va_eligible, :purchase_close_date, :second_mortgage, :second_mortgage_payment,
10
+ :second_mortgage_date_opened, :second_mortgage_balance, :x2nd_mortgage_date_opened__c, :second_mortgage_rate, :refinance_reason,
11
+ :number_of_units, :session_uuid
12
+
13
+ def to_h
14
+ AFCSalesforce::Models::Account.new(
15
+ acres__c: @property_acre_count,
16
+ appraised_value__c: @appraised_value,
17
+ approximate_value__c: @approximate_value,
18
+ bathrooms__c: @property_bathroom_count,
19
+ bedrooms__c: @property_bedroom_count,
20
+ billingpostalcode: @zip,
21
+ billingstate: @state,
22
+ billingstreet: @street,
23
+ down_payment__c: @property_down_payment,
24
+ endorser__c: @endorser,
25
+ escrowed__c: @is_escrowed,
26
+ hoa_dues__c: @hoa_dues,
27
+ last_appraisal__c: @date_of_last_appraisal,
28
+ loan_type__c: @refinance_loan_type,
29
+ loan_purpose__c: @loan_purpose,
30
+ monthly_insurance__c: @monthly_insurance,
31
+ monthly_taxes__c: @monthly_taxes,
32
+ name: @name,
33
+ new_purchase_price__c: @property_price,
34
+ number_of_units__c: @number_of_units,
35
+ original_purchase_price__c: @initial_purchase_price,
36
+ phone: @phone,
37
+ program_type__c: @program_type,
38
+ property_type__c: @property_type,
39
+ purchase_date__c: @purchase_date,
40
+ puchase_close_date__c: @purchase_close_date,
41
+ realtor_email__c: @realtor_email,
42
+ realtor_name__c: @realtor_name,
43
+ realtor_phone_number__c: @realtor_phone,
44
+ refinance_purpose__c: @refinance_reason,
45
+ session_uuid__c: @session_uuid,
46
+ source__c: @source,
47
+ square_feet__c: @square_feet,
48
+ type__c: @loan_type,
49
+ va_eligible__c: @is_va_eligible,
50
+ x1st_mortgage_balance__c: @first_mortgage_balance,
51
+ x1st_mortgage_payment__c: @first_mortgage_payment,
52
+ x1st_mortgage_rate__c: @first_mortgage_interest_rate,
53
+ x2nd_mortgage__c: @second_mortgage,
54
+ x2nd_mortgage_balance__c: @second_mortgage_balance,
55
+ x2nd_mortgage_date_opened__c: @second_mortgage_date_opened,
56
+ x2nd_mortgage_payment__c: @second_mortgage_payment,
57
+ x2nd_mortgage_rate__c: @second_mortgage_rate
58
+ ).to_h
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ module AFCSalesforce
2
+ class AdditionalIncome < Base
3
+ attr_accessor :owner, :type, :description, :amount, :is_owner_self_employed
4
+
5
+ def to_h
6
+ AFCSalesforce::Models::Income.new(
7
+ amount__c: @amount,
8
+ type__c: @type
9
+ ).to_h
10
+ end
11
+ end
12
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ module AFCSalesforce
2
+ class Asset < Base
3
+ attr_accessor :name, :type, :value, :owner
4
+
5
+ def to_h
6
+ AFCSalesforce::Models::Asset.new(
7
+ asset_value__c: @value,
8
+ name: @name,
9
+ asset_type__c: @type
10
+ ).to_h
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module AFCSalesforce
2
+ class Base
3
+ extend AFCSalesforce::Models::Concerns::TypeSetter
4
+
5
+ def initialize(options={})
6
+ options.each do |attribute_name, attribute_value|
7
+ self.send("#{attribute_name}=".to_sym, attribute_value)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module AFCSalesforce
2
+ class Borrower < Base
3
+ attr_accessor :first_name, :income_type, :middle_name, :last_name, :phone,
4
+ :ssn, :email, :street, :city, :state, :zip, :company_name,
5
+ :marital_status, :suffix
6
+
7
+ set_as_integer :monthly_income, :yearly_income, :years_on_job
8
+ set_as_boolean :is_self_employed, :is_primary
9
+ set_as_date :birthdate
10
+
11
+ def to_h
12
+ AFCSalesforce::Models::Contact.new(
13
+ additional_income_type__c: @income_type,
14
+ firstname: @first_name,
15
+ middle_name__c: @middle_name,
16
+ lastname: @last_name,
17
+ suffix__c: @suffix,
18
+ phone: @phone,
19
+ ssn__c: @ssn,
20
+ email: @email,
21
+ marital_status__c: @marital_status,
22
+ mailingstreet: @street,
23
+ mailingcity: @city,
24
+ mailingstate: @state,
25
+ mailingpostalcode: @zip,
26
+ bor_company_name__c: @company_name,
27
+ monthly_income__c: @monthly_income,
28
+ yearly_income__c: @yearly_income,
29
+ years_on_the_job__c: @years_on_job,
30
+ is_self_employed__c: @is_self_employed,
31
+ primary_borrower__c: @is_primary,
32
+ birthdate: @birthdate
33
+ ).to_h
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ module AFCSalesforce
2
+ class Configuration
3
+ attr_accessor :salesforce_host, :salesforce_username, :salesforce_password, :salesforce_security_token,
4
+ :salesforce_client_id, :salesforce_client_secret, :salesforce_api_version
5
+
6
+ def initialize
7
+ @salesforce_host = nil
8
+ @salesforce_username = nil
9
+ @salesforce_password = nil
10
+ @salesforce_security_token = nil
11
+ @salesforce_client_id = nil
12
+ @salesforce_client_secret = nil
13
+ @salesforce_api_version = nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ module AFCSalesforce
2
+ module Forms
3
+ class AgentReferral
4
+ attr_accessor :lead, :ahc_realtor
5
+
6
+ def initialize(options={})
7
+ @lead = options[:lead]
8
+ @ahc_realtor = options[:ahc_realtor]
9
+ end
10
+
11
+ def valid?
12
+ validator = AgentReferralValidator.new(self)
13
+ validator.valid?
14
+ end
15
+
16
+ def validate!
17
+ validator = AgentReferralValidator.new(self)
18
+ if validator.valid?
19
+ return true
20
+ else
21
+ return validator.errors
22
+ end
23
+ end
24
+
25
+ def salesforce_hash
26
+ {
27
+ short_lead: {
28
+ lead: @lead.to_h
29
+ }
30
+ }
31
+ end
32
+
33
+ def send_to_salesforce
34
+ Restforce.new(
35
+ username: AFCSalesforce.configuration.salesforce_username,
36
+ password: AFCSalesforce.configuration.salesforce_password,
37
+ client_id: AFCSalesforce.configuration.salesforce_client_id,
38
+ client_secret: AFCSalesforce.configuration.salesforce_client_secret,
39
+ api_version: AFCSalesforce.configuration.salesforce_api_version
40
+ ).post(URI('/services/apexrest/v1/lead_form'), salesforce_hash)
41
+ end
42
+ end
43
+
44
+ class AgentReferralValidator < AFCSalesforce::Tools::Validation::Validator
45
+ include AFCSalesforce::Tools::Validation
46
+ rule :lead, [{instance_of: AFCSalesforce::Lead}, :not_nil]
47
+ rule :ahc_realtor, [{instance_of: AFCSalesforce::AHCRealtor}, :not_nil]
48
+ end
49
+ end
50
+ end