convertkit-ruby_api 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.local.sample +16 -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 +111 -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 +29 -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 +28 -0
- data/lib/convertkit/client/tags.rb +32 -0
- data/lib/convertkit/configuration.rb +10 -0
- data/lib/convertkit/connection.rb +81 -0
- data/lib/convertkit/errors.rb +10 -0
- data/lib/convertkit/version.rb +3 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b1cb378d2894b8cc58ce83b2eb82e9899523730846bf3100520547fa4970ad47
|
4
|
+
data.tar.gz: 1c844adfd95900048c719d1ba5bd0b0c8b44028a4cbb238ac9c2cd167c27a689
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75fcac2bacf04477d0e51f69a613fe2bf40cf32b2062a7a1a95c82ac33a25c48fa4bd736b72c86b7f3eedb42036e737c3b9c8a1bedc15dc159270f530fcc7426
|
7
|
+
data.tar.gz: c83075ccd185747410eb020763a7cbfee6d86ed2530e0598690d1cf378bca73c860a74977ca645c9189f277864c6157f8d1354bc4e370c183a73ca5cdd3fcdec
|
data/.env.local.sample
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# copy this file to .env.local and substitute real values from
|
2
|
+
# your own convertkit account
|
3
|
+
|
4
|
+
API_SECRET='ABC'
|
5
|
+
API_KEY='DEF'
|
6
|
+
|
7
|
+
# a subscriber to retrieve
|
8
|
+
SUBSCRIBER_ID='GHI'
|
9
|
+
|
10
|
+
# a tag to retrieve and add a subscriber to
|
11
|
+
TAG_ID='JKL'
|
12
|
+
|
13
|
+
# a sequence to retrieve and add a subscriber to
|
14
|
+
SEQUENCE_ID='MNO'
|
15
|
+
# tags to add to a new subscriber when adding to a sequence
|
16
|
+
TAGS='PQR,STU'
|
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,111 @@
|
|
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
|
+
| Action | Method |
|
44
|
+
|:------------------------|:-----------------------------|
|
45
|
+
| Get account information | `#account` |
|
46
|
+
| List subscribers | `#subscribers(options = {})` |
|
47
|
+
| Fetch a subscriber | `#subscriber(subscriber_id)` |
|
48
|
+
| Update a subscriber | `#update_subscriber(subscriber_id, options = {})` |
|
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
|
+
| Create a tag | `#create_tag(tag_name)` |
|
54
|
+
| Create multiple tags | `#create_tags(tag_names)`|
|
55
|
+
| List forms | `#forms` |
|
56
|
+
| Add subscriber to form | `#add_subscriber_to_form(form_id, email, options = {})`|
|
57
|
+
| Unsubscribe | `#unsubscribe(email)` |
|
58
|
+
|
59
|
+
**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. [See the official API documentation](http://kb.convertkit.com/article/api-documentation-v3/) for a complete API reference.
|
60
|
+
|
61
|
+
## Use Cases
|
62
|
+
|
63
|
+
Here are some common use cases for the Convertkit v3 API client.
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
### List subscribers
|
68
|
+
|
69
|
+
List all subscribers added to your account on or after a specific date.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
response = client.subscribers(from: "2016-03-01")
|
73
|
+
# => <Faraday::Response ...>
|
74
|
+
|
75
|
+
response.status
|
76
|
+
# => 200
|
77
|
+
```
|
78
|
+
|
79
|
+
### Fetching subscriber data
|
80
|
+
|
81
|
+
Subscribers can be looked up by their ``subscriber_id``.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
response = client.subscriber("17682009")
|
85
|
+
# => <Faraday::Response ...>
|
86
|
+
|
87
|
+
response.status
|
88
|
+
# => 200
|
89
|
+
```
|
90
|
+
|
91
|
+
## Development
|
92
|
+
|
93
|
+
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.
|
94
|
+
|
95
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
96
|
+
|
97
|
+
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).
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hookengine/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.
|
102
|
+
|
103
|
+
1. Fork it ( https://github.com/hookengine/convertkit-ruby/fork )
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create a new Pull Request
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
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_api"
|
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", "~> 1.11"
|
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", ">= 0.9.2"
|
37
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.10.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,29 @@
|
|
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/tags"
|
7
|
+
require "convertkit/connection"
|
8
|
+
|
9
|
+
module Convertkit
|
10
|
+
class Client
|
11
|
+
include Account
|
12
|
+
include CustomFields
|
13
|
+
include Forms
|
14
|
+
include Sequences
|
15
|
+
include Subscribers
|
16
|
+
include Tags
|
17
|
+
|
18
|
+
attr_accessor :api_secret, :api_key
|
19
|
+
|
20
|
+
def initialize( api_key=nil, api_secret=nil )
|
21
|
+
@api_secret = api_secret || Convertkit.configuration.api_secret
|
22
|
+
@api_key = api_key || Convertkit.configuration.api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def connection
|
26
|
+
@connection ||= Connection.new(api_key: api_key, api_secret: api_secret)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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,28 @@
|
|
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 update_subscriber(subscriber_id, options = {})
|
13
|
+
response = connection.put("subscribers/#{subscriber_id}") do |f|
|
14
|
+
f.params["email_address"] = options[:email_address] if options[:email_address]
|
15
|
+
f.params["fields"] = options[:fields] if options[:fields]
|
16
|
+
f.params["first_name"] = options[:first_name] if options[:first_name]
|
17
|
+
end
|
18
|
+
response.body
|
19
|
+
end
|
20
|
+
|
21
|
+
def unsubscribe(email)
|
22
|
+
connection.put("unsubscribe") do |f|
|
23
|
+
f.params['email'] = email
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 create_tag(tag_name)
|
18
|
+
response = connection.post("tags") do |request|
|
19
|
+
request.params["tag"] = { name: tag_name }
|
20
|
+
end
|
21
|
+
response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_tags(tag_names)
|
25
|
+
response = connection.post("tags") do |request|
|
26
|
+
request.params["tag"] = tag_names.map { |tag_name| { name: tag_name } }
|
27
|
+
end
|
28
|
+
response.body
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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.headers['User-Agent'] = "Convertkit-Ruby v#{Convertkit::VERSION}"
|
42
|
+
f.headers['Content-Type'] = content_type
|
43
|
+
f.headers['Accept'] = "*/*"
|
44
|
+
|
45
|
+
f.params['api_secret'] = api_secret if api_secret
|
46
|
+
f.params['api_key'] = api_key if api_key
|
47
|
+
|
48
|
+
f.response :json, content_type: /\bjson$/
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def request(method, *args, &blk)
|
53
|
+
begin
|
54
|
+
response = http_connection.public_send(method, *args, &blk)
|
55
|
+
rescue Faraday::Error => e
|
56
|
+
raise ConnectionError.new(e)
|
57
|
+
end
|
58
|
+
|
59
|
+
unless response.success?
|
60
|
+
handle_error_response(response)
|
61
|
+
end
|
62
|
+
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
def handle_error_response(response)
|
67
|
+
case response.status
|
68
|
+
when 401
|
69
|
+
raise AuthorizationError.new(response.body)
|
70
|
+
when 422
|
71
|
+
raise UnprocessableEntityError.new(response.body)
|
72
|
+
when 429
|
73
|
+
raise TooManyRequestsError.new(response.body)
|
74
|
+
when 500..599
|
75
|
+
raise ServerError.new(response.body)
|
76
|
+
else
|
77
|
+
raise UnknownError.new(response.body)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Convertkit
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class AuthorizationError < Error; end
|
5
|
+
class ConnectionError < Error; end
|
6
|
+
class ServerError < Error; end
|
7
|
+
class TooManyRequestsError < Error; end
|
8
|
+
class UnknownError < Error; end
|
9
|
+
class UnprocessableEntityError < Error; end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convertkit-ruby_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raymond Cudjoe
|
8
|
+
- Hook Engine
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-09-19 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: '1.11'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.11'
|
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: 0.9.2
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.9.2
|
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: 0.10.0
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.10.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
|
+
- ".env.local.sample"
|
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/configuration.rb
|
148
|
+
- lib/convertkit/connection.rb
|
149
|
+
- lib/convertkit/errors.rb
|
150
|
+
- lib/convertkit/version.rb
|
151
|
+
homepage: http://hookengine.com
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata:
|
155
|
+
allowed_push_host: https://rubygems.org
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.7.7
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: A Ruby gem for interacting with the ConvertKit API v3
|
176
|
+
test_files: []
|