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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40ee3e78d98766e82df1c5f66b68d07de97296e9204ad7c121b996b1a8c8720f
4
- data.tar.gz: 8269b928eb9d98df12771bada12b33d351c9db2f92e11716a298143c1b757946
3
+ metadata.gz: fd556c4af0aa25954fdad4e7acc5f5c9ef077c182bacb7d395e3145f90ec73fa
4
+ data.tar.gz: 24dce3a08f06f15eb2341972b5cb2f01b8b07e3ae533a871cc6b82c2a6931b3a
5
5
  SHA512:
6
- metadata.gz: 70e6101f5777e6b8339dff5b16be8c5b746a1ac078a28dcfe57478f3a24d9fbed28b52803157e70df32a2fdf865937c0e7136875218d50ff7134a4b616d4230e
7
- data.tar.gz: 1c6b432fcb1fa03f464860cf2b176d3538e8f3909da35e22c9b2002ad9d912df395b236b7ba0fbdc1667921c3d0a7229e84b0548bb1748a6eb9073998d33172a
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
- # Lists (project can be slug or ID)
58
- lists = client.lists(project: project['data']['slug'])
59
- list = client.create_list(project: project['data']['slug'], name: 'Newsletter')
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(project: project['data']['slug'], email: 'user@example.com')
63
- client.update_contact(project: project['data']['slug'], id: contact_id, first_name: 'John')
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(project: project['data']['slug'], email: 'user@example.com', first_name: 'Jane')
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(project: project['data']['slug'], id: contact_id)
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(project: project['data']['slug'], list_id: list_id)
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 > environment detection > production default
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(id)
58
- get("projects/#{id}")
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(id, name: nil, description: nil)
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/#{id}", params)
60
+ patch("projects/#{slug}", params)
74
61
  end
75
62
 
76
- def delete_project(id)
77
- delete("projects/#{id}")
63
+ def delete_project(slug:)
64
+ delete("projects/#{slug}")
78
65
  end
79
66
 
80
67
  # Lists
81
- def lists(project:)
82
- get("projects/#{project}/lists")
68
+ def lists(project_slug:)
69
+ get("projects/#{project_slug}/lists")
83
70
  end
84
71
 
85
- def list(project:, slug:)
86
- get("projects/#{project}/lists/#{slug}")
72
+ def list(project_slug:, slug:)
73
+ get("projects/#{project_slug}/lists/#{slug}")
87
74
  end
88
75
 
89
- def create_list(project:, name:, description: nil)
90
- post("projects/#{project}/lists", { list: { name: name, description: description } })
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(project:, name:, description: nil)
94
- post("projects/#{project}/lists/upsert", { list: { name: name, description: description } })
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(project:, slug:, name: nil, description: nil)
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/#{project}/lists/#{slug}", params)
88
+ patch("projects/#{project_slug}/lists/#{slug}", params)
102
89
  end
103
90
 
104
- def delete_list(project:, slug:)
105
- delete("projects/#{project}/lists/#{slug}")
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(project:, page: 1)
110
- get("projects/#{project}/contacts", { page: page })
96
+ def contacts(project_slug:, page: 1)
97
+ get("projects/#{project_slug}/contacts", { page: page })
111
98
  end
112
99
 
113
- def contact(project:, id:)
114
- get("projects/#{project}/contacts/#{id}")
100
+ def contact(project_slug:, id:)
101
+ get("projects/#{project_slug}/contacts/#{id}")
115
102
  end
116
103
 
117
- def create_contact(project:, email:, first_name: nil, last_name: nil)
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/#{project}/contacts", params)
108
+ post("projects/#{project_slug}/contacts", params)
122
109
  end
123
110
 
124
- def update_contact(project:, id:, email: nil, first_name: nil, last_name: nil)
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/#{project}/contacts/#{id}", params)
116
+ patch("projects/#{project_slug}/contacts/#{id}", params)
130
117
  end
131
118
 
132
- def upsert_contact(project:, email:, first_name: nil, last_name: nil)
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/#{project}/contacts/upsert", params)
123
+ post("projects/#{project_slug}/contacts/upsert", params)
137
124
  end
138
125
 
139
- def delete_contact(project:, id:)
140
- delete("projects/#{project}/contacts/#{id}")
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(project:, list_slug:)
145
- get("projects/#{project}/lists/#{list_slug}/contacts")
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(project:, list_slug:, contacts:)
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/#{project}/lists/#{list_slug}/contacts", { contacts: contacts })
138
+ post("projects/#{project_slug}/lists/#{list_slug}/contacts", { contacts: contacts })
152
139
  end
153
140
 
154
- def add_contact_to_list(project:, list_slug:, contact_id:)
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(project: project, list_slug: list_slug, contacts: [ { id: contact_id } ])
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(project:, list_slug:, contact_id:)
160
- delete("projects/#{project}/lists/#{list_slug}/contacts/#{contact_id}")
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(project:, contacts:)
165
- post("projects/#{project}/contacts/bulk", { contacts: contacts })
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
- project: project_slug,
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[:data]
131
- contact_id = contact[:data][:id]
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
@@ -1,3 +1,3 @@
1
1
  module EmailListApi
2
- VERSION = "0.1.0.rc.4"
2
+ VERSION = "0.1.0.rc.6"
3
3
  end
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
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/docs
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/docs
102
+ homepage_uri: https://emaillist.dev
103
103
  rdoc_options: []
104
104
  require_paths:
105
105
  - lib