-
Notifications
You must be signed in to change notification settings - Fork 3
oAuth API v4 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oAuth API v4 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
|
||
| ## 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: | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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`) | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| module Convertkit | ||
| module ConvertkitV4 | ||
| class Client | ||
| module CustomFields | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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 :)