pardot_wrapper 0.1.0
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/.rspec +3 -0
- data/README.md +88 -0
- data/Rakefile +8 -0
- data/lib/pardot/client.rb +86 -0
- data/lib/pardot/version.rb +5 -0
- data/lib/pardot_wrapper.rb +6 -0
- data/pardot_wrapper.gemspec +45 -0
- data/sig/pardot_wrapper.rbs +4 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d87fb77d4119b3f4bf43abc2faeb4b567f01c0afdb380e46a9b154b620290275
|
4
|
+
data.tar.gz: 3254dc23d7820b5d52eede080435a5ed2f7b09f5152506bdec3368bb67fdecde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c75eacea8acf6ac59c014b366664425feb43cfd68db19f0137496c09eb06a79513f3c288a2abbc5da083fe259ad5904f5fbc2bcb8da5dfe89062617b244049b
|
7
|
+
data.tar.gz: 27fc5f383b0dc30127a45b863f115a5c5bfdb06264abf21ab6f2fe17aa0879c6dd1b6969b622073cb866b67e425a863328e2db29336ee13fdbac3b1c00703463
|
data/.rspec
ADDED
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# PardotWrapper Gem
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
`PardotWrapper` is a Ruby gem designed to simplify interactions with the Pardot API version 5. This gem provides a straightforward and efficient way to integrate Pardot's functionalities into Ruby applications, offering basic functionalities such as listing custom fields, viewing account information, creating prospects, and managing list memberships.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'pardot_wrapper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
gem install pardot_wrapper
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To start using PardotWrapper, configure the client with your OAuth credentials:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
client = PardotWrapper.new(access_token, refresh_token, client_id, client_secret)
|
33
|
+
```
|
34
|
+
|
35
|
+
## Available Methods
|
36
|
+
|
37
|
+
- List Custom Fields
|
38
|
+
```ruby
|
39
|
+
client.list_custom_fields
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
- View Account information
|
44
|
+
```ruby
|
45
|
+
client.get_account
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
- Create Prospect
|
50
|
+
```ruby
|
51
|
+
client.create_prospect(email, additional_params)
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
- Create List Membership
|
56
|
+
```ruby
|
57
|
+
client.create_prospect(email, additional_params)
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
## Handling Expired Tokens
|
62
|
+
PardotWrapper handles the renewal of the access token automatically using the provided refresh_token.
|
63
|
+
|
64
|
+
|
65
|
+
## Configuration
|
66
|
+
|
67
|
+
For setting up the gem in a Rails environment, you might consider placing the initialization inside an initializer, such as config/initializers/pardot_wrapper.rb.
|
68
|
+
|
69
|
+
## Tests
|
70
|
+
|
71
|
+
The gem includes a suite of unit tests using RSpec. To run the tests, execute:
|
72
|
+
|
73
|
+
```bash
|
74
|
+
bundle exec rspec
|
75
|
+
```
|
76
|
+
|
77
|
+
## Contributions
|
78
|
+
|
79
|
+
Contributions to PardotWrapper are welcome! To contribute:
|
80
|
+
|
81
|
+
1. Fork the project.
|
82
|
+
2. Create a 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.
|
86
|
+
|
87
|
+
## License
|
88
|
+
This gem is available under the MIT License. See the LICENSE file for more details.
|
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Pardot
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
|
5
|
+
BASE_URIS = {
|
6
|
+
production: 'https://pi.pardot.com/api/v5/objects',
|
7
|
+
demo: 'https://pi.demo.pardot.com/api/v5/objects',
|
8
|
+
login: 'https://login.salesforce.com'
|
9
|
+
}
|
10
|
+
|
11
|
+
def initialize(access_token, refresh_token, client_id, client_secret, pardot_business_unit_id, environment = :production)
|
12
|
+
@access_token = access_token
|
13
|
+
@refresh_token = refresh_token
|
14
|
+
@client_id = client_id
|
15
|
+
@client_secret = client_secret
|
16
|
+
@pardot_business_unit_id = pardot_business_unit_id
|
17
|
+
@token_refreshed = false
|
18
|
+
@environment = environment
|
19
|
+
|
20
|
+
self.class.base_uri BASE_URIS[environment]
|
21
|
+
end
|
22
|
+
|
23
|
+
def list_custom_fields
|
24
|
+
perform_request { self.class.get('/customFields', headers: auth_headers) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_account
|
28
|
+
perform_request { self.class.get('/account?fields=id,company,website', headers: auth_headers) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_prospect(email, params = {})
|
32
|
+
query = params.merge({ email: email })
|
33
|
+
perform_request { self.class.post('/prospects', body: query.to_json, headers: auth_headers) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_list_membership(prospect_id, list_id)
|
37
|
+
query = { prospect_id: prospect_id, list_id: list_id }
|
38
|
+
perform_request { self.class.post('/listMemberships', body: query.to_json, headers: auth_headers) }
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def auth_headers
|
44
|
+
{
|
45
|
+
"Authorization" => "Bearer #{@access_token}",
|
46
|
+
"Pardot-Business-Unit-Id" => @pardot_business_unit_id,
|
47
|
+
"Content-Type" => "application/json"
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def refresh_access_token
|
52
|
+
self.class.base_uri BASE_URIS[:login]
|
53
|
+
|
54
|
+
response = self.class.post('/services/oauth2/token', {
|
55
|
+
body: {
|
56
|
+
grant_type: 'refresh_token',
|
57
|
+
refresh_token: @refresh_token,
|
58
|
+
client_id: @client_id,
|
59
|
+
client_secret: @client_secret
|
60
|
+
}
|
61
|
+
})
|
62
|
+
|
63
|
+
self.class.base_uri BASE_URIS[@environment]
|
64
|
+
|
65
|
+
if response.success?
|
66
|
+
@access_token = response['access_token']
|
67
|
+
@token_refreshed = false
|
68
|
+
else
|
69
|
+
raise "Failed to refresh access token: #{response.body}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def perform_request
|
74
|
+
response = yield
|
75
|
+
|
76
|
+
if response.code == 401
|
77
|
+
refresh_access_token
|
78
|
+
response = yield
|
79
|
+
end
|
80
|
+
|
81
|
+
raise "API request failed: #{response.body}" unless response.success?
|
82
|
+
|
83
|
+
response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/pardot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "pardot_wrapper"
|
7
|
+
spec.version = Pardot::VERSION
|
8
|
+
spec.authors = ["DougPetronilio"]
|
9
|
+
spec.email = ["dougpetronilio@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Pardot Wrapper Api v5"
|
12
|
+
spec.description = "A gem PardotWrapper é uma biblioteca Ruby projetada para simplificar a interação com a API do Pardot, especificamente com a versão 5. Ela oferece uma interface clara e objetiva para realizar operações comuns, como visualizar informações de conta, criar prospects e gerenciar associações de listas. Esta gem abstrai as complexidades das chamadas de API e do tratamento de dados, permitindo que os desenvolvedores se concentrem na lógica de negócios principal de suas aplicações."
|
13
|
+
|
14
|
+
spec.homepage = "https://github.com/dougpetronilio/pardot_wrapper"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/dougpetronilio/pardot_wrapper"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/dougpetronilio/pardot_wrapper"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
# Uncomment to register a new dependency of your gem
|
36
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
37
|
+
|
38
|
+
spec.add_dependency "httparty"
|
39
|
+
|
40
|
+
spec.add_development_dependency 'pry'
|
41
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
42
|
+
|
43
|
+
# For more information and examples about making a new gem, check out our
|
44
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pardot_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DougPetronilio
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
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: pry
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A gem PardotWrapper é uma biblioteca Ruby projetada para simplificar
|
56
|
+
a interação com a API do Pardot, especificamente com a versão 5. Ela oferece uma
|
57
|
+
interface clara e objetiva para realizar operações comuns, como visualizar informações
|
58
|
+
de conta, criar prospects e gerenciar associações de listas. Esta gem abstrai as
|
59
|
+
complexidades das chamadas de API e do tratamento de dados, permitindo que os desenvolvedores
|
60
|
+
se concentrem na lógica de negócios principal de suas aplicações.
|
61
|
+
email:
|
62
|
+
- dougpetronilio@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- ".rspec"
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- lib/pardot/client.rb
|
71
|
+
- lib/pardot/version.rb
|
72
|
+
- lib/pardot_wrapper.rb
|
73
|
+
- pardot_wrapper.gemspec
|
74
|
+
- sig/pardot_wrapper.rbs
|
75
|
+
homepage: https://github.com/dougpetronilio/pardot_wrapper
|
76
|
+
licenses: []
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
homepage_uri: https://github.com/dougpetronilio/pardot_wrapper
|
80
|
+
source_code_uri: https://github.com/dougpetronilio/pardot_wrapper
|
81
|
+
changelog_uri: https://github.com/dougpetronilio/pardot_wrapper
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.6.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.4.10
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Pardot Wrapper Api v5
|
101
|
+
test_files: []
|