hubbah 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 +7 -0
- data/.env.example +3 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/hubbah.gemspec +39 -0
- data/lib/hubbah/configuration.rb +9 -0
- data/lib/hubbah/form_submission.rb +37 -0
- data/lib/hubbah/middleware.rb +23 -0
- data/lib/hubbah/payload.rb +41 -0
- data/lib/hubbah/version.rb +3 -0
- data/lib/hubbah.rb +31 -0
- data/spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/does_not_submit_a_form_if_required_data_is_not_supplied.yml +34 -0
- data/spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_404_is_encountered.yml +34 -0
- data/spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_500_is_encountered.yml +34 -0
- data/spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/submits_a_form_with_required_data_successfully.yml +34 -0
- data/spec/fixtures/vcr_cassettes/Hubbah_Payload/submits_successfully_to_hubspot.yml +34 -0
- data/spec/hubbah/configuration_spec.rb +20 -0
- data/spec/hubbah/form_submission_spec.rb +43 -0
- data/spec/hubbah/middleware_spec.rb +17 -0
- data/spec/hubbah/payload_spec.rb +54 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/rack_helper.rb +16 -0
- data/spec/support/vcr.rb +11 -0
- metadata +279 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: da19980856fd999ea53cd68fbff8270b82915865
|
4
|
+
data.tar.gz: 11f94f326343d6ebefddfcd1f29618cac9e60948
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1612acf80e7f46002a254ca6a15b6e746d29587ed8042f616da9f00a526021b7fe041dc9b488878eb8e154160cae7004c3bc0baabcd987fa110b24685a9784b4
|
7
|
+
data.tar.gz: 0af9908dfd0394152655276e58212292bb02271b2af0c70f54e17dda9fb1c5397994e3523495cd670a562532b51ad8eb5efe33f7f7fa064fc1f49eb8d5329c70
|
data/.env.example
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
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
|
23
|
+
.env
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan Pickett
|
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,39 @@
|
|
1
|
+
# Hubbah
|
2
|
+
|
3
|
+
```ruby
|
4
|
+
#in an initializer
|
5
|
+
config.middleware.use Hubba::Middleware do |app|
|
6
|
+
app.hub_id = '312425'
|
7
|
+
end
|
8
|
+
|
9
|
+
#in your controller, when you want to submit the form payload:
|
10
|
+
env['hubbah'].submit(form_guid, params[:subscriber])
|
11
|
+
```
|
12
|
+
|
13
|
+
TODO: Write a gem description
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'hubbah'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install hubbah
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
TODO: Write usage instructions here
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/hubbah/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/hubbah.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hubbah/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hubbah"
|
8
|
+
spec.version = Hubbah::VERSION
|
9
|
+
spec.authors = ["Dan Pickett"]
|
10
|
+
spec.email = ["dan.pickett@launchware.com"]
|
11
|
+
spec.summary = %q{Make hubspot form submissions a snap}
|
12
|
+
spec.description = %q{Provides a web wrapper and rack middleware for hubspot form submissions}
|
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 "faraday"
|
22
|
+
spec.add_dependency "rack"
|
23
|
+
spec.add_dependency "json"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "mocha"
|
29
|
+
spec.add_development_dependency "rack-test"
|
30
|
+
|
31
|
+
spec.add_development_dependency "guard"
|
32
|
+
spec.add_development_dependency "guard-rspec"
|
33
|
+
|
34
|
+
spec.add_development_dependency "dotenv"
|
35
|
+
|
36
|
+
spec.add_development_dependency "webmock"
|
37
|
+
spec.add_development_dependency "vcr"
|
38
|
+
spec.add_development_dependency "pry"
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Hubbah
|
4
|
+
class FormSubmission
|
5
|
+
def initialize(form_guid, attributes = {}, configuration = nil)
|
6
|
+
@form_guid = form_guid
|
7
|
+
@attributes = attributes
|
8
|
+
@configuration = configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def submit
|
12
|
+
resp = client.post("/uploads/form/v2/#{hub_id}/#{@form_guid}", @attributes)
|
13
|
+
if resp.status == 404
|
14
|
+
raise Hubbah::HubIdNotConfigured
|
15
|
+
elsif resp.status == 500
|
16
|
+
raise Hubbah::ServerErrorEncountered
|
17
|
+
else
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def client
|
24
|
+
@client ||= Faraday.new({
|
25
|
+
url: 'https://forms.hubspot.com'
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
def hub_id
|
30
|
+
configuration.hub_id
|
31
|
+
end
|
32
|
+
|
33
|
+
def configuration
|
34
|
+
@configuration || Hubbah.configuration
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
require 'rack'
|
4
|
+
|
5
|
+
module Hubbah
|
6
|
+
class Middleware < Rack::Builder
|
7
|
+
def initialize(app, &block)
|
8
|
+
@app = app
|
9
|
+
@configuration = Hubbah::Configuration.new(&block)
|
10
|
+
super {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
env['hubbah'] = Hubbah::Payload.new(@configuration, env)
|
15
|
+
to_app.call(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def encode(str)
|
20
|
+
URI.encode(str || '')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hubbah
|
2
|
+
class Payload
|
3
|
+
|
4
|
+
def initialize(configuration, env)
|
5
|
+
@configuration = configuration
|
6
|
+
request = Rack::Request.new(env)
|
7
|
+
@hutk = request.cookies['hubspotutk']
|
8
|
+
@ip = request.ip
|
9
|
+
@url = request.url
|
10
|
+
if !request.referer.nil? && request.referer != '/'
|
11
|
+
@url = request.referer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def submit(guid, attributes)
|
16
|
+
decorated_attrs = attributes.dup
|
17
|
+
decorated_attrs['hs_context'] = hs_context.to_json
|
18
|
+
submission = Hubbah::FormSubmission.new(guid, decorated_attrs, @configuration)
|
19
|
+
submission.submit
|
20
|
+
end
|
21
|
+
|
22
|
+
def hs_context
|
23
|
+
context_map.inject({}) do |map, keypair|
|
24
|
+
unless keypair[1].nil?
|
25
|
+
map[keypair[0]] = keypair[1]
|
26
|
+
end
|
27
|
+
map
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def context_map
|
33
|
+
{
|
34
|
+
'hutk' => @hutk,
|
35
|
+
'ipAddress' => @ip,
|
36
|
+
'pageUrl' => @url
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/hubbah.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'hubbah/version'
|
2
|
+
require 'hubbah/configuration'
|
3
|
+
require 'hubbah/form_submission'
|
4
|
+
|
5
|
+
require 'hubbah/middleware'
|
6
|
+
require 'hubbah/payload'
|
7
|
+
|
8
|
+
module Hubbah
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
|
12
|
+
def configure(&block)
|
13
|
+
@configuration = Configuration.new(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def hub_id
|
21
|
+
configuration.nil? ? nil : configuration.hub_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_key
|
25
|
+
configuration.nil? ? nil : configuration.api_key
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class HubIdNotConfigured < Exception; end
|
30
|
+
class ServerErrorEncountered < Exception; end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<HUBBAH_HUB_ID>/<HUBBAH_FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Access-Control-Allow-Credentials:
|
24
|
+
- 'false'
|
25
|
+
Date:
|
26
|
+
- Thu, 29 May 2014 15:59:29 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Thu, 29 May 2014 15:59:29 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<HUBBAH_HUB_ID>/<HUBBAH_FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: Email=user%40example.com
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Access-Control-Allow-Credentials:
|
24
|
+
- 'false'
|
25
|
+
Date:
|
26
|
+
- Thu, 29 May 2014 17:40:55 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Thu, 29 May 2014 17:40:55 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<HUBBAH_HUB_ID>/<HUBBAH_FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: Email=user%40example.com
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Access-Control-Allow-Credentials:
|
24
|
+
- 'false'
|
25
|
+
Date:
|
26
|
+
- Thu, 29 May 2014 17:49:42 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Thu, 29 May 2014 17:49:42 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<HUBBAH_HUB_ID>/<HUBBAH_FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: Email=user%40example.com
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Access-Control-Allow-Credentials:
|
24
|
+
- 'false'
|
25
|
+
Date:
|
26
|
+
- Thu, 29 May 2014 16:00:16 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Thu, 29 May 2014 16:00:16 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<HUBBAH_HUB_ID>/<HUBBAH_FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: Email=user%40example.com&hs_context=%7B%22hutk%22%3A%22r3142423154dfadgfdty%22%2C%22ipAddress%22%3A%22127.0.0.1%22%2C%22pageUrl%22%3A%22http%3A%2F%2Freferrer%2Fme%22%7D
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.0
|
12
|
+
Content-Type:
|
13
|
+
- application/x-www-form-urlencoded
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- '*/*'
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Access-Control-Allow-Credentials:
|
24
|
+
- 'false'
|
25
|
+
Date:
|
26
|
+
- Fri, 30 May 2014 15:45:02 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Fri, 30 May 2014 15:45:02 GMT
|
34
|
+
recorded_with: VCR 2.9.2
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hubbah::Configuration do
|
4
|
+
it 'assigns an api key' do
|
5
|
+
key = 'blah'
|
6
|
+
config = Hubbah::Configuration.new do |c|
|
7
|
+
c.api_key = key
|
8
|
+
end
|
9
|
+
expect(config.api_key).to eq(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'assigns a hub_id' do
|
13
|
+
hub_id = '342'
|
14
|
+
config = Hubbah::Configuration.new do |c|
|
15
|
+
c.hub_id = hub_id
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(config.hub_id).to eq(hub_id)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hubbah::FormSubmission, vcr: true do
|
4
|
+
let(:submission) do
|
5
|
+
Hubbah::FormSubmission.new(form_guid, {
|
6
|
+
'Email' => 'user@example.com'
|
7
|
+
})
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'submits a form with required data successfully' do
|
11
|
+
expect(submission.submit).to be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'raises an exception when a 404 is encountered' do
|
15
|
+
stub_response(submission, [404, {}, nil])
|
16
|
+
|
17
|
+
expect(lambda{ submission.submit }).to raise_error(Hubbah::HubIdNotConfigured)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an exception when a 500 is encountered' do
|
21
|
+
stub_response(submission, [500, {}, nil])
|
22
|
+
|
23
|
+
expect(lambda{ submission.submit }).to raise_error(Hubbah::ServerErrorEncountered)
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
def stub_response(submission, response)
|
28
|
+
mock_client = Faraday.new do |builder|
|
29
|
+
builder.adapter :test do |stubs|
|
30
|
+
stubs.post("/uploads/form/v2/#{hub_id}/#{form_guid}", '' ) { response }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
submission.stubs(:client).returns(mock_client)
|
35
|
+
end
|
36
|
+
def form_guid
|
37
|
+
ENV['HUBBAH_FORM_GUID']
|
38
|
+
end
|
39
|
+
|
40
|
+
def hub_id
|
41
|
+
Hubbah.hub_id
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hubbah::Middleware do
|
4
|
+
include Hubbah::RackHelper
|
5
|
+
|
6
|
+
let :middleware do
|
7
|
+
Hubbah::Middleware.new(app) do |a|
|
8
|
+
a.hub_id = '312425'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'sets the hubbah env variable' do
|
13
|
+
app, env = middleware.call(env_for("http://localhost/"))
|
14
|
+
env['hubbah'].should_not be_nil
|
15
|
+
env['hubbah'].should be_kind_of(Hubbah::Payload)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hubbah::Payload, vcr: true do
|
4
|
+
include Hubbah::RackHelper
|
5
|
+
|
6
|
+
let(:configuration) { Hubbah.configuration }
|
7
|
+
let(:url) { 'http://localhost/' }
|
8
|
+
let(:env) { env_for(url) }
|
9
|
+
let(:payload) { Hubbah::Payload.new(configuration, env) }
|
10
|
+
|
11
|
+
it 'does not include nil values in the context' do
|
12
|
+
expect(payload.hs_context).to_not have_key('hutk')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'includes the ip address when present' do
|
16
|
+
ip = '127.0.0.1'
|
17
|
+
env['REMOTE_ADDR'] = ip
|
18
|
+
expect(payload.hs_context['ipAddress']).to eq(ip)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'includes the request url when present' do
|
22
|
+
expect(payload.hs_context['pageUrl']).to eq(url)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'favors the referrer when present for the pageUrl' do
|
26
|
+
referrer = 'http://referrer/me'
|
27
|
+
env['HTTP_REFERER'] = referrer
|
28
|
+
expect(payload.hs_context['pageUrl']).to eq(referrer)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'includes the hutk cookie when present' do
|
32
|
+
cookie_val = 'r3142423154dfadgfdty'
|
33
|
+
env['HTTP_COOKIE'] = "hubspotutk=#{cookie_val}"
|
34
|
+
expect(payload.hs_context['hutk']).to eq(cookie_val)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'submits successfully to hubspot' do
|
38
|
+
cookie_val = 'r3142423154dfadgfdty'
|
39
|
+
env['HTTP_COOKIE'] = "hubspotutk=#{cookie_val}"
|
40
|
+
|
41
|
+
referrer = 'http://referrer/me'
|
42
|
+
env['HTTP_REFERER'] = referrer
|
43
|
+
|
44
|
+
ip = '127.0.0.1'
|
45
|
+
env['REMOTE_ADDR'] = ip
|
46
|
+
|
47
|
+
expect(payload.submit(form_guid, 'Email' => 'user@example.com')).to be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
def form_guid
|
52
|
+
ENV['HUBBAH_FORM_GUID']
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'mocha/api'
|
3
|
+
require 'hubbah'
|
4
|
+
|
5
|
+
require 'dotenv'
|
6
|
+
require 'pry'
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
Hubbah.configure do |config|
|
10
|
+
config.api_key = ENV['HUBBAH_API_KEY']
|
11
|
+
config.hub_id = ENV['HUBBAH_HUB_ID']
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_framework = 'mocha'
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
module Hubbah
|
4
|
+
module RackHelper
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.let(:app) { ->(env) { [200, env, "app"] } }
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def env_for url, opts={}
|
13
|
+
::Rack::MockRequest.env_for(url, opts)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
VCR.configure do |c|
|
4
|
+
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
5
|
+
c.hook_into :webmock # or :fakeweb
|
6
|
+
c.default_cassette_options = { :record => :new_episodes }
|
7
|
+
c.configure_rspec_metadata!
|
8
|
+
c.filter_sensitive_data('<HUBBAH_API_KEY>') { ENV['HUBBAH_API_KEY'] }
|
9
|
+
c.filter_sensitive_data('<HUBBAH_HUB_ID>') { ENV['HUBBAH_HUB_ID'] }
|
10
|
+
c.filter_sensitive_data('<HUBBAH_FORM_GUID>') { ENV['HUBBAH_FORM_GUID'] }
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubbah
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Pickett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
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: rack
|
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: json
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rack-test
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: guard-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: dotenv
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: vcr
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: pry
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
description: Provides a web wrapper and rack middleware for hubspot form submissions
|
210
|
+
email:
|
211
|
+
- dan.pickett@launchware.com
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- .env.example
|
217
|
+
- .gitignore
|
218
|
+
- .rspec
|
219
|
+
- Gemfile
|
220
|
+
- Guardfile
|
221
|
+
- LICENSE.txt
|
222
|
+
- README.md
|
223
|
+
- Rakefile
|
224
|
+
- hubbah.gemspec
|
225
|
+
- lib/hubbah.rb
|
226
|
+
- lib/hubbah/configuration.rb
|
227
|
+
- lib/hubbah/form_submission.rb
|
228
|
+
- lib/hubbah/middleware.rb
|
229
|
+
- lib/hubbah/payload.rb
|
230
|
+
- lib/hubbah/version.rb
|
231
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/does_not_submit_a_form_if_required_data_is_not_supplied.yml
|
232
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_404_is_encountered.yml
|
233
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_500_is_encountered.yml
|
234
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/submits_a_form_with_required_data_successfully.yml
|
235
|
+
- spec/fixtures/vcr_cassettes/Hubbah_Payload/submits_successfully_to_hubspot.yml
|
236
|
+
- spec/hubbah/configuration_spec.rb
|
237
|
+
- spec/hubbah/form_submission_spec.rb
|
238
|
+
- spec/hubbah/middleware_spec.rb
|
239
|
+
- spec/hubbah/payload_spec.rb
|
240
|
+
- spec/spec_helper.rb
|
241
|
+
- spec/support/rack_helper.rb
|
242
|
+
- spec/support/vcr.rb
|
243
|
+
homepage: ''
|
244
|
+
licenses:
|
245
|
+
- MIT
|
246
|
+
metadata: {}
|
247
|
+
post_install_message:
|
248
|
+
rdoc_options: []
|
249
|
+
require_paths:
|
250
|
+
- lib
|
251
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
252
|
+
requirements:
|
253
|
+
- - '>='
|
254
|
+
- !ruby/object:Gem::Version
|
255
|
+
version: '0'
|
256
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
257
|
+
requirements:
|
258
|
+
- - '>='
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
version: '0'
|
261
|
+
requirements: []
|
262
|
+
rubyforge_project:
|
263
|
+
rubygems_version: 2.0.14
|
264
|
+
signing_key:
|
265
|
+
specification_version: 4
|
266
|
+
summary: Make hubspot form submissions a snap
|
267
|
+
test_files:
|
268
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/does_not_submit_a_form_if_required_data_is_not_supplied.yml
|
269
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_404_is_encountered.yml
|
270
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/raises_an_exception_when_a_500_is_encountered.yml
|
271
|
+
- spec/fixtures/vcr_cassettes/Hubbah_FormSubmission/submits_a_form_with_required_data_successfully.yml
|
272
|
+
- spec/fixtures/vcr_cassettes/Hubbah_Payload/submits_successfully_to_hubspot.yml
|
273
|
+
- spec/hubbah/configuration_spec.rb
|
274
|
+
- spec/hubbah/form_submission_spec.rb
|
275
|
+
- spec/hubbah/middleware_spec.rb
|
276
|
+
- spec/hubbah/payload_spec.rb
|
277
|
+
- spec/spec_helper.rb
|
278
|
+
- spec/support/rack_helper.rb
|
279
|
+
- spec/support/vcr.rb
|