email_list_api 0.1.0.rc.5 → 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: '08d9df5fadd2f1405fa5e2110df8f0561b0570786b2fbef07b782d8e952a2dd1'
4
- data.tar.gz: ef4bdcc6ee092491bec523aba397a13e937e6615111c8efa356b557a9adcaa4d
3
+ metadata.gz: fd556c4af0aa25954fdad4e7acc5f5c9ef077c182bacb7d395e3145f90ec73fa
4
+ data.tar.gz: 24dce3a08f06f15eb2341972b5cb2f01b8b07e3ae533a871cc6b82c2a6931b3a
5
5
  SHA512:
6
- metadata.gz: 4823d66f90179d20ac9a786db1e6593a13946b1d5b29fd192f6a7e6d0b7c7f5db8c7927a3ff9a95e628a33166507f62025c3102754728a39c501fc61feeca8a3
7
- data.tar.gz: f454d2dd7e988647e6251239e29da723f6441f08d3f60ca6d6b768f42b8b053b4c636bf5d650c5b548a7904239901381b1e3f1ccba4ed52cf9ef137e4cc1e144
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
@@ -41,8 +41,8 @@ module EmailListApi
41
41
  get("projects")
42
42
  end
43
43
 
44
- def project(id)
45
- get("projects/#{id}")
44
+ def project(slug:)
45
+ get("projects/#{slug}")
46
46
  end
47
47
 
48
48
  def create_project(name:, description: nil)
@@ -53,103 +53,103 @@ module EmailListApi
53
53
  post("projects/upsert", { project: { name: name, description: description } })
54
54
  end
55
55
 
56
- def update_project(id, name: nil, description: nil)
56
+ def update_project(slug:, name: nil, description: nil)
57
57
  params = { project: {} }
58
58
  params[:project][:name] = name if name
59
59
  params[:project][:description] = description if description
60
- patch("projects/#{id}", params)
60
+ patch("projects/#{slug}", params)
61
61
  end
62
62
 
63
- def delete_project(id)
64
- delete("projects/#{id}")
63
+ def delete_project(slug:)
64
+ delete("projects/#{slug}")
65
65
  end
66
66
 
67
67
  # Lists
68
- def lists(project:)
69
- get("projects/#{project}/lists")
68
+ def lists(project_slug:)
69
+ get("projects/#{project_slug}/lists")
70
70
  end
71
71
 
72
- def list(project:, slug:)
73
- get("projects/#{project}/lists/#{slug}")
72
+ def list(project_slug:, slug:)
73
+ get("projects/#{project_slug}/lists/#{slug}")
74
74
  end
75
75
 
76
- def create_list(project:, name:, description: nil)
77
- 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 } })
78
78
  end
79
79
 
80
- def upsert_list(project:, name:, description: nil)
81
- 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 } })
82
82
  end
83
83
 
84
- def update_list(project:, slug:, name: nil, description: nil)
84
+ def update_list(project_slug:, slug:, name: nil, description: nil)
85
85
  params = { list: {} }
86
86
  params[:list][:name] = name if name
87
87
  params[:list][:description] = description if description
88
- patch("projects/#{project}/lists/#{slug}", params)
88
+ patch("projects/#{project_slug}/lists/#{slug}", params)
89
89
  end
90
90
 
91
- def delete_list(project:, slug:)
92
- delete("projects/#{project}/lists/#{slug}")
91
+ def delete_list(project_slug:, slug:)
92
+ delete("projects/#{project_slug}/lists/#{slug}")
93
93
  end
94
94
 
95
95
  # Contacts
96
- def contacts(project:, page: 1)
97
- get("projects/#{project}/contacts", { page: page })
96
+ def contacts(project_slug:, page: 1)
97
+ get("projects/#{project_slug}/contacts", { page: page })
98
98
  end
99
99
 
100
- def contact(project:, id:)
101
- get("projects/#{project}/contacts/#{id}")
100
+ def contact(project_slug:, id:)
101
+ get("projects/#{project_slug}/contacts/#{id}")
102
102
  end
103
103
 
104
- def create_contact(project:, email:, first_name: nil, last_name: nil)
104
+ def create_contact(project_slug:, email:, first_name: nil, last_name: nil)
105
105
  params = { contact: { email: email } }
106
106
  params[:contact][:first_name] = first_name if first_name
107
107
  params[:contact][:last_name] = last_name if last_name
108
- post("projects/#{project}/contacts", params)
108
+ post("projects/#{project_slug}/contacts", params)
109
109
  end
110
110
 
111
- 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)
112
112
  params = { contact: {} }
113
113
  params[:contact][:email] = email if email
114
114
  params[:contact][:first_name] = first_name if first_name
115
115
  params[:contact][:last_name] = last_name if last_name
116
- patch("projects/#{project}/contacts/#{id}", params)
116
+ patch("projects/#{project_slug}/contacts/#{id}", params)
117
117
  end
118
118
 
119
- def upsert_contact(project:, email:, first_name: nil, last_name: nil)
119
+ def upsert_contact(project_slug:, email:, first_name: nil, last_name: nil)
120
120
  params = { contact: { email: email } }
121
121
  params[:contact][:first_name] = first_name if first_name
122
122
  params[:contact][:last_name] = last_name if last_name
123
- post("projects/#{project}/contacts/upsert", params)
123
+ post("projects/#{project_slug}/contacts/upsert", params)
124
124
  end
125
125
 
126
- def delete_contact(project:, id:)
127
- delete("projects/#{project}/contacts/#{id}")
126
+ def delete_contact(project_slug:, id:)
127
+ delete("projects/#{project_slug}/contacts/#{id}")
128
128
  end
129
129
 
130
130
  # List Memberships
131
- def list_contacts(project:, list_slug:)
132
- get("projects/#{project}/lists/#{list_slug}/contacts")
131
+ def list_contacts(project_slug:, list_slug:)
132
+ get("projects/#{project_slug}/lists/#{list_slug}/contacts")
133
133
  end
134
134
 
135
- def add_contacts_to_list(project:, list_slug:, contacts:)
135
+ def add_contacts_to_list(project_slug:, list_slug:, contacts:)
136
136
  # contacts can be an array of hashes or a single hash, but API expects array
137
137
  contacts = [ contacts ] unless contacts.is_a?(Array)
138
- post("projects/#{project}/lists/#{list_slug}/contacts", { contacts: contacts })
138
+ post("projects/#{project_slug}/lists/#{list_slug}/contacts", { contacts: contacts })
139
139
  end
140
140
 
141
- def add_contact_to_list(project:, list_slug:, contact_id:)
141
+ def add_contact_to_list(project_slug:, list_slug:, contact_id:)
142
142
  # Helper for adding single existing contact by ID
143
- 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 } ])
144
144
  end
145
145
 
146
- def remove_contact_from_list(project:, list_slug:, contact_id:)
147
- 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}")
148
148
  end
149
149
 
150
150
  # Bulk Operations
151
- def bulk_create_contacts(project:, contacts:)
152
- post("projects/#{project}/contacts/bulk", { contacts: contacts })
151
+ def bulk_create_contacts(project_slug:, contacts:)
152
+ post("projects/#{project_slug}/contacts/bulk", { contacts: contacts })
153
153
  end
154
154
 
155
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.5"
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.5
4
+ version: 0.1.0.rc.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Email List Dev