forked from maximadeka/convertkit-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add .env.local.sample file which can be copied to get a working .env.local which is needed for testing purposes - pull out some of the hard coded values in the tests into those env variables - accept api_key and api_secret in client initialization - default api_key and api_secret to nil so that when making a request the string 'api_key' and 'api_secret' aren't sent to convertkit (this is a problem when you dont need/want to specify api_secret, and that string is sent along anyway) - there was some mixing of tabs and spaces, i think i caught them all and made them spaces - bump to 0.0.2 - removed the need to make 2 requests per test (use same response to check success and body)
- Loading branch information
Showing
12 changed files
with
133 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# copy this file to .env.local and substitute real values from | ||
# your own convertkit account | ||
|
||
API_SECRET='ABC' | ||
API_KEY='DEF' | ||
|
||
# a subscriber to retrieve | ||
SUBSCRIBER_ID='GHI' | ||
|
||
# a tag to retrieve and add a subscriber to | ||
TAG_ID='JKL' | ||
|
||
# a sequence to retrieve and add a subscriber to | ||
SEQUENCE_ID='MNO' | ||
# tags to add to a new subscriber when adding to a sequence | ||
TAGS='PQR,STU' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
module Convertkit | ||
class Client | ||
module Sequences | ||
def sequences | ||
connection.get("sequences") | ||
end | ||
module Sequences | ||
def sequences | ||
connection.get("sequences") | ||
end | ||
|
||
def add_subscriber_to_sequence(sequence_id, email, options = {}) | ||
connection.post("sequences/#{sequence_id}/subscribe?email=#{email}") do |f| | ||
f.params['first_name'] = options[:first_name] | ||
f.params['fields'] = options[:fields] | ||
f.params['tags'] = options[:tags] | ||
end | ||
end | ||
end | ||
def add_subscriber_to_sequence(sequence_id, email, options = {}) | ||
connection.post("sequences/#{sequence_id}/subscribe") do |f| | ||
f.params['email'] = email | ||
f.params['first_name'] = options[:first_name] | ||
f.params['fields'] = options[:fields] | ||
f.params['tags'] = options[:tags] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Convertkit | ||
class Client | ||
module Tags | ||
def tags | ||
connection.get("tags") | ||
end | ||
|
||
def add_subscriber_to_tag(tag_id, email, options = {}) | ||
connection.post("tags/#{tag_id}/subscribe") do |f| | ||
f.params['email'] = email | ||
f.params['first_name'] = options[:first_name] | ||
f.params['fields'] = options[:fields] | ||
f.params['tags'] = options[:tags] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
module Convertkit | ||
class Configuration | ||
attr_accessor :api_secret, :api_key | ||
|
||
def initialize | ||
@api_secret = "api_secret" | ||
@api_key = "api_key" | ||
@api_secret = nil | ||
@api_key = nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Convertkit | ||
VERSION = "0.0.1" | ||
end | ||
VERSION = "0.0.2" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
require "spec_helper" | ||
|
||
module Convertkit | ||
class Client | ||
describe Sequences do | ||
before do | ||
Convertkit.configure do |config| | ||
config.api_secret = ENV["API_SECRET"] | ||
config.api_key = ENV["API_KEY"] | ||
class Client | ||
describe Sequences do | ||
before do | ||
Convertkit.configure do |config| | ||
config.api_secret = ENV["API_SECRET"] | ||
config.api_key = ENV["API_KEY"] | ||
end | ||
|
||
@client = Convertkit::Client.new | ||
end | ||
|
||
describe "#sequences" do | ||
it "sends the right request" do | ||
expect(@client.sequences.success?).to be_truthy | ||
|
||
expect(@client.sequences.body).to_not eql({"error"=>"Authorization Failed","message"=>"API Key not present"}) | ||
end | ||
it "sends the right request" do | ||
r = @client.sequences | ||
expect(r.success?).to be_truthy | ||
expect(r.body).to_not eql({"error"=>"Authorization Failed","message"=>"API Key not present"}) | ||
end | ||
end | ||
|
||
describe "#add_subscriber_to_sequence" do | ||
it "sends the right request" do | ||
sequence_id = "15402" | ||
email = "[email protected]" | ||
it "sends the right request" do | ||
sequence_id = ENV['SEQUENCE_ID'] | ||
email = "crt-sequences+#{Time.now.to_i}@example.com" | ||
tags = ENV['TAGS'] | ||
|
||
expect(@client.add_subscriber_to_sequence(sequence_id, email,first_name: "Raymond Cudjoe", tags: "26471,45372")).to be_truthy | ||
|
||
expect(@client.add_subscriber_to_sequence(sequence_id, email).body).to_not eql({"error"=>"Missing parameter","message"=>"Subscriber email is required"}) | ||
end | ||
r = @client.add_subscriber_to_sequence(sequence_id, email, tags: tags) | ||
expect(r.success?).to be_truthy | ||
expect(r.body).to_not eql({"error"=>"Missing parameter","message"=>"Subscriber email is required"}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "spec_helper" | ||
|
||
module Convertkit | ||
class Client | ||
describe Tags do | ||
before do | ||
Convertkit.configure do |config| | ||
config.api_secret = ENV["API_SECRET"] | ||
config.api_key = ENV["API_KEY"] | ||
end | ||
|
||
@client = Convertkit::Client.new | ||
end | ||
|
||
describe "#tags" do | ||
it "sends the right request" do | ||
r = @client.tags | ||
expect(r.success?).to be_truthy | ||
expect(r.body).to_not eql({"error"=>"Authorization Failed","message"=>"API Key not present"}) | ||
end | ||
end | ||
|
||
describe "#add_subscriber_to_tag" do | ||
it "sends the right request" do | ||
tag_id = ENV['TAG_ID'] | ||
email = "crt-tags+#{Time.now.to_i}@example.com" | ||
|
||
r = @client.add_subscriber_to_tag(tag_id, email) | ||
expect(r.success?).to be_truthy | ||
expect(r.body).to_not eql({"error"=>"Missing parameter","message"=>"Subscriber email is required"}) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
require 'convertkit' | ||
require "dotenv" | ||
Dotenv.load(".env.local") | ||
Dotenv.load(".env.local") |