Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in convertkit-ruby.gemspec
# Specify your gem's dependencies in convertkit_v4-ruby.gemspec
gemspec

gem 'dotenv', '~> 2.1', '>= 2.1.1'
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Convertkit Ruby Client
# Convertkit V4 Ruby Client

A Ruby toolkit for [Convertkit](https://convertkit.com/) API.
A Ruby toolkit for [ConvertkitV4](https://convertkit.com/) API.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this was a CTRL+F+REPLACE kind of job :)


## Installation

Add this line to your application's Gemfile:

```ruby
gem 'convertkit-ruby', require: 'convertkit'
gem 'convertkit_v4-ruby', require: 'convertkit_v4'
```

And then execute:
Expand All @@ -16,29 +16,29 @@ And then execute:

Or install it yourself as:

$ gem install convertkit-ruby
$ gem install convertkit_v4-ruby

## Authentication

For private integrations, use your personal ``API_KEY`` and ``API_SECRET`` found in [your account settings.](https://app.convertkit.com/account/edit)
For private integrations, use your personal ``API_KEY`` and ``API_SECRET`` found in [your account settings.](https://app.ConvertkitV4.com/account/edit)

```ruby
require "dotenv"
Dotenv.load(".env.local")

Convertkit.configure do |config|
ConvertkitV4.configure do |config|
config.api_secret = ENV["API_SECRET"]
config.api_key = ENV["API_KEY"]
end
Comment on lines +29 to 32
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to update these instructions :)


client = Convertkit::Client.new
client = ConvertkitV4::Client.new
```

## Usage

Calls for Convertkit API v3 are relative to the url [http://api.convertkit.com/v3](http://api.convertkit.com/v3).
Calls for ConvertkitV4 API v3 are relative to the url [developers.convertkit.com](developers.convertkit.com).

API actions are available as methods on the client object. Currently, the Convertkit client has the following methods:
API actions are available as methods on the client object. Currently, the ConvertkitV4 client has the following methods:


| Action | Method |
Expand All @@ -61,9 +61,9 @@ API actions are available as methods on the client object. Currently, the Conver

## Use Cases

Here are some common use cases for the Convertkit v3 API client.
Here are some common use cases for the ConvertkitV4 v4 API client.

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.
First configure the ``convertkit_v4-ruby`` gem with your ``API_KEY`` and ``API_SECRET``, and initialize a new client. After that, you can fetch data from your account.

### List subscribers

Expand Down Expand Up @@ -99,9 +99,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

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.
Bug reports and pull requests are welcome on GitHub at https://github.com/SparkLoop/convertkit-ruby-v4. 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.

1. Fork it ( https://github.com/Atomoworks/convertkit-ruby/fork )
1. Fork it ( https://github.com/SparkLoop/convertkit-ruby-v4/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
9 changes: 5 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "convertkit"
require "convertkit_v4"
require "dotenv"

Dotenv.load(".env.local")

Convertkit.configure do |config|
config.api_secret = ENV["API_SECRET"]
config.api_key = ENV["API_KEY"]
ConvertkitV4.configure do |config|
config.client_id = ENV["CONVERTKIT_CLIENT_ID"]
config.client_secret = ENV["CONVERTKIT_CLIENT_SECRET"]
config.redirect_uri = ENV["CONVERTKIT_REDIRECT_URI"]
end

# You can add fixtures and/or initialization code here to make experimenting
Expand Down
14 changes: 7 additions & 7 deletions convertkit-ruby.gemspec → convertkit_v4-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'convertkit/version'
require 'convertkit_v4/version'

Gem::Specification.new do |spec|
spec.name = "convertkit-ruby"
spec.version = Convertkit::VERSION
spec.authors = ["Manuel Frigerio"]
spec.email = ["manuel.frigerio@gmail.com"]
spec.name = "convertkit_v4-ruby"
spec.version = ConvertkitV4::VERSION
spec.authors = ["Manuel Frigerio", "Petar Risteski"]
spec.email = ["manuel.frigerio@gmail.com", "risteskipetar3@gmail.com"]

spec.summary = %q{A Ruby gem for interacting with the ConvertKit API v3}
spec.description = %q{A simple wrapper for the ConvertKit API}
spec.summary = %q{A Ruby gem for interacting with the Convertkit API v4}
spec.description = %q{A simple wrapper for the Convertkit V4 API}
spec.homepage = "https://manuel.friger.io"
spec.license = "MIT"

Expand Down
4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/account.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/add_subscriber_to_form.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/delete_custom_field.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/forms.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/get_custom_fields.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/new_custom_field.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fixtures/vcr_cassettes/update_custom_field.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions lib/convertkit/client.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/convertkit.rb → lib/convertkit_v4.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "convertkit/version"
require "convertkit/configuration"
require "convertkit/client"
require "convertkit_v4/version"
require "convertkit_v4/configuration"
require "convertkit_v4/client"

module Convertkit
module ConvertkitV4
class << self
attr_accessor :configuration
end
Expand Down
82 changes: 82 additions & 0 deletions lib/convertkit_v4/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require "convertkit_v4/client/account"
require "convertkit_v4/client/custom_fields"
require "convertkit_v4/client/forms"
require "convertkit_v4/client/sequences"
require "convertkit_v4/client/subscribers"
require "convertkit_v4/client/webhooks"
require "convertkit_v4/client/tags"
require "convertkit_v4/connection"

module ConvertkitV4
class Client
include Account
include CustomFields
include Forms
include Sequences
include Subscribers
include Webhooks
include Tags

attr_accessor :access_token, :refresh_token, :client_id, :client_secret, :redirect_uri

AUTH_URL = "https://app.convertkit.com/oauth/authorize"
ACCESS_TOKEN_URL = "https://app.convertkit.com/oauth/token"
REVOKE_ACCESS_URL = "https://app.convertkit.com/oauth/revoke"

def initialize(access_token: nil, refresh_token: nil, client_id: nil, client_secret: nil, redirect_uri: nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whilst we are here, can we kill two birds with one stone and support for this?

Basically, we should send an "integration_key" parameter for all our API requests.

@access_token = access_token
@refresh_token = refresh_token

@client_id = client_id || ConvertkitV4.configuration.client_id
@client_secret = client_secret || ConvertkitV4.configuration.client_secret
@redirect_uri = redirect_uri || ConvertkitV4.configuration.redirect_uri
end

def connection
@connection ||= Connection.new(access_token: @access_token)
end

def authorize
Faraday.new(url: AUTH_URL).get do |req|
req.headers["Content-Type"] = "application/json"
req.params = { client_id: @client_id, redirect_uri: @redirect_uri }
end
end

def get_access_token(code)
Faraday.new(url: ACCESS_TOKEN_URL).post do |req|
req.headers["Content-Type"] = "application/json"
req.params = {
client_id: @client_id,
client_secret: @client_secret,
code: code,
grant_type: "authorization_code",
redirect_uri: @redirect_uri
}
end
end

def refresh_token
Faraday.new(url: ACCESS_TOKEN_URL).post do |req|
req.headers["Content-Type"] = "application/json"
req.params = {
client_id: @client_id,
client_secret: @client_secret,
refresh_token: @refresh_token,
grant_type: "refresh_token"
}
end
end

def revoke_access
Faraday.new(url: REVOKE_ACCESS_URL).post do |req|
req.headers["Content-Type"] = "application/json"
req.params = {
client_id: @client_id,
client_secret: @client_secret,
token: @access_token
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Convertkit
module ConvertkitV4
class Client
module Account
def account
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Convertkit
module ConvertkitV4
class Client
module CustomFields

Expand Down
Loading