rds_pdrive 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1eff7734fcc1309d79b71159fe3f03071eb0b221
4
+ data.tar.gz: 71cfa45014d1d5be6771aea55caa8523fbe1ad36
5
+ SHA512:
6
+ metadata.gz: 95aa1e18882ff78383c2d8cd1c38888bff80700b269c4125637231856bb7c4f5c129f034c9ba7279962f07f45d1e4a27e3fcbe89ea00189869e1bd691b94e858
7
+ data.tar.gz: b0dfd650b2d42fec11abe0e9cf3ae2a419c31a27e83f2b9136c5cf2b594bed0cc3e616324a8b362c166fd06e5bf24d7b9d5842ac9f93b19698ce2156599d6501
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rds_pdrive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Douglas Petronilio
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # RdsPdrive
2
+
3
+ RdsPdrive is a gem for make integration of application RD_station and CRM PipeDrive.
4
+ This gem implemented this functionality:
5
+ Authentication with email and password in pipedrive;
6
+ Add a lead to pipedrive
7
+ List all leads of the authenticated account
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'rds_pdrive'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rds_pdrive
22
+
23
+ ## Usage
24
+
25
+ For Authenticated in account is passed the email and password in the construtor of the class Integrator as in the example:
26
+
27
+ integrator = Integrator('emailteste@gmail.com', 'pass123pass')
28
+
29
+ For list all persons of the authenticated account use the function get_all_leads of the class Integrator as in the example:
30
+
31
+ list_of_my_leads = integrator.get_all_leads
32
+
33
+ For add a lead to authenticated account use the function add_lead of the class Integrator as in the example:
34
+
35
+ lead = Lead.new("name", "last_name", "email", "company", "99229922")
36
+ integrator.add_lead(lead)
37
+
38
+ For find a lead in authenticated account use tha function find_by_name of the class Integrator as in the example:
39
+
40
+ lead = integrator.find_by_name("name")
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "lib"
6
+ t.test_files = Dir["test/**/*_test.rb"]
7
+ end
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module RdsPdrive
6
+ class Integrator
7
+ attr_reader :token, :leads
8
+ def initialize(email, password)
9
+ @email = email
10
+ @password = password
11
+ @url = "https://api.pipedrive.com/v1/"
12
+ authenticate
13
+ @leads = []
14
+ end
15
+
16
+ def get_all_leads
17
+ uri = URI.parse("#{@url}persons?api_token=#{@token}")
18
+ response = Net::HTTP.get(uri)
19
+ objeto_json = JSON.parse(response)
20
+ data = objeto_json['data']
21
+ data.each do |d|
22
+ lead = Lead.new(d['name'], "", d['email'][0]['value'], "", d['phone'][0]['value'])
23
+ @leads << lead
24
+ end
25
+ @leads
26
+ end
27
+
28
+ def add_lead(lead)
29
+ uri = URI.parse("#{@url}persons?api_token=#{@token}")
30
+ response = Net::HTTP.post_form(uri, {"name" => lead.full_name, "email" => lead.email, "phone" => lead.phone, "company_id" => @company_id})
31
+ objeto_json = JSON.parse(response.body)
32
+ end
33
+
34
+ def find_by_name(name)
35
+ get_all_leads
36
+ @leads.select { |l| l.name == name}
37
+ end
38
+
39
+ private
40
+ def authenticate
41
+ uri = URI.parse(@url+"authorizations")
42
+ response = Net::HTTP.post_form(uri, {"email" => @email, "password" => @password})
43
+ objeto_json = JSON.parse(response.body)
44
+ @token = objeto_json['data'][0]['api_token']
45
+ @user_id = objeto_json['data'][0]['user_id']
46
+ @company_id = objeto_json['data'][0]['company_id']
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ module RdsPdrive
2
+ class Lead
3
+ attr_reader :name, :last_name, :email, :company, :phone
4
+ def initialize(name, last_name, email, company, phone)
5
+ @name = name
6
+ @last_name = last_name
7
+ @email = email
8
+ @company = company
9
+ @phone = phone
10
+ end
11
+
12
+ def full_name
13
+ "#{@name} #{@last_name}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module RdsPdrive
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rds_pdrive.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ require "rds_pdrive/version"
3
+ require "rds_pdrive/lead"
4
+ require "rds_pdrive/integrator"
5
+
6
+ module RdsPdrive
7
+
8
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rds_pdrive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rds_pdrive"
8
+ spec.version = RdsPdrive::VERSION
9
+ spec.authors = ["Douglas Petronilio de Oliveira"]
10
+ spec.email = ["dougpetronilio@gmail.com"]
11
+ spec.description = %q{A gem to integration RD_Station with Pipedrive}
12
+ spec.summary = %q{Export a lead from RD_Station to Pipedrive}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'test/unit'
2
+ require 'rds_pdrive'
3
+
4
+ module RdsPdrive
5
+ class IntegratorTest < Test::Unit::TestCase
6
+ def setup
7
+ @integrator = Integrator.new("dougpetronilio@gmail.com", "testeapirdspipedrive")
8
+ end
9
+
10
+ def test_authorization
11
+ assert_equal "264af15c36a2bfa50ceb21ae1734e6f0f3527788", @integrator.token
12
+ end
13
+
14
+ def test_get_all_leads
15
+
16
+ assert_equal "Teste1", @integrator.get_all_leads[0].name
17
+ end
18
+
19
+ def test_add_new_lead
20
+ lead = Lead.new("Teste", "", "teste@teste.com.br", "Res", "99234512")
21
+ @integrator.add_lead(lead)
22
+ assert_not_nil @integrator.find_by_name(lead.name)
23
+ end
24
+ end
25
+ end
data/test/lead_test.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require 'rds_pdrive'
3
+
4
+ module RdsPdrive
5
+ class LeadTest < Test::Unit::TestCase
6
+ def test_add_new_lead
7
+ lead = Lead.new("Douglas", "Petronilio", "dougpetronilio@gmail.com", "Resultados Digitais", "4899469912")
8
+ assert_equal("Douglas", lead.name)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require 'rds_pdrive'
3
+
4
+ module RdsPdrive
5
+ class RdsPdriveTest < Test::Unit::TestCase
6
+ def test_module
7
+ assert_not_nil RdsPdrive::VERSION
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rds_pdrive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Douglas Petronilio de Oliveira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A gem to integration RD_Station with Pipedrive
42
+ email:
43
+ - dougpetronilio@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rds_pdrive.rb
54
+ - lib/rds_pdrive/integrator.rb
55
+ - lib/rds_pdrive/lead.rb
56
+ - lib/rds_pdrive/version.rb
57
+ - rds_pdrive.gemspec
58
+ - test/integrator_test.rb
59
+ - test/lead_test.rb
60
+ - test/rds_pdrive_test.rb
61
+ homepage:
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Export a lead from RD_Station to Pipedrive
85
+ test_files:
86
+ - test/integrator_test.rb
87
+ - test/lead_test.rb
88
+ - test/rds_pdrive_test.rb