email_list_api 0.1.0.rc.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9f6eff66fff016c13db422fe77d7b6173a6389a4ebb48e56c6a976180fe78e9
4
+ data.tar.gz: 5eb26fa011aeb57b16a6d22dbfb422f69310c16d75a0750337c22c25771394bd
5
+ SHA512:
6
+ metadata.gz: 5d8fa655ccabbdb642b73954f6a426a26ff8f6c92c8cb9a1b4bbf4f8e391977327779aaa5b78956e6fe1dcf8b978d0094b6650b478b4df3e17599b3df13c3790
7
+ data.tar.gz: 32760843f905f7c7918fd4b358394c10e57420b6eedc4f8b98b2ef24cac062d32f2c4bb6a307f30e180d6200acfaac527628ff423c768af94d8b896e33eb466d
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # EmailListApi
2
+
3
+ A Ruby client for the Email List API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'email_list_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install email_list_api
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'email_list_api'
25
+
26
+ client = EmailListApi::Client.new(api_key: 'your_api_key')
27
+
28
+ # Projects
29
+ projects = client.projects
30
+ project = client.create_project(name: 'My Project')
31
+
32
+ # Lists
33
+ lists = client.lists(project_id: project['id'])
34
+ list = client.create_list(project_id: project['id'], name: 'Newsletter')
35
+
36
+ # Contacts
37
+ client.create_contact(project_id: project['id'], email: 'user@example.com')
38
+ ```
@@ -0,0 +1,152 @@
1
+ require 'faraday'
2
+ require 'faraday/retry'
3
+ require 'faraday/follow_redirects'
4
+ require 'json'
5
+
6
+ module EmailListApi
7
+ class Client
8
+ DEFAULT_BASE_URL = "http://localhost:3000/api/v1"
9
+
10
+ def initialize(api_key: ENV['EMAILLIST_API_KEY'], base_url: DEFAULT_BASE_URL)
11
+ @api_key = api_key
12
+ @base_url = base_url
13
+ end
14
+
15
+ # Projects
16
+ def projects
17
+ get("projects")
18
+ end
19
+
20
+ def project(id)
21
+ get("projects/#{id}")
22
+ end
23
+
24
+ def create_project(name:, description: nil)
25
+ post("projects", { project: { name: name, description: description } })
26
+ end
27
+
28
+ def update_project(id, name: nil, description: nil)
29
+ params = { project: {} }
30
+ params[:project][:name] = name if name
31
+ params[:project][:description] = description if description
32
+ patch("projects/#{id}", params)
33
+ end
34
+
35
+ def delete_project(id)
36
+ delete("projects/#{id}")
37
+ end
38
+
39
+ # Lists
40
+ def lists(project_id:)
41
+ get("projects/#{project_id}/lists")
42
+ end
43
+
44
+ def list(project_id:, id:)
45
+ get("projects/#{project_id}/lists/#{id}")
46
+ end
47
+
48
+ def create_list(project_id:, name:, description: nil)
49
+ post("projects/#{project_id}/lists", { list: { name: name, description: description } })
50
+ end
51
+
52
+ def update_list(project_id:, id:, name: nil, description: nil)
53
+ params = { list: {} }
54
+ params[:list][:name] = name if name
55
+ params[:list][:description] = description if description
56
+ patch("projects/#{project_id}/lists/#{id}", params)
57
+ end
58
+
59
+ def delete_list(project_id:, id:)
60
+ delete("projects/#{project_id}/lists/#{id}")
61
+ end
62
+
63
+ # Contacts
64
+ def contacts(project_id:, page: 1)
65
+ get("projects/#{project_id}/contacts", { page: page })
66
+ end
67
+
68
+ def contact(project_id:, id:)
69
+ get("projects/#{project_id}/contacts/#{id}")
70
+ end
71
+
72
+ def create_contact(project_id:, email:, first_name: nil, last_name: nil)
73
+ params = { contact: { email: email } }
74
+ params[:contact][:first_name] = first_name if first_name
75
+ params[:contact][:last_name] = last_name if last_name
76
+ post("projects/#{project_id}/contacts", params)
77
+ end
78
+
79
+ def update_contact(project_id:, id:, email: nil, first_name: nil, last_name: nil)
80
+ params = { contact: {} }
81
+ params[:contact][:email] = email if email
82
+ params[:contact][:first_name] = first_name if first_name
83
+ params[:contact][:last_name] = last_name if last_name
84
+ patch("projects/#{project_id}/contacts/#{id}", params)
85
+ end
86
+
87
+ def delete_contact(project_id:, id:)
88
+ delete("projects/#{project_id}/contacts/#{id}")
89
+ end
90
+
91
+ # List Memberships
92
+ def list_contacts(project_id:, list_id:)
93
+ get("projects/#{project_id}/lists/#{list_id}/contacts")
94
+ end
95
+
96
+ def add_contacts_to_list(project_id:, list_id:, contacts:)
97
+ # contacts can be an array of hashes or a single hash, but API expects array
98
+ contacts = [contacts] unless contacts.is_a?(Array)
99
+ post("projects/#{project_id}/lists/#{list_id}/contacts", { contacts: contacts })
100
+ end
101
+
102
+ def add_contact_to_list(project_id:, list_id:, contact_id:)
103
+ # Helper for adding single existing contact by ID
104
+ add_contacts_to_list(project_id: project_id, list_id: list_id, contacts: [{ id: contact_id }])
105
+ end
106
+
107
+ def remove_contact_from_list(project_id:, list_id:, contact_id:)
108
+ delete("projects/#{project_id}/lists/#{list_id}/contacts/#{contact_id}")
109
+ end
110
+
111
+ # Bulk Operations
112
+ def bulk_create_contacts(project_id:, contacts:)
113
+ post("projects/#{project_id}/contacts/bulk", { contacts: contacts })
114
+ end
115
+
116
+ private
117
+
118
+ def connection
119
+ @connection ||= Faraday.new(url: @base_url) do |conn|
120
+ conn.request :json
121
+ conn.request :retry
122
+ conn.response :json, content_type: /\bjson$/
123
+ conn.response :raise_error
124
+ conn.response :follow_redirects
125
+ conn.headers['Authorization'] = "Bearer #{@api_key}"
126
+ conn.headers['Content-Type'] = 'application/json'
127
+ conn.headers['User-Agent'] = "EmailListApi Ruby Client/#{EmailListApi::VERSION}"
128
+ conn.adapter Faraday.default_adapter
129
+ end
130
+ end
131
+
132
+ def get(path, params = {})
133
+ response = connection.get(path, params)
134
+ response.body
135
+ end
136
+
137
+ def post(path, body = {})
138
+ response = connection.post(path, body)
139
+ response.body
140
+ end
141
+
142
+ def patch(path, body = {})
143
+ response = connection.patch(path, body)
144
+ response.body
145
+ end
146
+
147
+ def delete(path)
148
+ response = connection.delete(path)
149
+ response.body
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,3 @@
1
+ module EmailListApi
2
+ VERSION = "0.1.0.rc.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "email_list_api/version"
2
+ require "email_list_api/client"
3
+
4
+ module EmailListApi
5
+ class Error < StandardError; end
6
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_list_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.rc.1
5
+ platform: ruby
6
+ authors:
7
+ - Email List Dev
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-retry
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: faraday-follow_redirects
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rake
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '13.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '3.0'
96
+ description: A simple Ruby client for managing projects, lists, and contacts via the
97
+ Email List API.
98
+ email:
99
+ - dev@emaillist.dev
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - README.md
105
+ - lib/email_list_api.rb
106
+ - lib/email_list_api/client.rb
107
+ - lib/email_list_api/version.rb
108
+ homepage: https://github.com/yourusername/emaillist-ruby
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.6.9
127
+ specification_version: 4
128
+ summary: Ruby client for Email List API
129
+ test_files: []