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: JoshvaR88/salesforce_integration
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: railsdog/salesforce_integration
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Oct 21, 2014

  1. Copy the full SHA
    f8e632b View commit details
  2. IN-392 Bump VCR, webmock; Add .rspec; Ignore .env

    Pablo Cantero committed Oct 21, 2014
    Copy the full SHA
    5892c5e View commit details
  3. IN-392 Fix order spec

    Pablo Cantero committed Oct 21, 2014
    Copy the full SHA
    3637957 View commit details
  4. IN-392 Add rake console

    Pablo Cantero committed Oct 21, 2014
    Copy the full SHA
    9c22a35 View commit details
  5. Copy the full SHA
    0e397ba View commit details
  6. Copy the full SHA
    8851ab9 View commit details
  7. Dont allow http connection when no cassetes

    Avoid tests taking forever .. faster feedback
    huoxito committed Oct 21, 2014
    Copy the full SHA
    6920cf0 View commit details
  8. Copy the full SHA
    bb96ca0 View commit details
  9. IN-392 Changes account finder, changes cassettes, changes custom obje…

    …ct order to oportunity
    reinaldob committed Oct 21, 2014
    Copy the full SHA
    e0065cf View commit details

Commits on Oct 22, 2014

  1. Copy the full SHA
    47a0940 View commit details
  2. Copy the full SHA
    9b63522 View commit details
  3. Copy the full SHA
    63e9289 View commit details
  4. Copy the full SHA
    5eec38d View commit details

Commits on Oct 24, 2014

  1. Add /get_products webhook

    huoxito committed Oct 24, 2014
    Copy the full SHA
    32ad8ab View commit details
  2. Drop Spree_services/product.rb ..

    Cant really see a reason for having this file here. Less code to
    maintain
    huoxito committed Oct 24, 2014
    Copy the full SHA
    11d73f9 View commit details
  3. Copy the full SHA
    7c4150a View commit details
  4. Copy the full SHA
    08deed2 View commit details

Commits on Oct 27, 2014

  1. drop Spree_services/customer

    huoxito committed Oct 27, 2014
    Copy the full SHA
    e96afde View commit details
  2. Upgrade add / update customer webhooks

    and clean up cassetes.
    
    Account__c breaks on latest salesforce:
    
            INVALID_FIELD:
            select Account__c from Contact where Email
                   ^
            ERROR at Row:1:Column:8
            No such column 'Account__c' on entity 'Contact'. If you are attempting to use a custom field, be sure to append the '__c'
    er the custom field name. Please reference your WSDL or the describe call for the appropriate names.
    huoxito committed Oct 27, 2014
    Copy the full SHA
    5c692d7 View commit details
  3. endpoint_base bump

    huoxito committed Oct 27, 2014
    Copy the full SHA
    293e6c2 View commit details
  4. Copy the full SHA
    16ce1d5 View commit details
  5. Add /get_customers webhook

    huoxito committed Oct 27, 2014
    Copy the full SHA
    13bccb5 View commit details
  6. Copy the full SHA
    3ed80bb View commit details
  7. Copy the full SHA
    56eccc8 View commit details
  8. Copy the full SHA
    4aa8af3 View commit details

Commits on Oct 28, 2014

  1. Copy the full SHA
    5806cf9 View commit details

Commits on Dec 16, 2014

  1. update cassetes

    huoxito committed Dec 16, 2014
    Copy the full SHA
    94cb154 View commit details
  2. Add sku to product objects

    huoxito committed Dec 16, 2014
    Copy the full SHA
    e36d555 View commit details
  3. Make the send orders webhook work

    Currently taking forever to process /add_order .. code needs some major
    dedesign
    huoxito committed Dec 16, 2014
    Copy the full SHA
    939ceac View commit details
  4. bump endpoint_base

    huoxito committed Dec 16, 2014
    Copy the full SHA
    4ac8fbb View commit details
  5. Copy the full SHA
    c2cb1ff View commit details
  6. IN-392 Adds services to app

    reinaldob committed Dec 16, 2014
    Copy the full SHA
    701df12 View commit details
  7. Copy the full SHA
    ec01685 View commit details
  8. Copy the full SHA
    024faaa View commit details
  9. Copy the full SHA
    a8a03b8 View commit details
  10. Copy the full SHA
    ce828d7 View commit details
  11. Copy the full SHA
    110cef5 View commit details
  12. Copy the full SHA
    393d803 View commit details
  13. Copy the full SHA
    b1ccb3f View commit details
  14. Copy the full SHA
    bd82043 View commit details
  15. Copy the full SHA
    4fce921 View commit details
  16. Drop most SpreeService classes

    they just delegated method to other classes, no idea why or how that
    would come in handy, feels like just more files and code to keep track of
    huoxito committed Dec 16, 2014
    Copy the full SHA
    eda4fae View commit details
  17. Copy the full SHA
    7650218 View commit details
  18. Pass opportunity_id to Integration::LineItem

    So it doesnt have to query again for it
    huoxito committed Dec 16, 2014
    Copy the full SHA
    896588a View commit details
  19. Copy the full SHA
    2ae5bae View commit details
  20. Copy the full SHA
    7ade76d View commit details
  21. Copy the full SHA
    041906a View commit details

Commits on Dec 17, 2014

  1. Copy the full SHA
    59435d8 View commit details
  2. Copy the full SHA
    f0bb30e View commit details
  3. Copy the full SHA
    365f7f4 View commit details
Showing with 7,895 additions and 1,427 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 .rspec
  3. +24 −0 Dockerfile
  4. +5 −3 Gemfile
  5. +23 −13 Gemfile.lock
  6. +1 −0 README.md
  7. +32 −0 Rakefile
  8. +0 −6 app.rb
  9. +6 −1 config.ru
  10. +0 −3 config/environment.rb
  11. +0 −1 config/environments/development.rb
  12. +0 −4 config/environments/production.rb
  13. 0 config/environments/test.rb
  14. +26 −0 lib/SF_services/account.rb
  15. +53 −9 lib/SF_services/base.rb
  16. +40 −2 lib/SF_services/contact.rb
  17. +10 −19 lib/SF_services/line_item.rb
  18. +23 −0 lib/SF_services/note.rb
  19. +59 −19 lib/SF_services/order.rb
  20. +0 −33 lib/SF_services/payment.rb
  21. +68 −3 lib/SF_services/product.rb
  22. +0 −40 lib/Spree_services/base.rb
  23. +0 −8 lib/Spree_services/customer.rb
  24. +0 −8 lib/Spree_services/line_item.rb
  25. +0 −8 lib/Spree_services/order.rb
  26. +0 −8 lib/Spree_services/payment.rb
  27. +0 −8 lib/Spree_services/product.rb
  28. +0 −8 lib/Spree_services/return.rb
  29. +49 −4 lib/integrations/base.rb
  30. +25 −4 lib/integrations/builders/account.rb
  31. +3 −2 lib/integrations/builders/contact.rb
  32. +3 −6 lib/integrations/builders/line_item.rb
  33. +11 −16 lib/integrations/builders/order.rb
  34. +0 −37 lib/integrations/builders/order_from_sf.rb
  35. +0 −23 lib/integrations/builders/order_product.rb
  36. +13 −5 lib/integrations/builders/payment.rb
  37. +13 −7 lib/integrations/builders/product.rb
  38. +32 −0 lib/integrations/builders/return.rb
  39. +50 −9 lib/integrations/contact_account.rb
  40. +0 −32 lib/integrations/line_item.rb
  41. +143 −5 lib/integrations/order.rb
  42. +0 −36 lib/integrations/payment.rb
  43. +36 −20 lib/integrations/product.rb
  44. +5 −31 lib/integrations/return.rb
  45. +49 −0 lib/integrations/shipment.rb
  46. +5 −13 lib/salesforce_integration.rb
  47. +58 −44 salesforce_endpoint.rb
  48. +1,470 −0 spec/cassettes/requests/TTT54352352345245.yml
  49. +90 −25 spec/cassettes/requests/add_customer.yml
  50. +313 −222 spec/cassettes/requests/add_order.yml
  51. +277 −18 spec/cassettes/requests/add_product.yml
  52. +289 −0 spec/cassettes/requests/add_returns.yml
  53. +290 −0 spec/cassettes/requests/add_shipment.yml
  54. +323 −0 spec/cassettes/requests/add_shipment_custom.yml
  55. +355 −0 spec/cassettes/requests/add_shipment_custom_update.yml
  56. +310 −0 spec/cassettes/requests/get_customers.yml
  57. +168 −0 spec/cassettes/requests/get_orders.yml
  58. +126 −0 spec/cassettes/requests/get_orders_with_filters.yml
  59. +201 −0 spec/cassettes/requests/get_products.yml
  60. +126 −0 spec/cassettes/requests/get_products_empty.yml
  61. +823 −0 spec/cassettes/requests/new_order_pricebook.yml
  62. +127 −0 spec/cassettes/requests/no_shipment.yml
  63. +258 −0 spec/cassettes/requests/opportunity_person_account.yml
  64. +91 −25 spec/cassettes/requests/update_customer.yml
  65. +488 −180 spec/cassettes/requests/update_order.yml
  66. +277 −18 spec/cassettes/requests/update_product.yml
  67. +21 −11 spec/cassettes/services/contact_find_account_id_by_email_false.yml
  68. +21 −11 spec/cassettes/services/contact_find_account_id_by_email_true.yml
  69. +0 −28 spec/lib/SF_services/contact_spec.rb
  70. +0 −32 spec/lib/SF_services/product_spec.rb
  71. +0 −33 spec/lib/Spree_services/base_spec.rb
  72. +0 −12 spec/lib/Spree_services/customer_spec.rb
  73. +0 −12 spec/lib/Spree_services/order_spec.rb
  74. +0 −12 spec/lib/Spree_services/product_spec.rb
  75. +26 −5 spec/lib/integrations/builders/account_spec.rb
  76. +8 −2 spec/lib/integrations/builders/contact_spec.rb
  77. +0 −17 spec/lib/integrations/builders/order_spec.rb
  78. +1 −1 spec/lib/integrations/builders/product_spec.rb
  79. +0 −17 spec/lib/integrations/contact_account_spec.rb
  80. +10 −5 spec/lib/integrations/product_spec.rb
  81. +221 −69 spec/salesforce_endpoint_spec.rb
  82. +18 −3 spec/spec_helper.rb
  83. +6 −6 spec/support/factories/add_customer.json
  84. +4 −42 spec/support/factories/add_product.json
  85. +55 −57 spec/support/factories/add_returns.json
  86. +68 −0 spec/support/factories/new_order.json
  87. +1 −2 spec/support/factories/{add_order.json → order.json}
  88. +68 −0 spec/support/factories/person_account_order.json
  89. +53 −0 spec/support/factories/shipment.json
  90. +31 −0 spec/support/factories/shipment_custom.json
  91. +0 −48 spec/support/factories/update_product.json
  92. +6 −7 spec/support/messages.rb
  93. +7 −9 spec/support/shared_examples.rb
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -18,3 +18,4 @@ _yardoc
doc/

.bundle/install.log
.env
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--order rand
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM rlister/ruby:2.1.5
MAINTAINER Ric Lister, ric@spreecommerce.com

## bundle deps for nokogiri and github gems
RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get install -y \
libxslt-dev libxml2-dev \
git

## help docker cache bundle
WORKDIR /tmp
ADD ./Gemfile /tmp/
ADD ./Gemfile.lock /tmp/
RUN bundle install
RUN rm -f /tmp/Gemfile /tmp/Gemfile.lock

WORKDIR /app
ADD ./ /app

EXPOSE 5000

ENTRYPOINT [ "bundle", "exec" ]
CMD [ "unicorn", "-c", "./config/unicorn.rb", "-p", "5000" ]
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -8,10 +8,12 @@ gem 'endpoint_base', github: 'spree/endpoint_base'
gem 'executrix'
gem 'honeybadger'
gem 'rollbar'
gem 'rake'

group :development do
gem "rake"
gem "pry"
group :development, :test do
gem 'pry'
gem 'pry-byebug'
gem 'dotenv'
end

group :test do
36 changes: 23 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/spree/endpoint_base.git
revision: f6c1859af1175bd4e29aa36823c8b02a2bb722c2
revision: f9e595fbf41c1509a4afc58ab805a7b0e5c74a51
specs:
endpoint_base (0.3)
activesupport
@@ -10,16 +10,21 @@ GIT
GEM
remote: https://rubygems.org/
specs:
activesupport (4.1.0)
activesupport (4.1.8)
i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.5)
addressable (2.3.6)
byebug (2.7.0)
columnize (~> 0.3)
debugger-linecache (~> 1.2)
coderay (1.1.0)
columnize (0.8.9)
crack (0.4.2)
safe_yaml (~> 1.0.0)
debugger-linecache (1.2.0)
diff-lcs (1.2.5)
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
@@ -40,16 +45,16 @@ GEM
hashie (2.0.5)
honeybadger (1.13.0)
json
i18n (0.6.9)
jbuilder (2.0.6)
i18n (0.6.11)
jbuilder (2.2.5)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
json (1.8.1)
kgio (2.9.2)
method_source (0.8.2)
mini_portile (0.5.3)
minitest (5.3.2)
multi_json (1.9.2)
minitest (5.5.0)
multi_json (1.10.1)
multipart-post (1.2.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
@@ -58,6 +63,9 @@ GEM
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-byebug (1.3.2)
byebug (~> 2.7)
pry (~> 0.9.12)
rack (1.5.2)
rack-protection (1.5.2)
rack
@@ -81,38 +89,40 @@ GEM
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rubyzip (1.1.3)
safe_yaml (1.0.1)
safe_yaml (1.0.4)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.5.0)
thor (0.19.1)
thread_safe (0.3.3)
thread_safe (0.3.4)
tilt (1.4.1)
tilt-jbuilder (0.5.3)
jbuilder
tilt (<= 1.4.1)
tzinfo (1.1.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
unicorn (4.8.2)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
vcr (2.8.0)
webmock (1.17.4)
addressable (>= 2.2.7)
vcr (2.9.3)
webmock (1.19.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)

PLATFORMS
ruby

DEPENDENCIES
dotenv
endpoint_base!
executrix
foreman
honeybadger
pry
pry-byebug
rack-test
rake
restforce
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ product. With this integration you can perform the following functions:
* Send returns to Salesforce
* Send products to Salesforce
* Send customers to Salesforce
* Send custom fields to Salesforce

[Wombat](http://wombat.co) allows you to connect to your own custom integrations.
Feel free to modify the source code and host your own version of the integration
32 changes: 32 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$stdout.sync = true

require 'bundler'
Bundler.require(:default)

desc 'Open pry console'
task :console do
require 'pry'
require_relative 'lib/salesforce_integration'

env_file = File.join File.expand_path('..', __FILE__), '.env'

if File.exist? env_file
require 'dotenv'
Dotenv.load

@client = Restforce.new(
instance_url: ENV['SALESFORCE_INSTANCE_URL'],
oauth_token: ENV['SALESFORCE_ACCESS_TOKEN'],
refresh_token: ENV['SALESFORCE_REFRESH_TOKEN'],
client_id: ENV['SALESFORCE_CLIENT_ID'],
client_secret: ENV['SALESFORCE_CLIENT_SECRET']
)
end

def client
@client
end

ARGV.clear
Pry.start
end
6 changes: 0 additions & 6 deletions app.rb

This file was deleted.

7 changes: 6 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
require './app'
require 'rubygems'
require 'bundler'

Bundler.require(:default)
require './salesforce_endpoint.rb'

run SalesforceEndpoint
3 changes: 0 additions & 3 deletions config/environment.rb

This file was deleted.

1 change: 0 additions & 1 deletion config/environments/development.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/environments/production.rb

This file was deleted.

Empty file removed config/environments/test.rb
Empty file.
26 changes: 26 additions & 0 deletions lib/SF_services/account.rb
Original file line number Diff line number Diff line change
@@ -3,5 +3,31 @@ class Account < Base
def initialize(config)
super("Account", config)
end

def find_account_id_by_email(email)
results = salesforce.query("SELECT Contact.Account.Id FROM Contact WHERE Email = '#{email}'")
results.any? ? results.first['Account']['Id'] : nil
end

def fetch_contacts_along(ids)
fields = ["Account.Id",
"Account.BillingCity",
"Account.BillingCountry",
"Account.BillingPostalCode",
"Account.BillingState",
"Account.BillingStreet",
"Account.Name",
"Account.Phone",
"Account.ShippingCity",
"Account.ShippingCountry",
"Account.ShippingPostalCode",
"Account.ShippingState",
"Account.ShippingStreet"].join(", ")

contacts = "SELECT FirstName, LastName, Email FROM Contacts"
filter = "Id IN (#{ids.join(", ")})"

salesforce.query("SELECT #{fields}, (#{contacts}) FROM Account WHERE #{filter}")
end
end
end
62 changes: 53 additions & 9 deletions lib/SF_services/base.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
module SFService
# Note about `query` methods:
#
# http://www.salesforce.com/us/developer/docs/api_rest/Content/resources_query.htm
#
# If the query results are too large, the response contains the first batch
# of results and a query identifier in the nextRecordsUrl field of the
# response. The identifier can be used in an additional request to retrieve
# the next batch.
#
#
# About Salesforce Object Query Language (SOQL):
#
# http://www.salesforce.com/us/developer/docs/soql_sosl/index.htm
#
class Base
attr_reader :salesforce, :config, :model_name

def initialize(model_name, config)
@model_name = model_name
@config = config
@salesforce = config[:salesforce] || client
end

def create!(attributes = {})
@@ -15,16 +30,45 @@ def update!(attributes = {})
salesforce.update!(model_name, attributes)
end

def client
Restforce.new user_credentials.merge(app_credentials)
end

private
def user_credentials
if config[:salesforce_instance_url].present?
oauth_params
else
user_passwd_params
end
end

def salesforce
@salesforce ||= Restforce.new(
username: config['salesforce_username'],
password: config['salesforce_password'],
security_token: config['salesforce_security_token'],
client_id: config['salesforce_client_id'],
client_secret: config['salesforce_client_secret']
)
end
def app_credentials
{
client_id: ENV['SALESFORCE_CLIENT_ID'],
client_secret: ENV['SALESFORCE_CLIENT_SECRET']
}
end

def oauth_params
initial = {
instance_url: config[:salesforce_instance_url],
oauth_token: config[:salesforce_access_token]
}

if config[:salesforce_refresh_token].present?
initial.merge refresh_token: config[:salesforce_refresh_token]
else
initial
end
end

def user_passwd_params
{
username: config[:salesforce_username],
password: config[:salesforce_password],
security_token: config[:salesforce_security_token],
}
end
end
end
42 changes: 40 additions & 2 deletions lib/SF_services/contact.rb
Original file line number Diff line number Diff line change
@@ -11,13 +11,51 @@ def find_id_by_email(email)
end

def find_account_id_by_email(email)
results = salesforce.query("select Account__c from Contact where Email = '#{email}'")
results.any? ? results.first['Account__c'] : nil
results = salesforce.query("select AccountId from Contact where Email = '#{email}'")
results.any? ? results.first['AccountId'] : nil
end

def upsert!(email, attributes = {})
contact_id = find_id_by_email(email)
contact_id.present? ? update!(attributes.merge({ Id: contact_id })) : create!(attributes)
end

def person_contact_update!(account_id, attributes)
results = salesforce.query("select Id from Contact where AccountId = '#{account_id}'")
update! attributes.merge(Id: results.first.to_h['Id'])
end

def latest_updates(time = Time.now.utc.iso8601)
since = time ? Time.parse(time).utc.iso8601 : Time.now.utc.iso8601

fields = ["Contact.Id",
"Contact.Firstname",
"Contact.Lastname",
"Contact.Email",
"Contact.Account.Name",
"Contact.Account.AccountNumber",
"Contact.Account.BillingCity",
"Contact.Account.BillingCountry",
# "Contact.Account.BillingCountryCode",
"Contact.Account.BillingPostalCode",
"Contact.Account.BillingState",
# "Contact.Account.BillingStateCode",
"Contact.Account.BillingStreet",
"Contact.Account.Rating",
"Contact.Account.Phone",
"Contact.Account.ShippingCity",
"Contact.Account.ShippingCountry",
# "Contact.Account.ShippingCountryCode",
"Contact.Account.ShippingPostalCode",
"Contact.Account.ShippingState",
# "Contact.Account.ShippingStateCode",
"Contact.Account.ShippingStreet",
"Contact.Account.Website",
"Contact.Account.Type",
"Contact.LastModifiedDate"]

filter = "LastModifiedDate > #{since} ORDER BY LastModifiedDate ASC LIMIT 100"
salesforce.query("SELECT #{fields.join(", ")} FROM Contact WHERE #{filter}")
end
end
end
Loading