sf_integrator 0.0.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 098462d10d0ed108233318ffbae543a560d0f5dd
4
- data.tar.gz: f4a93f4091750d46949f1153efbe3b95096f0240
3
+ metadata.gz: bffccaca92dbd74e24436fe478ecd36a2e4fcc7d
4
+ data.tar.gz: a55fb45ea02b2f25cf709f3e4311723fb43aa964
5
5
  SHA512:
6
- metadata.gz: 1b5ac75954787d51e035683ea6c2a7919aea9cb946b6e2629b738bfc19d85d689214ba0e3b9af8407348b7824147a473ac73068e2568c4412814cc4ab4db7c37
7
- data.tar.gz: cecf0cae644586d15efc66e240936c16b978df5d6dd032b30286fdf5531454c8933333079128acd87d60ba9e893ad174faf655d5bc8e38fa25ff981c59d4f7f0
6
+ metadata.gz: 693aff9780a97e9d454a6a615d37e940528522979f7367663f6384ce5e4b2715e423c334179034e1a383a6a9e36608a901d45dbcc835e2d8b383d9ccc51e7743
7
+ data.tar.gz: ae3055a74642e8658c13691b3ac6d2cf41a247bd1a544549ae083f970d0ded5d0e01c2ad3db060afe350131cbbe170a9c688a0ee4ac73b37be04c58c2384ae2c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SfIntegrator
2
2
 
3
- Simple gem to integration with SalesForce Leads.
3
+ TODO: Write a gem description
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,23 +16,50 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install sf_integrator
18
18
 
19
- ## Usage
19
+ ## Configuration
20
20
 
21
- Run the generator:
21
+ First, create a new file in called `sf_integrator.rb` in `config/initializers` path.
22
22
 
23
- `rails g sf_integrator:install`
23
+ In this file, you put this configs:
24
24
 
25
- This command will copy a template file to `app/config/initializers/sf_integrator.rb`, in this file you need to write your credentials from salesforce
25
+ ```ruby
26
+ SfIntegrator::Integrator.configure do |config|
27
+ config.username = 'YOUR_SALESFORCE_EMAIL'
28
+ config.password = 'YOUR_SALESFORCE_PASSWORD + YOUR_SALESFORCE_SECURITY_TOKEN'
29
+ config.client_id = 'YOUR_CUSTOMER_KEY'
30
+ config.client_secret = 'YOUR_CLIENT_SECRET'
31
+ end
32
+ ```
26
33
 
27
- After that you create a simples ruby class that inherits from `SfIntegrator::Lead`:
34
+ ## Usage
35
+
36
+ After that you create a simple ruby class in `models` directory that inherits from `SfIntegrator::Lead`
28
37
 
29
38
  ```ruby
30
39
  class Lead < SfIntegrator::Lead
31
40
  end
32
41
  ```
33
42
 
34
- Now in your controller you can use like a `ActiveRecord` model, the `SfIntegrator::Lead` include `ActiveModel::Validations`.
43
+ In you controller you can use like a `ActiveRecord` model
44
+
45
+ ```ruby
46
+ # app/controllers/leads_controller.rb
47
+
48
+ def index
49
+ @leads = Lead.all
50
+ end
51
+ def new
52
+ @lead = Lead.new
53
+ end
54
+
55
+ def create
56
+ params = { first_name: 'Cezer', last_name: 'Filho', email: 'luiz.cezer@yahoo.com.br', company: 'Google', job_title: 'Developer', phone: '5555555', website: 'http://github.com/lccezinha' }
57
+ @lead = Lead.new(params)
58
+ @lead.create
59
+ end
60
+ ```
35
61
 
62
+ The fields `first_name, last_name, email, company, job_title, phone, website` are all required.
36
63
 
37
64
  ## Contributing
38
65
 
@@ -6,21 +6,41 @@ module SfIntegrator
6
6
 
7
7
  validates :first_name, :last_name, :email, :company, :job_title, :phone, :website, presence: true
8
8
 
9
- attr_accessor :client, :first_name, :last_name, :email, :company, :job_title, :phone, :website
10
-
11
- def initialize
12
- @client = Restforce.new(SfIntegrator::Integrator.configs.to_hash)
9
+ attr_accessor :first_name, :last_name, :email, :company, :job_title, :phone, :website
10
+
11
+ def initialize(args)
12
+ @first_name = args[:first_name]
13
+ @last_name = args[:last_name]
14
+ @email = args[:email]
15
+ @company = args[:company]
16
+ @job_title = args[:job_title]
17
+ @phone = args[:phone]
18
+ @website = args[:website]
13
19
  end
14
20
 
15
21
  def create
16
- params = build_params
17
- client.create('Lead', params)
22
+ params = {
23
+ FirstName: first_name, LastName: last_name, Email: email,
24
+ Company: company, Title: job_title, Phone: phone, Website: website
25
+ }
26
+ self.class.client.create('Lead', params)
27
+ end
28
+
29
+ def self.all
30
+ records = client.query('select FirstName, LastName, Email, Company, Title, Phone, Website from Lead')
31
+ records.map do |record|
32
+ attributes = {
33
+ first_name: record.FirstName, last_name: record.LastName, email: record.Email,
34
+ company: record.Company, job_title: record.Title, phone: record.Phone, website: record.Website
35
+ }
36
+ Lead.new(attributes)
37
+ end
18
38
  end
19
39
 
20
40
  private
21
41
 
22
- def build_params
23
- { FirstName: first_name, LastName: last_name, Email: email, Company: company, Title: job_title, Phone: phone, Website: website }
42
+ def self.client
43
+ @client ||= Restforce.new(SfIntegrator::Integrator.configs.to_hash)
24
44
  end
25
45
 
26
46
  end
@@ -1,3 +1,3 @@
1
1
  module SfIntegrator
2
- VERSION = "0.0.9"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/sf_integrator.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "sf_integrator/engine"
2
1
  require "sf_integrator/version"
3
2
  require "sf_integrator/configuration"
4
3
  require "sf_integrator/integrator"
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'restforce', '1.4.3'
22
- spec.add_runtime_dependency "activemodel"
22
+ spec.add_runtime_dependency "activemodel", '~> 0'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rake", '~> 0'
26
+ spec.add_development_dependency "rspec", '~> 0'
27
27
  end
@@ -14,9 +14,9 @@ describe SfIntegrator::Integrator do
14
14
  end
15
15
  end
16
16
 
17
- it { expect(subject.instance.configs.username).to eql('lccezinha@gmail.com') }
18
- it { expect(subject.instance.configs.password).to eql('batata880AvOSHd43zql8ZIMJ1emQNjkt') }
19
- it { expect(subject.instance.configs.client_id).to eql('3MVG9xOCXq4ID1uFbfzoMHMM0bGJfUgjThmhEmajKOh75cvDlJn.E3g5FYx2R45vTpFRJfiPDfda5o.td8HQ2') }
20
- it { expect(subject.instance.configs.client_secret).to eql('3340784302062558262') }
17
+ it { expect(subject.configs.username).to eql('lccezinha@gmail.com') }
18
+ it { expect(subject.configs.password).to eql('batata880AvOSHd43zql8ZIMJ1emQNjkt') }
19
+ it { expect(subject.configs.client_id).to eql('3MVG9xOCXq4ID1uFbfzoMHMM0bGJfUgjThmhEmajKOh75cvDlJn.E3g5FYx2R45vTpFRJfiPDfda5o.td8HQ2') }
20
+ it { expect(subject.configs.client_secret).to eql('3340784302062558262') }
21
21
  end
22
22
  end
data/spec/lead_spec.rb CHANGED
@@ -2,7 +2,10 @@ require 'spec_helper'
2
2
  require_relative '../lib/sf_integrator/lead.rb'
3
3
 
4
4
  describe SfIntegrator::Lead do
5
- subject(:lead) { described_class.new }
5
+ let(:attributes) {
6
+ { first_name: 'Cezer', last_name: 'Filho', email: 'luiz.cezer@yahoo.com.br', company: 'Google', job_title: 'Developer', phone: '5555555', website: 'http://github.com/lccezinha' }
7
+ }
8
+ subject(:lead) { described_class.new(attributes) }
6
9
 
7
10
  context 'be instance of SfIntegrator::Lead' do
8
11
  it { expect(lead).to be_an_instance_of(SfIntegrator::Lead) }
@@ -11,7 +14,7 @@ describe SfIntegrator::Lead do
11
14
  it { expect(described_class.ancestors).to include(ActiveModel::Validations) }
12
15
 
13
16
  context 'accessors' do
14
- [:client, :first_name, :last_name, :email, :company, :job_title, :phone, :website].each do |attribute|
17
+ [:first_name, :last_name, :email, :company, :job_title, :phone, :website].each do |attribute|
15
18
  context attribute.to_s do
16
19
  it { expect(lead).to respond_to attribute }
17
20
  it { expect(lead).to respond_to "#{attribute}=" }
@@ -19,6 +22,16 @@ describe SfIntegrator::Lead do
19
22
  end
20
23
  end
21
24
 
25
+ it 'match values' do
26
+ expect(lead.first_name).to eql('Cezer')
27
+ expect(lead.last_name).to eql('Filho')
28
+ expect(lead.email).to eql('luiz.cezer@yahoo.com.br')
29
+ expect(lead.company).to eql('Google')
30
+ expect(lead.job_title).to eql('Developer')
31
+ expect(lead.phone).to eql('5555555')
32
+ expect(lead.website).to eql('http://github.com/lccezinha')
33
+ end
34
+
22
35
  context 'validations' do
23
36
  context 'presence_of' do
24
37
  [:first_name, :last_name, :email, :company, :job_title, :phone, :website].each do |attribute|
@@ -31,36 +44,17 @@ describe SfIntegrator::Lead do
31
44
  end
32
45
 
33
46
  it { expect(lead).to respond_to(:create) }
47
+ it { expect(described_class).to respond_to(:all) }
34
48
 
35
- it 'match values' do
36
- lead.first_name = 'Luiz'
37
- lead.last_name = 'Cezer'
38
- lead.email = 'lccezinha@gmail.com'
39
- lead.company = 'Google'
40
- lead.job_title = 'Rails Dev'
41
- lead.phone = '5555555'
42
- lead.website = 'github.com/lccezinha'
43
-
44
- expect(lead.first_name).to eql('Luiz')
45
- expect(lead.last_name).to eql('Cezer')
46
- expect(lead.email).to eql('lccezinha@gmail.com')
47
- expect(lead.company).to eql('Google')
48
- expect(lead.job_title).to eql('Rails Dev')
49
- expect(lead.phone).to eql('5555555')
50
- expect(lead.website).to eql('github.com/lccezinha')
49
+ context '#all' do
50
+ it 'return an array' do
51
+ expect(SfIntegrator::Lead.all).to be_an_instance_of(Array)
52
+ end
51
53
  end
52
54
 
53
55
  context 'create new lead' do
54
56
  context 'when success' do
55
57
  it do
56
- lead.first_name = 'Cezer'
57
- lead.last_name = 'Filho'
58
- lead.email = 'luiz.cezer@gmail.com'
59
- lead.company = 'Google'
60
- lead.job_title = 'Rails Dev'
61
- lead.phone = '5555555'
62
- lead.website = 'http://github.com/lccezinha'
63
-
64
58
  result = lead.create
65
59
 
66
60
  expect(result).to match(/[a-z]|[A-Z]|[0-9]/)
@@ -68,10 +62,10 @@ describe SfIntegrator::Lead do
68
62
  end
69
63
 
70
64
  context 'when fail' do
65
+ let(:attributes) { { first_name: 'Cezer' } }
66
+ subject(:fail_lead) { described_class.new(attributes) }
71
67
  it do
72
- lead.first_name = 'Luiz'
73
-
74
- result = lead.create
68
+ result = fail_lead.create
75
69
 
76
70
  expect(result).to eq(false)
77
71
  end
data/spec/version_spec.rb CHANGED
@@ -2,5 +2,5 @@ require 'spec_helper'
2
2
 
3
3
  # just testing if rspec is ok
4
4
  describe SfIntegrator::VERSION do
5
- it { expect(SfIntegrator::VERSION).to eq('0.0.1') }
5
+ it { expect(SfIntegrator::VERSION).to eq('1.0.0') }
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sf_integrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Cezer
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -56,28 +56,28 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: ' Integration with Sales Force leads. '
@@ -93,11 +93,8 @@ files:
93
93
  - LICENSE.txt
94
94
  - README.md
95
95
  - Rakefile
96
- - lib/generators/sf_integrator/install_generator.rb
97
- - lib/generators/sf_integrator/templates/sf_integrator.rb
98
96
  - lib/sf_integrator.rb
99
97
  - lib/sf_integrator/configuration.rb
100
- - lib/sf_integrator/engine.rb
101
98
  - lib/sf_integrator/integrator.rb
102
99
  - lib/sf_integrator/lead.rb
103
100
  - lib/sf_integrator/version.rb
@@ -127,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
124
  version: '0'
128
125
  requirements: []
129
126
  rubyforge_project:
130
- rubygems_version: 2.0.2
127
+ rubygems_version: 2.4.5
131
128
  signing_key:
132
129
  specification_version: 4
133
130
  summary: Integration with Sales Force leads.
@@ -1,9 +0,0 @@
1
- module SfIntegrator
2
- class InstallGenerator < Rails::Generators::Base
3
- source_root File.expand_path("../templates", __FILE__)
4
-
5
- def copy_initializer
6
- template 'sf_integrator.rb', 'config/initializers/sf_integrator.rb'
7
- end
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- SfIntegrator::Integrator.configure do |config|
2
- config.username = 'YOUR_EMAIL_FROM_SALESFORCE_ACCOUNT'
3
- config.password = 'YOUR_PASSWORD_FROM_SALESFORCE+YOUR_SECURITY_TOKEN'
4
- config.client_id = 'YOUR_APP_CUSTOMER_KEY'
5
- config.client_secret = 'YOUR_APP_CUSTOMER_SECRET'
6
- end
@@ -1,4 +0,0 @@
1
- module SfIntegrator
2
- class Engine < ::Rails::Engine
3
- end
4
- end