lead_router 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17a035f4674e6553d64cb935952c7bf8753d3c235b1496438a8571a5be81abd9
4
+ data.tar.gz: b18e92f4decbd6423b1c121723ab2e628224cb4dfad1c759983cb50055300fbf
5
+ SHA512:
6
+ metadata.gz: 75f5b8658161fc9980964e5816ab6f0d54345b7f1224fb48cdaf9c0ae1b88a28749098cba2ae6096dc57f919a58276d0345ed0e2a6088a075bfcf5c795ed1be2
7
+ data.tar.gz: 7b939161205bb713b52ec4610aca01c5f11a3fe44136edf59030cf47de7aee8a357251b64eecd608a317c2209ee53f28a918a319b22763f31699871a32133eb9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lead_router.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) Real Geeks LLC
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Ruby client to Real Geeks Leads API
2
+
3
+ Send leads and activities to Lead Router, the Real Geeks Leads API.
4
+
5
+ For more details see [our documentation](http://docs.realgeeks.com/outgoing_leads_api_developers).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lead_router'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install lead_router
22
+
23
+ ## Usage
24
+
25
+ First get a user and token from the `lead_router` project, it will identify your project and which permissions you have.
26
+
27
+ If you're a Real Geeks client send a message to [support](https://www.realgeeks.com/support/) and we'll give you credentials.
28
+
29
+ ```ruby
30
+ require 'lead_router'
31
+
32
+ lr = LeadRouter.new("receivers.leadrouter.realgeeks.com", "user", "token")
33
+ ```
34
+
35
+ with a client created use one the methods below. For details on which fields
36
+ you can send for a `lead` or an `activity`, see our [API docs](http://docs.realgeeks.com/incoming_leads_api)
37
+
38
+ #### `create_lead(site_uuid, lead)`
39
+
40
+ Send a new lead.
41
+
42
+ - `site_uuid` is a string with the RG2 Site UUID
43
+ - `lead` id a dictionary with lead fields
44
+
45
+ #### `update_lead(site_uuid, lead_uuid, lead)`
46
+
47
+ Update an existing lead.
48
+
49
+ - `site_uuid` is a string with the RG2 Site UUID
50
+ - `lead_uuid` is a string with the Lead Manager Lead UUID
51
+ - `lead` id a dictionary with lead fields to be overriden
52
+
53
+ #### `add_activities(site_uuid, lead_uuid, activities)`
54
+
55
+ Add activities to an existing lead.
56
+
57
+ - `site_uuid` is a string with the RG2 Site UUID
58
+ - `lead_uuid` is a string with the Lead Manager Lead UUID
59
+ - `activities` is a list of dictionaries, each dictionary is an activitity
60
+
61
+ #### `create_potential_seller_lead(site_uuid, lead)`
62
+
63
+ Send a new potential seller lead. Somebody who attempted to view a property valuation but didn't sign-up to give contact details. So all we have is the property they looked at.
64
+
65
+ - `site_uuid` is a string with the RG2 Site UUID
66
+ - `lead` id a dictionary with lead fields
67
+
68
+ ## Development
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
71
+
72
+ To run tests:
73
+
74
+ $ rake
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lead_router"
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
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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lead_router/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lead_router"
8
+ spec.version = LeadRouter::VERSION
9
+ spec.authors = ["Igor Sobreira"]
10
+ spec.email = ["igor@realgeeks.com"]
11
+
12
+ spec.summary = "Client to Real Geeks Leads API"
13
+ spec.description = "Send Leads and Activities to Real Geeks"
14
+ spec.homepage = "https://github.com/realgeeks/lead_router.rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "rest-client", "~> 2.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.8"
27
+ spec.add_development_dependency "mocha", "~> 1.1"
28
+ spec.add_development_dependency "webmock", "~> 2.3.2"
29
+ end
@@ -0,0 +1,9 @@
1
+ require "lead_router/version"
2
+ require "lead_router/client"
3
+ require "lead_router/exceptions"
4
+
5
+ module LeadRouter
6
+ def self.new(host, user, token)
7
+ LeadRouter::Client.new(host, user, token)
8
+ end
9
+ end
@@ -0,0 +1,91 @@
1
+ require "rest-client"
2
+
3
+ module LeadRouter
4
+
5
+ class Client
6
+ def initialize(host, user, token)
7
+ @host = host
8
+ @user = user
9
+ @token = token
10
+ end
11
+
12
+ def create_lead(site_uuid, lead, destinations=[])
13
+ destinations ||= []
14
+ require_arg "site_uuid", site_uuid
15
+ dest_headers = destinations.empty? ? nil : { "X-ROUTER-DESTINATIONS" => destinations.join(",") }
16
+ request :post, "https://#{@host}/rest/sites/#{site_uuid}/leads", lead.to_json, dest_headers
17
+ end
18
+
19
+ def update_lead(site_uuid, lead_uuid, lead)
20
+ require_arg "site_uuid", site_uuid
21
+ require_arg "lead_uuid", lead_uuid
22
+ request :patch, "https://#{@host}/rest/sites/#{site_uuid}/leads/#{lead_uuid}", lead.to_json
23
+ end
24
+
25
+ def add_activities(site_uuid, lead_uuid, activities)
26
+ require_arg "site_uuid", site_uuid
27
+ require_arg "lead_uuid", lead_uuid
28
+ request :post, "https://#{@host}/rest/sites/#{site_uuid}/leads/#{lead_uuid}/activities", activities.to_json
29
+ end
30
+
31
+ def create_potential_seller_lead(site_uuid, lead)
32
+ require_arg "site_uuid", site_uuid
33
+ request :post, "https://#{@host}/rest/sites/#{site_uuid}/potential-seller-leads", lead.to_json
34
+ end
35
+
36
+ # Send a request to notify a user was updated in the Lead Manager
37
+ #
38
+ # Only the lead manager is allowed to send this request, every other
39
+ # client will get 403
40
+ #
41
+ # Must be called with the full user object, all fields. See all fields
42
+ # in: https://developers.realgeeks.com/users/
43
+ #
44
+ # 'name' could be provided as 'first_name' and 'last_name', they will be
45
+ # combined as 'name'
46
+ def update_user(site_uuid, user_id, user)
47
+ require_arg "site_uuid", site_uuid
48
+ require_arg "user_id", user_id
49
+
50
+ # if name not set try to use first_name and last_name
51
+ user = user.clone
52
+ first = user.delete(:first_name)
53
+ last = user.delete(:last_name)
54
+ user['name'] ||= first unless first.nil?
55
+ user['name'] += " #{last}" unless last.nil?
56
+
57
+ request :put, "https://#{@host}/rest/sites/#{site_uuid}/users/#{user_id}", user.to_json
58
+ end
59
+
60
+ # Send a request to notify a user was deleted in the Lead Manager
61
+ #
62
+ # Only the lead manager is allowed to send this request, every other
63
+ # client will get 403
64
+ def delete_user(site_uuid, user_id)
65
+ request :delete, "http://#{@host}/rest/sites/#{site_uuid}/users/#{user_id}"
66
+ end
67
+
68
+ private
69
+
70
+ def request(method, url, body='', headers={})
71
+ headers ||= {}
72
+ headers.merge!({content_type: 'application/json', user_agent: "LeadRouterRuby/#{VERSION}"})
73
+
74
+ RestClient::Request.execute(
75
+ :method => method,
76
+ :url => url,
77
+ :payload => body,
78
+ :headers => headers,
79
+ :user => @user,
80
+ :password => @token
81
+ )
82
+ rescue ::Exception => ex
83
+ raise LeadRouter::Exception, ex
84
+ end
85
+
86
+ def require_arg(name, value)
87
+ raise LeadRouter::Exception, ArgumentError.new("#{name} cannot be nil") if value.nil?
88
+ end
89
+
90
+ end
91
+ end
@@ -0,0 +1,34 @@
1
+ module LeadRouter
2
+
3
+ # All possible exceptions raised by the LeadRouter::Client will be an instance
4
+ # of this class
5
+ #
6
+ # Use 'original_exception' method to access the original exception object , or
7
+ # just 'to_s' to display a nice error message
8
+ #
9
+ # If the error was an invalid HTTP status code, 'http_code' and 'http_body' methods
10
+ # will be available (they return 0 and "" otherwise)
11
+ class Exception < RuntimeError
12
+
13
+ attr_accessor :original_exception
14
+
15
+ def initialize(exception)
16
+ @original_exception = exception
17
+ end
18
+
19
+ def to_s
20
+ return "#{original_exception.to_s}: HTTP status #{http_code} with body #{http_body}" unless http_code == 0
21
+ original_exception.to_s
22
+ end
23
+
24
+ def http_code
25
+ original_exception.respond_to?(:http_code) ? original_exception.http_code : 0
26
+ end
27
+
28
+ def http_body
29
+ original_exception.respond_to?(:http_body) ? original_exception.http_body : ""
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module LeadRouter
2
+ VERSION = "1.4.0"
3
+ end
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lead_router
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Sobreira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.3.2
97
+ description: Send Leads and Activities to Real Geeks
98
+ email:
99
+ - igor@realgeeks.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - lead_router.gemspec
112
+ - lib/lead_router.rb
113
+ - lib/lead_router/client.rb
114
+ - lib/lead_router/exceptions.rb
115
+ - lib/lead_router/version.rb
116
+ - pkg/lead_router-1.1.1.gem
117
+ - pkg/lead_router-1.3.1.gem
118
+ homepage: https://github.com/realgeeks/lead_router.rb
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Client to Real Geeks Leads API
142
+ test_files: []