rd-salesforce 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e0ccff61ad3e03e3168e82a7dfd37b3da8aaa05
4
+ data.tar.gz: 90f8a24f2c83e46cee04d52151f7dc8ec93de562
5
+ SHA512:
6
+ metadata.gz: 674d28b8ca99aaf8cf95a95b54127c487c8bdff474da1d6b5f566b1feda92c005a2167d81acc4907f3a8cf8ae586fe3eeaffbaff6b8edd66b0393ff009411b78
7
+ data.tar.gz: 5999c4b43f99c270f148a2a3ae3eab7dbdb1bc0226648d243f24e8e3d49a893c915590b87fc4bdfa7e0287f68764ffc5a334a4549c50b1f8d5ff21b5d73bd6a6
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rd-salesforce.gemspec
4
+ gemspec
5
+
6
+
7
+ group :test do
8
+ gem "rspec"
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jônatas Davi Paganini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jônatas Paganini
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # Rd::Salesforce
2
+
3
+ Integrates with salesforce allowing to add people as leads.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rd-salesforce', git: "https://github.com/jonatas/rd-salesforce.git"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rd-salesforce https://github.com/jonatas/rd-salesforce.git
20
+
21
+ ## Usage
22
+
23
+ These library consists basically in:
24
+
25
+ * [client.rb](/lib/rd/salesforce/client.rb) - wraps the [RestForce api](https://github.com/ejholmes/restforce) and authentication info.
26
+ * [person.rb](/lib/rd/salesforce/person.rb) - stores and validates the person/lead info
27
+
28
+ ### Setup a client
29
+
30
+ You can use the same [RestForce params to authentication](https://github.com/ejholmes/restforce#oauth-token-authentication) to the client:
31
+
32
+
33
+ ```ruby
34
+ @client = Rd::Salesforce::Client.new instance_url: "https://xx.salesforce.com",
35
+ oauth_token: "xxxxx...."
36
+ ```
37
+
38
+ ### Instance a person
39
+
40
+ ```ruby
41
+ @person = Rd::Salesforce::Person.new
42
+ @person.first_name = "Jônatas"
43
+ @person.last_name = "Paganini"
44
+ @person.email = "jonatasdp@gmail.com"
45
+ ```
46
+
47
+ You can see all the attributes at [person.rb](/lib/rd/salesforce/person.rb).
48
+
49
+ ### Upload person to salesforce with the client
50
+
51
+ ```ruby
52
+ @person.upload_to_salesforce! @client
53
+ ```
54
+
55
+ ## Setting up a different translation to salesforce fields
56
+
57
+ You can manage/override the fields connection that will be sent to salesforce via managing the translate hash.
58
+
59
+
60
+ ```ruby
61
+ Rd::Salesforce::Person.translate = {
62
+ :first_name => "First Name",
63
+ :last_name => "Last Name",
64
+ :email => "Email",
65
+ :company => "Company",
66
+ :website => "Website",
67
+ :job_title => "Title",
68
+ :phone => "Phone"
69
+ }
70
+ ```
71
+
72
+ Or simple avoid send one attribute.
73
+
74
+ ```ruby
75
+ Rd::Salesforce::Person.translate.delete :job_title
76
+ ```
77
+
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/jonatas/rd-salesforce/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,9 @@
1
+ require 'rd/salesforce/version'
2
+ require 'rd/salesforce/client'
3
+ require 'rd/salesforce/person'
4
+
5
+ module Rd
6
+ module Salesforce
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ require 'restforce'
2
+
3
+ module Rd
4
+ module Salesforce
5
+ class Client
6
+ VALID_PARAMS = %i(oauth_token host instance_url)
7
+ def initialize params
8
+ raise ArgumentError.new("Invalid Params: #{params.inspect} not in #{VALID_PARAMS.inspect}") if not valid_params? params
9
+ @api = Restforce.new(params)
10
+ end
11
+
12
+ def save_lead(person)
13
+ if not person.valid?
14
+ raise ArgumentError.new("can't upload an invalid record to sales force. person is invalid: #{person.inspect}\n #{person.errors.inspect}")
15
+ end
16
+ if person.salesforce_id
17
+ @api.update!("Lead", person.salesforce_id, person.translate_attributes)
18
+ else
19
+ person.salesforce_id = @api.create!("Lead", person.translate_attributes)
20
+ end
21
+ end
22
+
23
+ def valid?
24
+ not @api.nil?
25
+ end
26
+
27
+ private
28
+
29
+ def valid_params? params
30
+ return false if not params or not params.is_a? Hash
31
+ params.each do |key,value|
32
+ return false if not VALID_PARAMS.include?(key)
33
+ end
34
+ true
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,70 @@
1
+ require 'active_model'
2
+ require 'active_support/core_ext'
3
+ require 'validate_url'
4
+
5
+ module Rd
6
+ module Salesforce
7
+
8
+ ##
9
+ # Basic structure to handle a contact.
10
+ # It stores and validates basic person info and +upload_to_salesforce!+
11
+ #
12
+
13
+ class Person
14
+ include ActiveModel::Model
15
+ include ActiveModel::Validations
16
+
17
+
18
+ cattr_accessor :translate
19
+
20
+ self.translate = {
21
+ :first_name => "FirstName",
22
+ :last_name => "LastName",
23
+ :email => "Email",
24
+ :company => "Company",
25
+ :website => "Website",
26
+ :job_title => "Title",
27
+ :phone => "Phone"
28
+ }
29
+
30
+
31
+
32
+ attr_accessor :first_name, :last_name, :email, :company, :job_title, :phone, :website
33
+ attr_accessor :salesforce_id
34
+
35
+
36
+ validates :first_name, :last_name, :email, presence: true
37
+ validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
38
+ validates :first_name, :phone, length: {maximum: 40}
39
+ validates :last_name, :job_title, :email, length: {maximum: 80}
40
+ validates :company, length: {maximum: 50}
41
+ validates :website, url: {allow_nil: true}, length: {maximum: 255}
42
+
43
+ ##
44
+ # Uploads current person to salesforce.
45
+ #
46
+ # Raises ArgumentError if the +client+ is nil or client is invalid
47
+ # Raises StandardError if the current instance is invalid
48
+
49
+ def upload_to_salesforce!(client)
50
+ raise ArgumentError.new("client is nil") if not client
51
+ raise ArgumentError.new("client is invalid: #{client.inspect}") if not client.valid?
52
+ raise ArgumentError.new("client does not respond to :save_lead method. client: #{client.inspect}") if not client.respond_to? :save_lead
53
+
54
+ client.save_lead self
55
+ end
56
+
57
+ ##
58
+ # Translates person fields to salesforce Lead attributes.
59
+ # see more about Lead object at: https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_lead.htm
60
+
61
+ def translate_attributes
62
+ info = {}
63
+ translate.each do |attribute_name, label|
64
+ info[label] = send(attribute_name)
65
+ end
66
+ info
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Rd
2
+ module Salesforce
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rd/salesforce/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rd-salesforce"
8
+ spec.version = Rd::Salesforce::VERSION
9
+ spec.authors = ["Jônatas Paganini"]
10
+ spec.email = ["jonatasdp@gmail.com"]
11
+ spec.summary = %q{Integrates Person with salesforce as a Lead.}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'restforce'
22
+ spec.add_dependency 'activemodel'
23
+ spec.add_dependency 'validate_url'
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,26 @@
1
+ require_relative "./spec_shared_behaviour"
2
+ describe Rd::Salesforce::Client do
3
+
4
+ include_context "shared behaviour"
5
+
6
+ describe "configuration" do
7
+ it "allow multiple accounts" do
8
+ expect(auth_client).to be_a(Rd::Salesforce::Client)
9
+
10
+ second_auth_client = Rd::Salesforce::Client.new with_oauth.merge(host: "serious.host.com")
11
+ expect(second_auth_client).to be_a(Rd::Salesforce::Client)
12
+ end
13
+ it "validates input params" do
14
+ expect(
15
+ lambda {
16
+ invalid_keys = { with: "ERRORS", and: "NON SENSE keys and values" }
17
+ Rd::Salesforce::Client.new invalid_keys
18
+ }
19
+ ).to raise_error(ArgumentError)
20
+ end
21
+ it "can save a lead" do
22
+ expect(auth_client).to be_respond_to :save_lead
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,77 @@
1
+ require_relative "spec_shared_behaviour"
2
+ describe Rd::Salesforce::Person do
3
+
4
+ include_context "shared behaviour"
5
+
6
+ let(:person){ Rd::Salesforce::Person.new valid_person_attributes }
7
+ let(:auth_client) { Rd::Salesforce::Client.new with_oauth }
8
+
9
+ describe "integrates with salesforce" do
10
+ it "new person" do
11
+ expect(person).to be_valid
12
+ end
13
+ it "only valid records" do
14
+ invalid_person = Rd::Salesforce::Person.new {}
15
+ expect(invalid_person).to_not be_valid
16
+ end
17
+ it "uploads returns true if the person is valid" do
18
+ expect(auth_client).to receive(:save_lead).with(person)
19
+ expect(person.upload_to_salesforce! auth_client)
20
+ end
21
+ it "do not uploads an invalid person" do
22
+ expect(
23
+ lambda do
24
+ expect(person).to receive(:valid?).and_return(false)
25
+ person.upload_to_salesforce! auth_client
26
+ end
27
+ ).to raise_error(ArgumentError)
28
+ end
29
+ it "do not uploads with invalid client" do
30
+ expect(
31
+ lambda do
32
+ person.upload_to_salesforce! nil
33
+ end
34
+ ).to raise_error ArgumentError
35
+ end
36
+ end
37
+ it "has basic attributes" do
38
+ valid_person_attributes.each do |attr, expected_value|
39
+ expect(person.send(attr)).to eql(expected_value)
40
+ end
41
+ end
42
+ describe "know translate attributes" do
43
+ let (:translated_attributes) { person.translate_attributes }
44
+ it "converts job_title to Title" do
45
+ expect(translated_attributes).to have_key("Title")
46
+ end
47
+ it "uses camelized keys for all others fields" do
48
+ expected_keys = Rd::Salesforce::Person.translate.values
49
+ expected_keys.each do |expected_key|
50
+ expect(translated_attributes).to have_key expected_key
51
+ end
52
+ end
53
+ end
54
+ describe "validations" do
55
+ it "validate maximum size of each field" do
56
+ invalid_attributes = {}
57
+ valid_person_attributes.each do |name, value|
58
+ invalid_attributes[name] = value * 50 if value
59
+ end
60
+ invalid_person = Rd::Salesforce::Person.new invalid_attributes
61
+ expect(invalid_person).to_not be_valid
62
+ valid_person_attributes.each do |name, value|
63
+ expect(invalid_person.errors).to have_key name if value
64
+ end
65
+ end
66
+ end
67
+ describe "translations" do
68
+ it "can be overrided" do
69
+ Rd::Salesforce::Person.translate = {:email => "FirstName"}
70
+ attributes = person.translate_attributes
71
+ expect(attributes).to eql("FirstName" => "jonatasdp@gmail.com")
72
+ end
73
+ end
74
+ it "uploading the object to " do
75
+ expect(person).to respond_to(:upload_to_salesforce!)
76
+ end
77
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../lib/rd/salesforce'
2
+ require 'rspec/autorun'
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+ config.mock_with :rspec do |mocks|
8
+ mocks.verify_partial_doubles = true
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.shared_context "shared behaviour", :a => :b do
2
+
3
+ let(:valid_person_attributes) do
4
+ { first_name: "Jônatas",
5
+ last_name: "Paganini",
6
+ email: "jonatasdp@gmail.com",
7
+ company: nil,
8
+ job_title: "Developer",
9
+ phone: "+55 4699117879",
10
+ website: "http://ideia.me" }
11
+ end
12
+
13
+ let(:with_oauth) do
14
+ { host: 'test.salesforce.com',
15
+ oauth_token: '123MyAwesomeToken321',
16
+ instance_url: 'http://test.salesforce.com' }
17
+ end
18
+
19
+ let(:auth_client) { Rd::Salesforce::Client.new with_oauth }
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rd-salesforce
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jônatas Paganini
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: restforce
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: validate_url
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - jonatasdp@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/rd/salesforce.rb
98
+ - lib/rd/salesforce/client.rb
99
+ - lib/rd/salesforce/person.rb
100
+ - lib/rd/salesforce/version.rb
101
+ - rd-salesforce.gemspec
102
+ - spec/rd-salesforce_client_spec.rb
103
+ - spec/rd-salesforce_person_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/spec_shared_behaviour.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Integrates Person with salesforce as a Lead.
130
+ test_files:
131
+ - spec/rd-salesforce_client_spec.rb
132
+ - spec/rd-salesforce_person_spec.rb
133
+ - spec/spec_helper.rb
134
+ - spec/spec_shared_behaviour.rb