convertkit-ruby 0.0.5
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/.github/workflows/ruby.yml +20 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +112 -0
- data/Rakefile +6 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/convertkit-ruby.gemspec +39 -0
- data/fixtures/vcr_cassettes/account.yml +65 -0
- data/fixtures/vcr_cassettes/add_subscriber_to_form.yml +63 -0
- data/fixtures/vcr_cassettes/delete_custom_field.yml +57 -0
- data/fixtures/vcr_cassettes/forms.yml +64 -0
- data/fixtures/vcr_cassettes/get_custom_fields.yml +62 -0
- data/fixtures/vcr_cassettes/new_custom_field.yml +65 -0
- data/fixtures/vcr_cassettes/update_custom_field.yml +59 -0
- data/lib/convertkit.rb +17 -0
- data/lib/convertkit/client.rb +31 -0
- data/lib/convertkit/client/account.rb +9 -0
- data/lib/convertkit/client/custom_fields.rb +27 -0
- data/lib/convertkit/client/forms.rb +18 -0
- data/lib/convertkit/client/sequences.rb +18 -0
- data/lib/convertkit/client/subscribers.rb +36 -0
- data/lib/convertkit/client/tags.rb +49 -0
- data/lib/convertkit/client/webhooks.rb +17 -0
- data/lib/convertkit/configuration.rb +11 -0
- data/lib/convertkit/connection.rb +86 -0
- data/lib/convertkit/errors.rb +11 -0
- data/lib/convertkit/version.rb +3 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ffa2c590c805d4b469e21a2317d06fe9f7cda67ecdaf012ab8c56a35d78aa7e3
|
4
|
+
data.tar.gz: 556327cb6b3f4b869051fd5fa44711edd1798bc7a5f64a5056b805e30a8be742
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e2e3d45951fe679c11106820919a91226d7804ddf7b6a7389d1cfb7cb464093e0334b7e86af536a065dedc59ae9bdf677f9a1c3f398d79868f6f0643161702b
|
7
|
+
data.tar.gz: bb71306553a06a4a6bd5fb6c6c7ce137eb596250db5deff1d391da19fb6ab91ec6a4a51a8d915308ffe44675fe3afb799789a6e3d618ac7156d9cc0a0963297a
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v1
|
12
|
+
- name: Set up Ruby 2.6
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at rkcudjoe@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hook Engine
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Convertkit Ruby Client
|
2
|
+
|
3
|
+
A Ruby toolkit for [Convertkit](https://convertkit.com/) API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'convertkit-ruby', require: 'convertkit'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install convertkit-ruby
|
20
|
+
|
21
|
+
## Authentication
|
22
|
+
|
23
|
+
For private integrations, use your personal ``API_KEY`` and ``API_SECRET`` found in [your account settings.](https://app.convertkit.com/account/edit)
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "dotenv"
|
27
|
+
Dotenv.load(".env.local")
|
28
|
+
|
29
|
+
Convertkit.configure do |config|
|
30
|
+
config.api_secret = ENV["API_SECRET"]
|
31
|
+
config.api_key = ENV["API_KEY"]
|
32
|
+
end
|
33
|
+
|
34
|
+
client = Convertkit::Client.new
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Calls for Convertkit API v3 are relative to the url [http://api.convertkit.com/v3](http://api.convertkit.com/v3).
|
40
|
+
|
41
|
+
API actions are available as methods on the client object. Currently, the Convertkit client has the following methods:
|
42
|
+
|
43
|
+
|
44
|
+
| Action | Method |
|
45
|
+
|:-----------------------------|:----------------------------------------------------------------|
|
46
|
+
| Get account information | `#account` |
|
47
|
+
| List subscribers | `#subscribers(options = {})` |
|
48
|
+
| Fetch a subscriber | `#subscriber(subscriber_id)` |
|
49
|
+
| List sequences/courses | `#sequences` |
|
50
|
+
| Add subscriber to sequence | `#add_subscriber_to_sequence(sequence_id, email, options = {})` |
|
51
|
+
| List tags | `#tags` |
|
52
|
+
| Add subscriber to tag | `#add_subscriber_to_tag(tag_id, email, options = {})` |
|
53
|
+
| Remove tag from a subscriber | `#remove_tag_from_subscriber(subscriber_id, tag_id)` |
|
54
|
+
| List forms | `#forms` |
|
55
|
+
| Add subscriber to form | `#add_subscriber_to_form(form_id, email, options = {})` |
|
56
|
+
| Unsubscribe | `#unsubscribe(email)` |
|
57
|
+
|
58
|
+
**Note:** We do not have complete API coverage yet. If we are missing an API method that you need to use in your application, please file an issue and/or open a pull request.
|
59
|
+
|
60
|
+
[See the official API documentation](http://kb.convertkit.com/article/api-documentation-v3/) for a complete API reference.
|
61
|
+
|
62
|
+
## Use Cases
|
63
|
+
|
64
|
+
Here are some common use cases for the Convertkit v3 API client.
|
65
|
+
|
66
|
+
First configure the ``convertkit-ruby`` gem with your ``API_KEY`` and ``API_SECRET``, and initialize a new client. After that, you can fetch data from your account.
|
67
|
+
|
68
|
+
### List subscribers
|
69
|
+
|
70
|
+
List all subscribers added to your account on or after a specific date.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
response = client.subscribers(from: "2016-03-01")
|
74
|
+
# => <Faraday::Response ...>
|
75
|
+
|
76
|
+
response.status
|
77
|
+
# => 200
|
78
|
+
```
|
79
|
+
|
80
|
+
### Fetching subscriber data
|
81
|
+
|
82
|
+
Subscribers can be looked up by their ``subscriber_id``.
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
response = client.subscriber("17682009")
|
86
|
+
# => <Faraday::Response ...>
|
87
|
+
|
88
|
+
response.status
|
89
|
+
# => 200
|
90
|
+
```
|
91
|
+
|
92
|
+
## Development
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, copy `.env.local.sample` to `.env.local` and substitute your own real values from your account. Finally, run `rake spec` to run the tests.
|
95
|
+
|
96
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
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).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Atomoworks/convertkit-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
103
|
+
|
104
|
+
1. Fork it ( https://github.com/Atomoworks/convertkit-ruby/fork )
|
105
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
107
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
5. Create a new Pull Request
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "convertkit"
|
5
|
+
require "dotenv"
|
6
|
+
|
7
|
+
Dotenv.load(".env.local")
|
8
|
+
|
9
|
+
Convertkit.configure do |config|
|
10
|
+
config.api_secret = ENV["API_SECRET"]
|
11
|
+
config.api_key = ENV["API_KEY"]
|
12
|
+
end
|
13
|
+
|
14
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
15
|
+
# with your gem easier. You can also use a different console, if you like.
|
16
|
+
|
17
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
18
|
+
# require "pry"
|
19
|
+
# Pry.start
|
20
|
+
|
21
|
+
require "irb"
|
22
|
+
IRB.start
|
data/bin/setup
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 'convertkit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "convertkit-ruby"
|
8
|
+
spec.version = Convertkit::VERSION
|
9
|
+
spec.authors = ["Raymond Cudjoe","Hook Engine"]
|
10
|
+
spec.email = ["rkcudjoe@gmail.com","rkcudjoe@hookengine.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby gem for interacting with the ConvertKit API v3}
|
13
|
+
spec.description = %q{A simple wrapper for the ConvertKit API}
|
14
|
+
spec.homepage = "http://hookengine.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
|
20
|
+
if spec.respond_to?(:metadata)
|
21
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "dotenv", "~> 2.1"
|
35
|
+
|
36
|
+
spec.add_runtime_dependency "faraday", "~> 1.0"
|
37
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 1.0"
|
38
|
+
spec.add_runtime_dependency "json", '>= 1.8.3'
|
39
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.convertkit.com/v3/account?api_key=<API_KEY>&api_secret=<API_SECRET>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Date:
|
26
|
+
- Wed, 17 Jan 2018 09:10:11 GMT
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Strict-Transport-Security:
|
30
|
+
- max-age=31536000
|
31
|
+
X-Frame-Options:
|
32
|
+
- ALLOWALL
|
33
|
+
X-Xss-Protection:
|
34
|
+
- 1; mode=block
|
35
|
+
X-Content-Type-Options:
|
36
|
+
- nosniff
|
37
|
+
X-Ua-Compatible:
|
38
|
+
- chrome=1
|
39
|
+
Content-Type:
|
40
|
+
- application/json; charset=utf-8
|
41
|
+
Etag:
|
42
|
+
- '"31780a9f8927b4bd79eabb594a810a34"'
|
43
|
+
Cache-Control:
|
44
|
+
- max-age=0, private, must-revalidate
|
45
|
+
Set-Cookie:
|
46
|
+
- XSRF-TOKEN=diVno%2FS7V7GFb4pbqOovRPnLYFLZ3ZzxHwkwWA6UN0aWW8KoIhJVeGajXm1oQdEkQoN5vcNEMgrgYKVe6io5ZQ%3D%3D;
|
47
|
+
path=/; secure
|
48
|
+
- _mailapp_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTBmZjA3OTJlYmZiZDRlMmZiMDRhOWE1Njk4OGI4N2E5BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTRINmxDOWFwQXNuanpOUTJ3S3YrWUx0SUdlOGFtYTc3LzJtVkJ1UytEaU09BjsARg%3D%3D--302b98f5ac8e3011ce838971d06f91655aee9c57;
|
49
|
+
path=/; secure; HttpOnly
|
50
|
+
X-Request-Id:
|
51
|
+
- 9d124ca6-8fa0-4af7-8eb6-e9de81fdf524
|
52
|
+
X-Runtime:
|
53
|
+
- '0.045639'
|
54
|
+
Vary:
|
55
|
+
- Accept-Encoding, Origin
|
56
|
+
Transfer-Encoding:
|
57
|
+
- chunked
|
58
|
+
Via:
|
59
|
+
- 1.1 vegur
|
60
|
+
body:
|
61
|
+
encoding: ASCII-8BIT
|
62
|
+
string: '{"name":"","primary_email_address":"email@example.com"}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Wed, 17 Jan 2018 09:10:12 GMT
|
65
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.convertkit.com/v3/forms/175221/subscribe?api_key=<API_KEY>&api_secret=<API_SECRET>&email=test@example.com&fields&first_name&tags
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Content-Length:
|
17
|
+
- '0'
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Cowboy
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Strict-Transport-Security:
|
30
|
+
- max-age=31536000
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
X-Ua-Compatible:
|
34
|
+
- IE=Edge,chrome=1
|
35
|
+
Etag:
|
36
|
+
- '"6f4dadc87b9a387093acd852dea9618e"'
|
37
|
+
Cache-Control:
|
38
|
+
- max-age=0, private, must-revalidate
|
39
|
+
Set-Cookie:
|
40
|
+
- XSRF-TOKEN=0SJZ0xaPTqHyg18%2BKQTSzc8d06nLQ52PAA8CJFnNGYjPxXvaO4%2FiRw1h%2BJy1Mqg3fLc1KeCNh7WK9wi7D%2BTZoQ%3D%3D;
|
41
|
+
path=/; secure
|
42
|
+
- _mailapp_session=BAh7BzoQX2NzcmZfdG9rZW5JIjFIdWNpQ1MwQXJPYi80cWVpbkRaNityT3E1b0FyemhvNml2Z0tuMVlwd0NrPQY6BkVGSSIPc2Vzc2lvbl9pZAY7BlRJIiViMGU3ZWUxNWM4Y2JkOTA5MDE4MGIzNzc3ZTRkNjE4ZQY7BlQ%3D--af4cf7b866ea64b704d0265f67773beb6a442f1e;
|
43
|
+
path=/; secure; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 581c1b56-1f79-4f3e-941b-821ce66ede3e
|
46
|
+
X-Runtime:
|
47
|
+
- '0.239698'
|
48
|
+
Vary:
|
49
|
+
- Accept-Encoding, Origin
|
50
|
+
Date:
|
51
|
+
- Tue, 28 Feb 2017 01:56:05 GMT
|
52
|
+
X-Rack-Cache:
|
53
|
+
- invalidate, pass
|
54
|
+
Transfer-Encoding:
|
55
|
+
- chunked
|
56
|
+
Via:
|
57
|
+
- 1.1 vegur
|
58
|
+
body:
|
59
|
+
encoding: ASCII-8BIT
|
60
|
+
string: '{"subscription":{"id":376449416,"state":"inactive","created_at":"2017-02-28T01:56:05Z","source":null,"referrer":null,"subscribable_id":175221,"subscribable_type":"form","subscriber":{"id":92766417,"first_name":null,"email_address":"test@example.com","state":"inactive","created_at":"2017-02-28T01:56:05Z","fields":{}}}}'
|
61
|
+
http_version:
|
62
|
+
recorded_at: Tue, 28 Feb 2017 01:56:05 GMT
|
63
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://api.convertkit.com/v3/custom_fields/11176?api_key=<API_KEY>&api_secret=<API_SECRET>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 204
|
21
|
+
message: No Content
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Content-Length:
|
26
|
+
- '0'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Strict-Transport-Security:
|
30
|
+
- max-age=31536000
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge,chrome=1
|
33
|
+
Cache-Control:
|
34
|
+
- no-cache, no-transform
|
35
|
+
Set-Cookie:
|
36
|
+
- XSRF-TOKEN=fmDy%2Fft9G%2F27ou%2Bhv1ImZi1kMJKcG5Vy69Hn5%2BlLnf0%2F1DZe%2FiWYEK8teH0uzhrMOmLCLqVvUCtiW1OfX%2BuFpw%3D%3D;
|
37
|
+
path=/; secure
|
38
|
+
- _mailapp_session=BAh7BzoQX2NzcmZfdG9rZW5JIjFRYlRFb3dWWWcrMFVqNWZja1p3OHFoY0c4cnc1ZE1WWmlZcTBlTGFnR0ZvPQY6BkVGSSIPc2Vzc2lvbl9pZAY7BlRJIiUzMWU1YzVmNjhkM2U1MDI5NjhmN2VhODQ2Mjc4OGVlOQY7BlQ%3D--352d4b2c54243bc8ee9def05694b6eb8bc799561;
|
39
|
+
path=/; secure; HttpOnly
|
40
|
+
X-Request-Id:
|
41
|
+
- 2660d874-056f-4c6d-af0b-8e51a2f8436f
|
42
|
+
X-Runtime:
|
43
|
+
- '0.070583'
|
44
|
+
Date:
|
45
|
+
- Fri, 03 Mar 2017 01:30:58 GMT
|
46
|
+
X-Rack-Cache:
|
47
|
+
- invalidate, pass
|
48
|
+
Vary:
|
49
|
+
- Origin
|
50
|
+
Via:
|
51
|
+
- 1.1 vegur
|
52
|
+
body:
|
53
|
+
encoding: UTF-8
|
54
|
+
string: ''
|
55
|
+
http_version:
|
56
|
+
recorded_at: Fri, 03 Mar 2017 01:30:58 GMT
|
57
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,64 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.convertkit.com/v3/forms?api_key=<API_KEY>&api_secret=<API_SECRET>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=31536000
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge,chrome=1
|
33
|
+
Etag:
|
34
|
+
- '"2d9600a1c415ac1e19ee2465fe41e8cc"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
Set-Cookie:
|
38
|
+
- XSRF-TOKEN=a1hcmaYVulN4QDrGoRSz6Y51cfjXMdmyJ66kyX3dPECeDZnhdd9AOW%2BBSwx3ppH5jwi4MQ%2FuR5kIfxCRlDy8dg%3D%3D;
|
39
|
+
path=/; secure
|
40
|
+
- _mailapp_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTMwYzJkNTcxMWViZjNhMmVjYTIxZjI0NDE0NGZiYjY2BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTlWWEZlTlBLK21vWHdYSEsxcklpRUFGOXljblkzNTRyTDlHMFdPbmhnRFk9BjsARg%3D%3D--f0567bcf5195953cceab58959153298cdae4426b;
|
41
|
+
path=/; secure; HttpOnly
|
42
|
+
X-Request-Id:
|
43
|
+
- 6816358f-f95d-4374-ada6-9afe67a9717b
|
44
|
+
X-Runtime:
|
45
|
+
- '0.022329'
|
46
|
+
Vary:
|
47
|
+
- Accept-Encoding, Origin
|
48
|
+
Date:
|
49
|
+
- Fri, 02 Dec 2016 22:20:57 GMT
|
50
|
+
X-Rack-Cache:
|
51
|
+
- miss
|
52
|
+
Transfer-Encoding:
|
53
|
+
- chunked
|
54
|
+
Via:
|
55
|
+
- 1.1 vegur
|
56
|
+
body:
|
57
|
+
encoding: ASCII-8BIT
|
58
|
+
string: '{"forms":[{"id":133233,"name":"Did you like this post","created_at":"2016-12-01T17:25:23Z","type":"embed","url":"https://app.convertkit.com/landing_pages/133233","embed_js":"https://api.convertkit.com/v3/forms/133233.js?api_key=<API_KEY>","embed_url":"https://api.convertkit.com/v3/forms/133233.html?api_key=<API_KEY>","title":"Did
|
59
|
+
you like this post?","description":"\u003Cp\u003ESubscribe to my newsletter
|
60
|
+
and start every week with a new interesting post! \u003C/p\u003E","sign_up_button_text":"Subscribe","success_message":"Success!
|
61
|
+
Now check your email to confirm your subscription."}]}'
|
62
|
+
http_version:
|
63
|
+
recorded_at: Fri, 02 Dec 2016 22:21:29 GMT
|
64
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,62 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.convertkit.com/v3/custom_fields?api_key=<API_KEY>&api_secret=<API_SECRET>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- Cowboy
|
25
|
+
Connection:
|
26
|
+
- keep-alive
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=31536000
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
X-Ua-Compatible:
|
32
|
+
- IE=Edge,chrome=1
|
33
|
+
Etag:
|
34
|
+
- '"347787094aacea2ed1f0bc87551ec42e"'
|
35
|
+
Cache-Control:
|
36
|
+
- max-age=0, private, must-revalidate
|
37
|
+
Set-Cookie:
|
38
|
+
- XSRF-TOKEN=3%2F4ZwCDq72351KoSaKy5mRS87oiJTV4PCXk5uManqokO9Ej8zQUv4E2vXbPueOaKlRqs9cFcadHV0lqcfUC8dg%3D%3D;
|
39
|
+
path=/; secure
|
40
|
+
- _mailapp_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJTFjMzc4N2Y5M2YwZGVmZGExYTQ0YjBjYThmMWE1YWU5BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTBRcFJQTzN2d0kyMGUvZWhodFJmRTRHbVFuMUlFVGZlM0t0akpMdm5Gdjg9BjsARg%3D%3D--4ce462d08e77f8371cb3895c4f85c8425d210525;
|
41
|
+
path=/; secure; HttpOnly
|
42
|
+
X-Request-Id:
|
43
|
+
- 56645fe1-1737-4648-beaa-0b374aa5bb0c
|
44
|
+
X-Runtime:
|
45
|
+
- '0.075874'
|
46
|
+
Vary:
|
47
|
+
- Accept-Encoding, Origin
|
48
|
+
Date:
|
49
|
+
- Fri, 03 Mar 2017 01:05:50 GMT
|
50
|
+
X-Rack-Cache:
|
51
|
+
- miss
|
52
|
+
Transfer-Encoding:
|
53
|
+
- chunked
|
54
|
+
Via:
|
55
|
+
- 1.1 vegur
|
56
|
+
body:
|
57
|
+
encoding: ASCII-8BIT
|
58
|
+
string: '{"custom_fields":[{"id":11174,"name":"ck_field_11174_phone_number","key":"phone_number","label":"Phone
|
59
|
+
Number"}]}'
|
60
|
+
http_version:
|
61
|
+
recorded_at: Fri, 03 Mar 2017 01:05:51 GMT
|
62
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.convertkit.com/v3/custom_fields?api_key=<API_KEY>&api_secret=<API_SECRET>&label=Occupation
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Content-Length:
|
17
|
+
- '0'
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 201
|
23
|
+
message: Created
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Cowboy
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Strict-Transport-Security:
|
30
|
+
- max-age=31536000
|
31
|
+
Location:
|
32
|
+
- "/v3/custom_fields"
|
33
|
+
Content-Type:
|
34
|
+
- application/json; charset=utf-8
|
35
|
+
X-Ua-Compatible:
|
36
|
+
- IE=Edge,chrome=1
|
37
|
+
Etag:
|
38
|
+
- '"a28614c3d7734e0085a61cde2c07b05a"'
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- XSRF-TOKEN=pQN4%2BB%2FjHD4EqdFEpswxsF%2BnGsNfS%2FWTHnzKcnkOQSJucNwxsBRer4bXi%2Fm%2F%2FeMrg221XkmNeQ1%2Fn%2B2f9iLJIw%3D%3D;
|
43
|
+
path=/; secure
|
44
|
+
- _mailapp_session=BAh7BzoQX2NzcmZfdG9rZW5JIjF5M09reWEvM1FwR0NmbHE5R1RIU205ektyNTBXeG95ZVllTW43WThzaUFFPQY6BkVGSSIPc2Vzc2lvbl9pZAY7BlRJIiVmYTQzNTk1YjI3ZjcxMWU3ZGM4YjZiNTc1MzVjODMyYgY7BlQ%3D--c362e7889147cb4a77103b99cdc5721e88a12b30;
|
45
|
+
path=/; secure; HttpOnly
|
46
|
+
X-Request-Id:
|
47
|
+
- 2eef5bf1-8f2b-4a68-a157-0d7ccbef1012
|
48
|
+
X-Runtime:
|
49
|
+
- '0.073102'
|
50
|
+
Vary:
|
51
|
+
- Accept-Encoding, Origin
|
52
|
+
Date:
|
53
|
+
- Fri, 03 Mar 2017 01:22:53 GMT
|
54
|
+
X-Rack-Cache:
|
55
|
+
- invalidate, pass
|
56
|
+
Transfer-Encoding:
|
57
|
+
- chunked
|
58
|
+
Via:
|
59
|
+
- 1.1 vegur
|
60
|
+
body:
|
61
|
+
encoding: ASCII-8BIT
|
62
|
+
string: '{"account_id":26718,"created_at":"2017-03-03T01:22:53Z","id":11176,"key":"occupation","kind":null,"label":"Occupation","updated_at":"2017-03-03T01:22:53Z","name":"ck_field_11176_occupation","value":null}'
|
63
|
+
http_version:
|
64
|
+
recorded_at: Fri, 03 Mar 2017 01:22:53 GMT
|
65
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: put
|
5
|
+
uri: https://api.convertkit.com/v3/custom_fields/11184?api_key=<API_KEY>&api_secret=<API_SECRET>&label=Discount%20Code
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Convertkit-Ruby v0.0.2
|
12
|
+
Content-Type:
|
13
|
+
- application/vnd.api+json
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
Content-Length:
|
17
|
+
- '0'
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 204
|
23
|
+
message: No Content
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- Cowboy
|
27
|
+
Content-Length:
|
28
|
+
- '0'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Strict-Transport-Security:
|
32
|
+
- max-age=31536000
|
33
|
+
X-Ua-Compatible:
|
34
|
+
- IE=Edge,chrome=1
|
35
|
+
Cache-Control:
|
36
|
+
- no-cache, no-transform
|
37
|
+
Set-Cookie:
|
38
|
+
- XSRF-TOKEN=KHxmbTwPv230b%2FnQnhMO22pGqNhCPcksnKcn8HEx6KbM%2FH8V8aSKk25Y%2BZgzkACvJUasYJYWXYqihd2OsUBYRg%3D%3D;
|
39
|
+
path=/; secure
|
40
|
+
- _mailapp_session=BAh7BzoQX2NzcmZfdG9rZW5JIjE1SUFaZU0yck5mNmFOd0JJcllNT2RFOEFCTGpVSzVTbVBpTDZmc0J4c09BPQY6BkVGSSIPc2Vzc2lvbl9pZAY7BlRJIiVkN2NlZmE3M2ZlYjZjOTNjNWY3NTY3ZDc5ZWYzMzliYwY7BlQ%3D--c7d09be19409ef827cd003f03a056e4f374da37c;
|
41
|
+
path=/; secure; HttpOnly
|
42
|
+
X-Request-Id:
|
43
|
+
- 2b8dc9b0-69ef-4c7d-bfaf-1b47ca740e09
|
44
|
+
X-Runtime:
|
45
|
+
- '0.156904'
|
46
|
+
Date:
|
47
|
+
- Fri, 03 Mar 2017 01:41:15 GMT
|
48
|
+
X-Rack-Cache:
|
49
|
+
- invalidate, pass
|
50
|
+
Vary:
|
51
|
+
- Origin
|
52
|
+
Via:
|
53
|
+
- 1.1 vegur
|
54
|
+
body:
|
55
|
+
encoding: UTF-8
|
56
|
+
string: ''
|
57
|
+
http_version:
|
58
|
+
recorded_at: Fri, 03 Mar 2017 01:41:15 GMT
|
59
|
+
recorded_with: VCR 3.0.3
|
data/lib/convertkit.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "convertkit/version"
|
2
|
+
require "convertkit/configuration"
|
3
|
+
require "convertkit/client"
|
4
|
+
|
5
|
+
module Convertkit
|
6
|
+
class << self
|
7
|
+
attr_accessor :configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "convertkit/client/account"
|
2
|
+
require "convertkit/client/custom_fields"
|
3
|
+
require "convertkit/client/forms"
|
4
|
+
require "convertkit/client/sequences"
|
5
|
+
require "convertkit/client/subscribers"
|
6
|
+
require "convertkit/client/webhooks"
|
7
|
+
require "convertkit/client/tags"
|
8
|
+
require "convertkit/connection"
|
9
|
+
|
10
|
+
module Convertkit
|
11
|
+
class Client
|
12
|
+
include Account
|
13
|
+
include CustomFields
|
14
|
+
include Forms
|
15
|
+
include Sequences
|
16
|
+
include Subscribers
|
17
|
+
include Webhooks
|
18
|
+
include Tags
|
19
|
+
|
20
|
+
attr_accessor :api_secret, :api_key
|
21
|
+
|
22
|
+
def initialize( api_key=nil, api_secret=nil )
|
23
|
+
@api_secret = api_secret || Convertkit.configuration.api_secret
|
24
|
+
@api_key = api_key || Convertkit.configuration.api_key
|
25
|
+
end
|
26
|
+
|
27
|
+
def connection
|
28
|
+
@connection ||= Connection.new(api_key: api_key, api_secret: api_secret)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module CustomFields
|
4
|
+
|
5
|
+
def custom_fields
|
6
|
+
connection.get("custom_fields").body["custom_fields"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_custom_field(options = {})
|
10
|
+
connection.post("custom_fields") do |f|
|
11
|
+
f.params['label'] = options[:label]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def delete_custom_field(custom_field_id)
|
16
|
+
connection.delete("custom_fields/#{custom_field_id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_custom_field(custom_field_id, options = {})
|
20
|
+
connection.put("custom_fields/#{custom_field_id}") do |f|
|
21
|
+
f.params['label'] = options[:label]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module Forms
|
4
|
+
def forms
|
5
|
+
connection.get("forms").body["forms"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_subscriber_to_form(form_id, email, options = {})
|
9
|
+
connection.post("forms/#{form_id}/subscribe") do |f|
|
10
|
+
f.params['email'] = email
|
11
|
+
f.params['first_name'] = options[:first_name]
|
12
|
+
f.params['fields'] = options[:fields]
|
13
|
+
f.params['tags'] = options[:tags]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module Sequences
|
4
|
+
def sequences
|
5
|
+
connection.get("sequences")
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_subscriber_to_sequence(sequence_id, email, options = {})
|
9
|
+
connection.post("sequences/#{sequence_id}/subscribe") do |f|
|
10
|
+
f.params['email'] = email
|
11
|
+
f.params['first_name'] = options[:first_name]
|
12
|
+
f.params['fields'] = options[:fields]
|
13
|
+
f.params['tags'] = options[:tags]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module Subscribers
|
4
|
+
def subscribers(options = {})
|
5
|
+
connection.get("subscribers", options)
|
6
|
+
end
|
7
|
+
|
8
|
+
def subscriber(subscriber_id)
|
9
|
+
connection.get("subscribers/#{subscriber_id}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def subscriber_tags(subscriber_id)
|
13
|
+
connection.get("subscribers/#{subscriber_id}/tags")
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_subscriber(subscriber_id, options = {})
|
17
|
+
response = connection.put("subscribers/#{subscriber_id}") do |f|
|
18
|
+
f.params["email_address"] = options[:email_address] if options[:email_address]
|
19
|
+
f.params["fields"] = options[:fields] if options[:fields]
|
20
|
+
f.params["first_name"] = options[:first_name] if options[:first_name]
|
21
|
+
end
|
22
|
+
response.body
|
23
|
+
end
|
24
|
+
|
25
|
+
def unsubscribe(email)
|
26
|
+
connection.put("unsubscribe") do |f|
|
27
|
+
f.params['email'] = email
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_tag_from_subscriber(subscriber_id, tag_id)
|
32
|
+
connection.delete("subscribers/#{subscriber_id}/tags/#{tag_id}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module Tags
|
4
|
+
def tags
|
5
|
+
connection.get("tags")
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_subscriber_to_tag(tag_id, email, options = {})
|
9
|
+
connection.post("tags/#{tag_id}/subscribe") do |f|
|
10
|
+
f.params['email'] = email
|
11
|
+
f.params['first_name'] = options[:first_name]
|
12
|
+
f.params['fields'] = options[:fields]
|
13
|
+
f.params['tags'] = options[:tags]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove_tag_from_subscriber(tag_id, subscriber_id)
|
18
|
+
connection.delete("subscribers/#{subscriber_id}/tags/#{tag_id}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def remove_tag_from_subscriber_by_email(tag_id, email)
|
22
|
+
connection.post("tags/#{tag_id}/unsubscribe") do |f|
|
23
|
+
f.params['email'] = email
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_tag(tag_name)
|
28
|
+
response = connection.post("tags") do |request|
|
29
|
+
request.params["tag"] = { name: tag_name }
|
30
|
+
end
|
31
|
+
response.body
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_tags(tag_names)
|
35
|
+
response = connection.post("tags") do |request|
|
36
|
+
request.params["tag"] = tag_names.map { |tag_name| { name: tag_name } }
|
37
|
+
end
|
38
|
+
response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def subscriptions_to_tag(tag_id, options = {})
|
42
|
+
connection.get("tags/#{tag_id}/subscriptions", options) do |f|
|
43
|
+
f.params["sort_order"] = options[:sort_order] if options[:sort_order]
|
44
|
+
f.params["subscriber_state"] = options[:subscriber_state] if options[:subscriber_state]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Client
|
3
|
+
module Webhooks
|
4
|
+
def create_webhook(url, events)
|
5
|
+
response = connection.post("automations/hooks") do |f|
|
6
|
+
f.params['target_url'] = url
|
7
|
+
f.params['event'] = events
|
8
|
+
end
|
9
|
+
response.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_webhook(rule_id)
|
13
|
+
connection.delete("automations/hooks/#{rule_id}").body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "convertkit/errors"
|
2
|
+
require "faraday"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Convertkit
|
7
|
+
class Connection
|
8
|
+
attr_reader :http_connection
|
9
|
+
|
10
|
+
def initialize(api_key: nil, api_secret: nil)
|
11
|
+
@http_connection = faraday_connection(api_key, api_secret)
|
12
|
+
end
|
13
|
+
|
14
|
+
def content_type
|
15
|
+
"application/vnd.api+json"
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(*args, &blk)
|
19
|
+
request(:get, *args, &blk)
|
20
|
+
end
|
21
|
+
|
22
|
+
def post(*args, &blk)
|
23
|
+
request(:post, *args, &blk)
|
24
|
+
end
|
25
|
+
|
26
|
+
def put(*args, &blk)
|
27
|
+
request(:put, *args, &blk)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(*args, &blk)
|
31
|
+
request(:delete, *args, &blk)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def faraday_connection(api_key, api_secret)
|
37
|
+
Faraday.new do |f|
|
38
|
+
f.url_prefix = "https://api.convertkit.com/v3/"
|
39
|
+
f.adapter :net_http
|
40
|
+
|
41
|
+
f.options.timeout = Convertkit.configuration.timeout
|
42
|
+
f.options.open_timeout = Convertkit.configuration.open_timeout
|
43
|
+
|
44
|
+
f.headers['User-Agent'] = "Convertkit-Ruby v#{Convertkit::VERSION}"
|
45
|
+
f.headers['Content-Type'] = content_type
|
46
|
+
f.headers['Accept'] = "*/*"
|
47
|
+
|
48
|
+
f.params['api_secret'] = api_secret if api_secret
|
49
|
+
f.params['api_key'] = api_key if api_key
|
50
|
+
|
51
|
+
f.response :json, content_type: /\bjson$/
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def request(method, *args, &blk)
|
56
|
+
begin
|
57
|
+
response = http_connection.public_send(method, *args, &blk)
|
58
|
+
rescue Faraday::Error => e
|
59
|
+
raise ConnectionError.new(e)
|
60
|
+
end
|
61
|
+
|
62
|
+
unless response.success?
|
63
|
+
handle_error_response(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
response
|
67
|
+
end
|
68
|
+
|
69
|
+
def handle_error_response(response)
|
70
|
+
case response.status
|
71
|
+
when 401
|
72
|
+
raise AuthorizationError.new(response.body)
|
73
|
+
when 404
|
74
|
+
raise NotFoundError.new(response.body)
|
75
|
+
when 422
|
76
|
+
raise UnprocessableEntityError.new(response.body)
|
77
|
+
when 429
|
78
|
+
raise TooManyRequestsError.new(response.body)
|
79
|
+
when 500..599
|
80
|
+
raise ServerError.new(response.body)
|
81
|
+
else
|
82
|
+
raise UnknownError.new(response.body)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class AuthorizationError < Error; end
|
5
|
+
class ConnectionError < Error; end
|
6
|
+
class NotFoundError < Error; end
|
7
|
+
class ServerError < Error; end
|
8
|
+
class TooManyRequestsError < Error; end
|
9
|
+
class UnknownError < Error; end
|
10
|
+
class UnprocessableEntityError < Error; end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convertkit-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raymond Cudjoe
|
8
|
+
- Hook Engine
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-08-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: dotenv
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '2.1'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.1'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: faraday
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: faraday_middleware
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: json
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.8.3
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.8.3
|
112
|
+
description: A simple wrapper for the ConvertKit API
|
113
|
+
email:
|
114
|
+
- rkcudjoe@gmail.com
|
115
|
+
- rkcudjoe@hookengine.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- ".github/workflows/ruby.yml"
|
121
|
+
- ".gitignore"
|
122
|
+
- ".rspec"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CODE_OF_CONDUCT.md
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- convertkit-ruby.gemspec
|
132
|
+
- fixtures/vcr_cassettes/account.yml
|
133
|
+
- fixtures/vcr_cassettes/add_subscriber_to_form.yml
|
134
|
+
- fixtures/vcr_cassettes/delete_custom_field.yml
|
135
|
+
- fixtures/vcr_cassettes/forms.yml
|
136
|
+
- fixtures/vcr_cassettes/get_custom_fields.yml
|
137
|
+
- fixtures/vcr_cassettes/new_custom_field.yml
|
138
|
+
- fixtures/vcr_cassettes/update_custom_field.yml
|
139
|
+
- lib/convertkit.rb
|
140
|
+
- lib/convertkit/client.rb
|
141
|
+
- lib/convertkit/client/account.rb
|
142
|
+
- lib/convertkit/client/custom_fields.rb
|
143
|
+
- lib/convertkit/client/forms.rb
|
144
|
+
- lib/convertkit/client/sequences.rb
|
145
|
+
- lib/convertkit/client/subscribers.rb
|
146
|
+
- lib/convertkit/client/tags.rb
|
147
|
+
- lib/convertkit/client/webhooks.rb
|
148
|
+
- lib/convertkit/configuration.rb
|
149
|
+
- lib/convertkit/connection.rb
|
150
|
+
- lib/convertkit/errors.rb
|
151
|
+
- lib/convertkit/version.rb
|
152
|
+
homepage: http://hookengine.com
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata:
|
156
|
+
allowed_push_host: https://rubygems.org
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubygems_version: 3.0.0
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: A Ruby gem for interacting with the ConvertKit API v3
|
176
|
+
test_files: []
|