email_list_api 0.1.0.rc.4 → 0.1.0.rc.6
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 +4 -4
- data/README.md +14 -8
- data/lib/email_list_api/client.rb +42 -55
- data/lib/email_list_api/syncs_email_list_contact.rb +3 -3
- data/lib/email_list_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd556c4af0aa25954fdad4e7acc5f5c9ef077c182bacb7d395e3145f90ec73fa
|
|
4
|
+
data.tar.gz: 24dce3a08f06f15eb2341972b5cb2f01b8b07e3ae533a871cc6b82c2a6931b3a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 113f3a7bc9f3ca2c43797ef5b81578479682f0cb2f300ffd0b633c602b1730e96c270a7df5418a8a8a2035d023f5e3679795729ddd7f380343e485810d2dad46
|
|
7
|
+
data.tar.gz: 5e16ed50c5d2d9ce405f063b649a7986df62fccb0b107ac46c399cfaa6c1863c1a25d7a54c95b6cc6974c36bbfdfbf64a7083d1c142f2b645d6b15c24ccd7ad5
|
data/README.md
CHANGED
|
@@ -54,23 +54,29 @@ client = EmailListApi::Client.new(api_key: 'your_api_key', api_version: 1)
|
|
|
54
54
|
projects = client.projects
|
|
55
55
|
project = client.create_project(name: 'My Project')
|
|
56
56
|
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
# Create or update a project (idempotent)
|
|
58
|
+
project = client.upsert_project(name: 'My Project')
|
|
59
|
+
|
|
60
|
+
# Lists (project must be slug)
|
|
61
|
+
lists = client.lists(project_slug: project['data']['slug'])
|
|
62
|
+
list = client.create_list(project_slug: project['data']['slug'], name: 'Newsletter')
|
|
60
63
|
|
|
61
64
|
# Contacts
|
|
62
|
-
client.create_contact(
|
|
63
|
-
client.update_contact(
|
|
65
|
+
client.create_contact(project_slug: project['data']['slug'], email: 'user@example.com')
|
|
66
|
+
client.update_contact(project_slug: project['data']['slug'], id: contact_id, first_name: 'John')
|
|
64
67
|
# Upsert: creates if new, updates if exists (by email)
|
|
65
|
-
client.upsert_contact(
|
|
68
|
+
contact = client.upsert_contact(project_slug: project['data']['slug'], email: 'user@example.com', first_name: 'Jane')
|
|
69
|
+
# Access response data using string keys
|
|
70
|
+
contact_id = contact['data']['id']
|
|
71
|
+
email = contact['data']['email']
|
|
66
72
|
|
|
67
73
|
# Unsubscribe URLs
|
|
68
74
|
# Contact responses include unsubscribe_urls hash (list_id => unsubscribe_url)
|
|
69
|
-
contact = client.contact(
|
|
75
|
+
contact = client.contact(project_slug: project['data']['slug'], id: contact_id)
|
|
70
76
|
contact['data']['unsubscribe_urls'] # => { 1 => "https://emaillist.dev/unsubscribe/...", 2 => "..." }
|
|
71
77
|
|
|
72
78
|
# List contact responses include unsubscribe_url for that specific list
|
|
73
|
-
list_contacts = client.list_contacts(
|
|
79
|
+
list_contacts = client.list_contacts(project_slug: project['data']['slug'], list_slug: list['data']['slug'])
|
|
74
80
|
list_contacts['data'].each do |contact|
|
|
75
81
|
unsubscribe_url = contact['unsubscribe_url'] # => "https://emaillist.dev/unsubscribe/..."
|
|
76
82
|
# Include this URL in your email templates
|
|
@@ -17,21 +17,8 @@ module EmailListApi
|
|
|
17
17
|
private
|
|
18
18
|
|
|
19
19
|
def build_url_parts(base_url_override = nil)
|
|
20
|
-
# Priority: explicit parameter > config >
|
|
21
|
-
base_url = base_url_override || EmailListApi.configuration.base_url
|
|
22
|
-
|
|
23
|
-
# If still not set, try to detect environment and use appropriate default
|
|
24
|
-
if base_url.nil?
|
|
25
|
-
# Check if Rails is available and use environment-based default
|
|
26
|
-
if defined?(Rails) && Rails.env.development?
|
|
27
|
-
base_url = DEVELOPMENT_BASE_URL
|
|
28
|
-
elsif defined?(Rails) && Rails.env.test?
|
|
29
|
-
base_url = DEVELOPMENT_BASE_URL
|
|
30
|
-
else
|
|
31
|
-
# Default to production for all other cases
|
|
32
|
-
base_url = PRODUCTION_BASE_URL
|
|
33
|
-
end
|
|
34
|
-
end
|
|
20
|
+
# Priority: explicit parameter > config > production default
|
|
21
|
+
base_url = base_url_override || EmailListApi.configuration.base_url || PRODUCTION_BASE_URL
|
|
35
22
|
|
|
36
23
|
raise ArgumentError, "base_url must be configured" unless base_url
|
|
37
24
|
|
|
@@ -54,8 +41,8 @@ module EmailListApi
|
|
|
54
41
|
get("projects")
|
|
55
42
|
end
|
|
56
43
|
|
|
57
|
-
def project(
|
|
58
|
-
get("projects/#{
|
|
44
|
+
def project(slug:)
|
|
45
|
+
get("projects/#{slug}")
|
|
59
46
|
end
|
|
60
47
|
|
|
61
48
|
def create_project(name:, description: nil)
|
|
@@ -66,103 +53,103 @@ module EmailListApi
|
|
|
66
53
|
post("projects/upsert", { project: { name: name, description: description } })
|
|
67
54
|
end
|
|
68
55
|
|
|
69
|
-
def update_project(
|
|
56
|
+
def update_project(slug:, name: nil, description: nil)
|
|
70
57
|
params = { project: {} }
|
|
71
58
|
params[:project][:name] = name if name
|
|
72
59
|
params[:project][:description] = description if description
|
|
73
|
-
patch("projects/#{
|
|
60
|
+
patch("projects/#{slug}", params)
|
|
74
61
|
end
|
|
75
62
|
|
|
76
|
-
def delete_project(
|
|
77
|
-
delete("projects/#{
|
|
63
|
+
def delete_project(slug:)
|
|
64
|
+
delete("projects/#{slug}")
|
|
78
65
|
end
|
|
79
66
|
|
|
80
67
|
# Lists
|
|
81
|
-
def lists(
|
|
82
|
-
get("projects/#{
|
|
68
|
+
def lists(project_slug:)
|
|
69
|
+
get("projects/#{project_slug}/lists")
|
|
83
70
|
end
|
|
84
71
|
|
|
85
|
-
def list(
|
|
86
|
-
get("projects/#{
|
|
72
|
+
def list(project_slug:, slug:)
|
|
73
|
+
get("projects/#{project_slug}/lists/#{slug}")
|
|
87
74
|
end
|
|
88
75
|
|
|
89
|
-
def create_list(
|
|
90
|
-
post("projects/#{
|
|
76
|
+
def create_list(project_slug:, name:, description: nil)
|
|
77
|
+
post("projects/#{project_slug}/lists", { list: { name: name, description: description } })
|
|
91
78
|
end
|
|
92
79
|
|
|
93
|
-
def upsert_list(
|
|
94
|
-
post("projects/#{
|
|
80
|
+
def upsert_list(project_slug:, name:, description: nil)
|
|
81
|
+
post("projects/#{project_slug}/lists/upsert", { list: { name: name, description: description } })
|
|
95
82
|
end
|
|
96
83
|
|
|
97
|
-
def update_list(
|
|
84
|
+
def update_list(project_slug:, slug:, name: nil, description: nil)
|
|
98
85
|
params = { list: {} }
|
|
99
86
|
params[:list][:name] = name if name
|
|
100
87
|
params[:list][:description] = description if description
|
|
101
|
-
patch("projects/#{
|
|
88
|
+
patch("projects/#{project_slug}/lists/#{slug}", params)
|
|
102
89
|
end
|
|
103
90
|
|
|
104
|
-
def delete_list(
|
|
105
|
-
delete("projects/#{
|
|
91
|
+
def delete_list(project_slug:, slug:)
|
|
92
|
+
delete("projects/#{project_slug}/lists/#{slug}")
|
|
106
93
|
end
|
|
107
94
|
|
|
108
95
|
# Contacts
|
|
109
|
-
def contacts(
|
|
110
|
-
get("projects/#{
|
|
96
|
+
def contacts(project_slug:, page: 1)
|
|
97
|
+
get("projects/#{project_slug}/contacts", { page: page })
|
|
111
98
|
end
|
|
112
99
|
|
|
113
|
-
def contact(
|
|
114
|
-
get("projects/#{
|
|
100
|
+
def contact(project_slug:, id:)
|
|
101
|
+
get("projects/#{project_slug}/contacts/#{id}")
|
|
115
102
|
end
|
|
116
103
|
|
|
117
|
-
def create_contact(
|
|
104
|
+
def create_contact(project_slug:, email:, first_name: nil, last_name: nil)
|
|
118
105
|
params = { contact: { email: email } }
|
|
119
106
|
params[:contact][:first_name] = first_name if first_name
|
|
120
107
|
params[:contact][:last_name] = last_name if last_name
|
|
121
|
-
post("projects/#{
|
|
108
|
+
post("projects/#{project_slug}/contacts", params)
|
|
122
109
|
end
|
|
123
110
|
|
|
124
|
-
def update_contact(
|
|
111
|
+
def update_contact(project_slug:, id:, email: nil, first_name: nil, last_name: nil)
|
|
125
112
|
params = { contact: {} }
|
|
126
113
|
params[:contact][:email] = email if email
|
|
127
114
|
params[:contact][:first_name] = first_name if first_name
|
|
128
115
|
params[:contact][:last_name] = last_name if last_name
|
|
129
|
-
patch("projects/#{
|
|
116
|
+
patch("projects/#{project_slug}/contacts/#{id}", params)
|
|
130
117
|
end
|
|
131
118
|
|
|
132
|
-
def upsert_contact(
|
|
119
|
+
def upsert_contact(project_slug:, email:, first_name: nil, last_name: nil)
|
|
133
120
|
params = { contact: { email: email } }
|
|
134
121
|
params[:contact][:first_name] = first_name if first_name
|
|
135
122
|
params[:contact][:last_name] = last_name if last_name
|
|
136
|
-
post("projects/#{
|
|
123
|
+
post("projects/#{project_slug}/contacts/upsert", params)
|
|
137
124
|
end
|
|
138
125
|
|
|
139
|
-
def delete_contact(
|
|
140
|
-
delete("projects/#{
|
|
126
|
+
def delete_contact(project_slug:, id:)
|
|
127
|
+
delete("projects/#{project_slug}/contacts/#{id}")
|
|
141
128
|
end
|
|
142
129
|
|
|
143
130
|
# List Memberships
|
|
144
|
-
def list_contacts(
|
|
145
|
-
get("projects/#{
|
|
131
|
+
def list_contacts(project_slug:, list_slug:)
|
|
132
|
+
get("projects/#{project_slug}/lists/#{list_slug}/contacts")
|
|
146
133
|
end
|
|
147
134
|
|
|
148
|
-
def add_contacts_to_list(
|
|
135
|
+
def add_contacts_to_list(project_slug:, list_slug:, contacts:)
|
|
149
136
|
# contacts can be an array of hashes or a single hash, but API expects array
|
|
150
137
|
contacts = [ contacts ] unless contacts.is_a?(Array)
|
|
151
|
-
post("projects/#{
|
|
138
|
+
post("projects/#{project_slug}/lists/#{list_slug}/contacts", { contacts: contacts })
|
|
152
139
|
end
|
|
153
140
|
|
|
154
|
-
def add_contact_to_list(
|
|
141
|
+
def add_contact_to_list(project_slug:, list_slug:, contact_id:)
|
|
155
142
|
# Helper for adding single existing contact by ID
|
|
156
|
-
add_contacts_to_list(
|
|
143
|
+
add_contacts_to_list(project_slug: project_slug, list_slug: list_slug, contacts: [ { id: contact_id } ])
|
|
157
144
|
end
|
|
158
145
|
|
|
159
|
-
def remove_contact_from_list(
|
|
160
|
-
delete("projects/#{
|
|
146
|
+
def remove_contact_from_list(project_slug:, list_slug:, contact_id:)
|
|
147
|
+
delete("projects/#{project_slug}/lists/#{list_slug}/contacts/#{contact_id}")
|
|
161
148
|
end
|
|
162
149
|
|
|
163
150
|
# Bulk Operations
|
|
164
|
-
def bulk_create_contacts(
|
|
165
|
-
post("projects/#{
|
|
151
|
+
def bulk_create_contacts(project_slug:, contacts:)
|
|
152
|
+
post("projects/#{project_slug}/contacts/bulk", { contacts: contacts })
|
|
166
153
|
end
|
|
167
154
|
|
|
168
155
|
private
|
|
@@ -120,15 +120,15 @@ module EmailListApi
|
|
|
120
120
|
|
|
121
121
|
# Upsert contact (creates if new, updates if exists)
|
|
122
122
|
contact = emaillist_client.upsert_contact(
|
|
123
|
-
|
|
123
|
+
project_slug: project_slug,
|
|
124
124
|
email: email,
|
|
125
125
|
first_name: first_name,
|
|
126
126
|
last_name: last_name
|
|
127
127
|
)
|
|
128
128
|
|
|
129
129
|
# Optionally store the contact_id if column exists
|
|
130
|
-
if respond_to?(:emaillist_contact_id=) && contact && contact[
|
|
131
|
-
contact_id = contact[
|
|
130
|
+
if respond_to?(:emaillist_contact_id=) && contact && contact['data']
|
|
131
|
+
contact_id = contact['data']['id']
|
|
132
132
|
update_column(:emaillist_contact_id, contact_id) if persisted? && contact_id
|
|
133
133
|
end
|
|
134
134
|
rescue => e
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: email_list_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.0.rc.
|
|
4
|
+
version: 0.1.0.rc.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Email List Dev
|
|
@@ -94,12 +94,12 @@ files:
|
|
|
94
94
|
- lib/email_list_api/configuration.rb
|
|
95
95
|
- lib/email_list_api/syncs_email_list_contact.rb
|
|
96
96
|
- lib/email_list_api/version.rb
|
|
97
|
-
homepage: https://emaillist.dev
|
|
97
|
+
homepage: https://emaillist.dev
|
|
98
98
|
licenses:
|
|
99
99
|
- MIT
|
|
100
100
|
metadata:
|
|
101
101
|
allowed_push_host: https://rubygems.org
|
|
102
|
-
homepage_uri: https://emaillist.dev
|
|
102
|
+
homepage_uri: https://emaillist.dev
|
|
103
103
|
rdoc_options: []
|
|
104
104
|
require_paths:
|
|
105
105
|
- lib
|