mailshake-ruby 0.1.0
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 +7 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE.txt +21 -0
- data/README.md +151 -0
- data/lib/mailshake/activity.rb +81 -0
- data/lib/mailshake/base.rb +39 -0
- data/lib/mailshake/campaigns.rb +33 -0
- data/lib/mailshake/client.rb +90 -0
- data/lib/mailshake/configuration.rb +22 -0
- data/lib/mailshake/errors.rb +51 -0
- data/lib/mailshake/leads.rb +61 -0
- data/lib/mailshake/push.rb +13 -0
- data/lib/mailshake/recipients.rb +50 -0
- data/lib/mailshake/senders.rb +9 -0
- data/lib/mailshake/team.rb +9 -0
- data/lib/mailshake/version.rb +5 -0
- data/lib/mailshake.rb +37 -0
- data/spec/examples.txt +60 -0
- data/spec/mailshake/activity_spec.rb +95 -0
- data/spec/mailshake/campaigns_spec.rb +98 -0
- data/spec/mailshake/client_spec.rb +132 -0
- data/spec/mailshake/configuration_spec.rb +49 -0
- data/spec/mailshake/leads_spec.rb +85 -0
- data/spec/mailshake/push_spec.rb +40 -0
- data/spec/mailshake/recipients_spec.rb +98 -0
- data/spec/mailshake/senders_spec.rb +28 -0
- data/spec/mailshake/team_spec.rb +28 -0
- data/spec/spec_helper.rb +41 -0
- metadata +173 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dac51d36d81055f0ee4b47e3e0cbebef824b7b7b88168d2327869d8fa9ec6b8b
|
|
4
|
+
data.tar.gz: e595b5f7e002badc7ab1f1035fcd95500e27686f074aba1cbbc6a72801cb9bad
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d98021363059d25659da7be92cd6e69fe0219e029b661f709fc8dc0a73a20d0412374c66bfa75b348a07c06070f0acf55d18e8bcbd5a7c5586e33c6b0b39650f
|
|
7
|
+
data.tar.gz: e2d4bc194b916370ba0c0e059ecd06e74052eb662265e13ed1d8f5bce58862c14d8cbf28c7515fec5f20eb5f7c53075557c6a0d3a4df9bae08317c1693bdc4fb
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-04-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- Campaigns API (list, get, create, pause, unpause, export, export_status)
|
|
8
|
+
- Recipients API (add, add_status, list, get, pause, unpause, unsubscribe)
|
|
9
|
+
- Activity API (sent, opens, clicks, replies, created_leads, lead_assignments, lead_status_changes)
|
|
10
|
+
- Leads API (list, get, create, close, ignore, reopen)
|
|
11
|
+
- Team API (list_members)
|
|
12
|
+
- Senders API (list)
|
|
13
|
+
- Push/Webhooks API (create, delete)
|
|
14
|
+
- Me endpoint
|
|
15
|
+
- API key authentication via Basic Auth
|
|
16
|
+
- Automatic snake_case to camelCase parameter conversion
|
|
17
|
+
- Comprehensive RSpec test suite
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eduardo Souza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Mailshake Ruby
|
|
2
|
+
|
|
3
|
+
Ruby gem for the [Mailshake](https://mailshake.com) email outreach API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'mailshake-ruby'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then run:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install directly:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
gem install mailshake-ruby
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
Mailshake.configure do |config|
|
|
29
|
+
config.api_key = ENV['MAILSHAKE_API_KEY']
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Campaigns
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
campaigns = Mailshake::Campaigns.new
|
|
39
|
+
|
|
40
|
+
campaigns.list(search: "onboarding", per_page: 10)
|
|
41
|
+
campaigns.get(campaign_id: 1)
|
|
42
|
+
campaigns.create(title: "Q2 Outreach", sender_id: 5)
|
|
43
|
+
campaigns.pause(campaign_id: 1)
|
|
44
|
+
campaigns.unpause(campaign_id: 1)
|
|
45
|
+
campaigns.export(campaign_ids: [1, 2], export_type: "csv", timezone: "US/Pacific")
|
|
46
|
+
campaigns.export_status(status_id: 42)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Recipients
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
recipients = Mailshake::Recipients.new
|
|
53
|
+
|
|
54
|
+
recipients.add(campaign_id: 1, addresses: [{ emailAddress: "john@example.com" }])
|
|
55
|
+
recipients.add_status(status_id: 42)
|
|
56
|
+
recipients.list(campaign_id: 1, filter: "active", per_page: 25)
|
|
57
|
+
recipients.get(recipient_id: 100)
|
|
58
|
+
recipients.pause(campaign_id: 1, email_address: "john@example.com")
|
|
59
|
+
recipients.unpause(campaign_id: 1, email_address: "john@example.com")
|
|
60
|
+
recipients.unsubscribe(email_addresses: ["john@example.com"])
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Activity
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
activity = Mailshake::Activity.new
|
|
67
|
+
|
|
68
|
+
activity.sent(campaign_id: 1, per_page: 50)
|
|
69
|
+
activity.opens(campaign_id: 1, exclude_duplicates: true)
|
|
70
|
+
activity.clicks(campaign_id: 1, match_url: "https://example.com")
|
|
71
|
+
activity.replies(campaign_id: 1, reply_type: "reply")
|
|
72
|
+
activity.created_leads(campaign_id: 1, since: "2026-01-01")
|
|
73
|
+
activity.lead_assignments(campaign_id: 1)
|
|
74
|
+
activity.lead_status_changes(campaign_id: 1)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Leads
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
leads = Mailshake::Leads.new
|
|
81
|
+
|
|
82
|
+
leads.list(campaign_id: 1, status: "open")
|
|
83
|
+
leads.get(lead_id: 42)
|
|
84
|
+
leads.create(campaign_id: 1, email_addresses: ["john@example.com"])
|
|
85
|
+
leads.close(lead_id: 42, status: "won")
|
|
86
|
+
leads.ignore(lead_id: 42)
|
|
87
|
+
leads.reopen(lead_id: 42)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Team
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
team = Mailshake::Team.new
|
|
94
|
+
|
|
95
|
+
team.list_members(search: "john", per_page: 10)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Senders
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
senders = Mailshake::Senders.new
|
|
102
|
+
|
|
103
|
+
senders.list(search: "sales", per_page: 10)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Push/Webhooks
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
push = Mailshake::Push.new
|
|
110
|
+
|
|
111
|
+
push.create(target_url: "https://example.com/webhook", event: "reply")
|
|
112
|
+
push.delete(target_url: "https://example.com/webhook")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Me
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
client = Mailshake.client
|
|
119
|
+
client.me
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Pagination
|
|
123
|
+
|
|
124
|
+
Endpoints that return lists support pagination via `next_token` and `per_page`:
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
result = campaigns.list(per_page: 10)
|
|
128
|
+
next_page = campaigns.list(per_page: 10, next_token: result["nextToken"])
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Error Handling
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
begin
|
|
135
|
+
campaigns.get(campaign_id: 999)
|
|
136
|
+
rescue Mailshake::AuthenticationError => e
|
|
137
|
+
puts "Bad API key"
|
|
138
|
+
rescue Mailshake::NotFoundError => e
|
|
139
|
+
puts "Not found: #{e.message}"
|
|
140
|
+
rescue Mailshake::RateLimitError => e
|
|
141
|
+
puts "Rate limited, retry after: #{e.retry_after}"
|
|
142
|
+
rescue Mailshake::ValidationError => e
|
|
143
|
+
puts "Validation errors: #{e.errors}"
|
|
144
|
+
rescue Mailshake::APIError => e
|
|
145
|
+
puts "API error #{e.status_code}: #{e.message}"
|
|
146
|
+
end
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT License. See [LICENSE.txt](LICENSE.txt).
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Activity < Base
|
|
5
|
+
def sent(message_type: nil, campaign_message_type: nil, campaign_id: nil, recipient_email_address: nil, exclude_body: nil, next_token: nil, per_page: nil)
|
|
6
|
+
client.get("/activity/sent", camelize_params(
|
|
7
|
+
message_type: message_type,
|
|
8
|
+
campaign_message_type: campaign_message_type,
|
|
9
|
+
campaign_id: campaign_id,
|
|
10
|
+
recipient_email_address: recipient_email_address,
|
|
11
|
+
exclude_body: exclude_body,
|
|
12
|
+
next_token: next_token,
|
|
13
|
+
per_page: per_page
|
|
14
|
+
))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def opens(campaign_id: nil, exclude_duplicates: nil, recipient_email_address: nil, next_token: nil, per_page: nil, since: nil)
|
|
18
|
+
client.get("/activity/opens", camelize_params(
|
|
19
|
+
campaign_id: campaign_id,
|
|
20
|
+
exclude_duplicates: exclude_duplicates,
|
|
21
|
+
recipient_email_address: recipient_email_address,
|
|
22
|
+
next_token: next_token,
|
|
23
|
+
per_page: per_page,
|
|
24
|
+
since: since
|
|
25
|
+
))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def clicks(campaign_id: nil, exclude_duplicates: nil, match_url: nil, recipient_email_address: nil, next_token: nil, per_page: nil, since: nil)
|
|
29
|
+
client.get("/activity/clicks", camelize_params(
|
|
30
|
+
campaign_id: campaign_id,
|
|
31
|
+
exclude_duplicates: exclude_duplicates,
|
|
32
|
+
match_url: match_url,
|
|
33
|
+
recipient_email_address: recipient_email_address,
|
|
34
|
+
next_token: next_token,
|
|
35
|
+
per_page: per_page,
|
|
36
|
+
since: since
|
|
37
|
+
))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def replies(reply_type: nil, campaign_id: nil, recipient_email_address: nil, next_token: nil, per_page: nil)
|
|
41
|
+
client.get("/activity/replies", camelize_params(
|
|
42
|
+
reply_type: reply_type,
|
|
43
|
+
campaign_id: campaign_id,
|
|
44
|
+
recipient_email_address: recipient_email_address,
|
|
45
|
+
next_token: next_token,
|
|
46
|
+
per_page: per_page
|
|
47
|
+
))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def created_leads(campaign_id: nil, recipient_email_address: nil, assigned_to_email_address: nil, next_token: nil, per_page: nil, since: nil)
|
|
51
|
+
client.get("/activity/created-leads", camelize_params(
|
|
52
|
+
campaign_id: campaign_id,
|
|
53
|
+
recipient_email_address: recipient_email_address,
|
|
54
|
+
assigned_to_email_address: assigned_to_email_address,
|
|
55
|
+
next_token: next_token,
|
|
56
|
+
per_page: per_page,
|
|
57
|
+
since: since
|
|
58
|
+
))
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def lead_assignments(campaign_id: nil, next_token: nil, per_page: nil, since: nil)
|
|
62
|
+
client.get("/activity/lead-assignments", camelize_params(
|
|
63
|
+
campaign_id: campaign_id,
|
|
64
|
+
next_token: next_token,
|
|
65
|
+
per_page: per_page,
|
|
66
|
+
since: since
|
|
67
|
+
))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def lead_status_changes(campaign_id: nil, recipient_email_address: nil, assigned_to_email_address: nil, next_token: nil, per_page: nil, since: nil)
|
|
71
|
+
client.get("/activity/lead-status-changes", camelize_params(
|
|
72
|
+
campaign_id: campaign_id,
|
|
73
|
+
recipient_email_address: recipient_email_address,
|
|
74
|
+
assigned_to_email_address: assigned_to_email_address,
|
|
75
|
+
next_token: next_token,
|
|
76
|
+
per_page: per_page,
|
|
77
|
+
since: since
|
|
78
|
+
))
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Base
|
|
5
|
+
attr_reader :client
|
|
6
|
+
|
|
7
|
+
UPPERCASE_SUFFIXES = {
|
|
8
|
+
"id" => "ID",
|
|
9
|
+
"ids" => "IDs"
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
def initialize(client = nil)
|
|
13
|
+
@client = client || Mailshake.client
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def camelize(key)
|
|
19
|
+
parts = key.to_s.split('_')
|
|
20
|
+
return parts[0] if parts.length == 1
|
|
21
|
+
|
|
22
|
+
result = parts[0].dup
|
|
23
|
+
parts[1..].each do |part|
|
|
24
|
+
if UPPERCASE_SUFFIXES[part]
|
|
25
|
+
result << UPPERCASE_SUFFIXES[part]
|
|
26
|
+
else
|
|
27
|
+
result << part.capitalize
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
result
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def camelize_params(params)
|
|
34
|
+
params.each_with_object({}) do |(key, value), hash|
|
|
35
|
+
hash[camelize(key)] = value unless value.nil?
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Campaigns < Base
|
|
5
|
+
def list(search: nil, next_token: nil, per_page: nil)
|
|
6
|
+
client.get("/campaigns/list", camelize_params(search: search, next_token: next_token, per_page: per_page))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def get(campaign_id:)
|
|
10
|
+
client.get("/campaigns/get", camelize_params(campaign_id: campaign_id))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create(title:, sender_id: nil)
|
|
14
|
+
client.post("/campaigns/create", camelize_params(title: title, sender_id: sender_id))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def pause(campaign_id:)
|
|
18
|
+
client.post("/campaigns/pause", camelize_params(campaign_id: campaign_id))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def unpause(campaign_id:)
|
|
22
|
+
client.post("/campaigns/unpause", camelize_params(campaign_id: campaign_id))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def export(campaign_ids: nil, export_type: nil, timezone: nil)
|
|
26
|
+
client.post("/campaigns/export", camelize_params(campaign_ids: campaign_ids, export_type: export_type, timezone: timezone))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def export_status(status_id:)
|
|
30
|
+
client.get("/campaigns/export-status", camelize_params(status_id: status_id))
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
|
|
5
|
+
module Mailshake
|
|
6
|
+
class Client
|
|
7
|
+
include HTTParty
|
|
8
|
+
|
|
9
|
+
attr_reader :configuration
|
|
10
|
+
|
|
11
|
+
def initialize(configuration)
|
|
12
|
+
@configuration = configuration
|
|
13
|
+
validate_configuration!
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(path, params = {})
|
|
17
|
+
request(:get, path, query: params)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def post(path, data = {})
|
|
21
|
+
request(:post, path, body: data.to_json)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def me
|
|
25
|
+
get("/me")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def validate_configuration!
|
|
31
|
+
missing = configuration.missing_credentials
|
|
32
|
+
raise ConfigurationError, missing unless missing.empty?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def request(method, path, options = {})
|
|
36
|
+
url = "#{configuration.base_url}#{path}"
|
|
37
|
+
request_options = {
|
|
38
|
+
headers: auth_headers,
|
|
39
|
+
timeout: configuration.timeout
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if options[:query]
|
|
43
|
+
request_options[:query] = options[:query]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if options[:body]
|
|
47
|
+
request_options[:body] = options[:body]
|
|
48
|
+
request_options[:headers] = request_options[:headers].merge('Content-Type' => 'application/json')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
response = self.class.send(method, url, request_options)
|
|
52
|
+
handle_response(response)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def auth_headers
|
|
56
|
+
credentials = Base64.strict_encode64("#{configuration.api_key}:")
|
|
57
|
+
{
|
|
58
|
+
'Authorization' => "Basic #{credentials}",
|
|
59
|
+
'Accept' => 'application/json'
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def handle_response(response)
|
|
64
|
+
case response.code
|
|
65
|
+
when 200, 201, 202, 204
|
|
66
|
+
response.parsed_response
|
|
67
|
+
when 401
|
|
68
|
+
raise AuthenticationError, "Authentication failed: #{response.body}"
|
|
69
|
+
when 404
|
|
70
|
+
raise NotFoundError.new("Resource not found", response.code, response.body)
|
|
71
|
+
when 429
|
|
72
|
+
retry_after = response.headers['retry-after']
|
|
73
|
+
raise RateLimitError.new("Rate limit exceeded", response.code, response.body, retry_after)
|
|
74
|
+
when 400, 422
|
|
75
|
+
parsed = response.parsed_response || {}
|
|
76
|
+
errors = parsed['errors'] || {}
|
|
77
|
+
raise ValidationError.new(
|
|
78
|
+
parsed['message'] || 'Validation failed',
|
|
79
|
+
response.code,
|
|
80
|
+
response.body,
|
|
81
|
+
errors
|
|
82
|
+
)
|
|
83
|
+
when 500..599
|
|
84
|
+
raise APIError.new("Server error", response.code, response.body)
|
|
85
|
+
else
|
|
86
|
+
raise APIError.new("Unexpected response", response.code, response.body)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :api_key, :base_url, :timeout
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@base_url = "https://api.mailshake.com/2017-04-01"
|
|
9
|
+
@timeout = 30
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def valid?
|
|
13
|
+
!api_key.nil? && !api_key.empty?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def missing_credentials
|
|
17
|
+
missing = []
|
|
18
|
+
missing << "api_key" if api_key.nil? || api_key.to_s.empty?
|
|
19
|
+
missing
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class ConfigurationError < Error
|
|
7
|
+
def initialize(missing_credentials)
|
|
8
|
+
super("Missing required credentials: #{missing_credentials.join(', ')}")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class AuthenticationError < Error
|
|
13
|
+
def initialize(message = "Authentication failed")
|
|
14
|
+
super(message)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class APIError < Error
|
|
19
|
+
attr_reader :status_code, :response_body
|
|
20
|
+
|
|
21
|
+
def initialize(message, status_code = nil, response_body = nil)
|
|
22
|
+
super(message)
|
|
23
|
+
@status_code = status_code
|
|
24
|
+
@response_body = response_body
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class ValidationError < APIError
|
|
29
|
+
attr_reader :errors
|
|
30
|
+
|
|
31
|
+
def initialize(message, status_code = nil, response_body = nil, errors = {})
|
|
32
|
+
super(message, status_code, response_body)
|
|
33
|
+
@errors = errors
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class NotFoundError < APIError
|
|
38
|
+
def initialize(message = "Resource not found", status_code = 404, response_body = nil)
|
|
39
|
+
super(message, status_code, response_body)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class RateLimitError < APIError
|
|
44
|
+
attr_reader :retry_after
|
|
45
|
+
|
|
46
|
+
def initialize(message = "Rate limit exceeded", status_code = 429, response_body = nil, retry_after = nil)
|
|
47
|
+
super(message, status_code, response_body)
|
|
48
|
+
@retry_after = retry_after
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Leads < Base
|
|
5
|
+
def list(campaign_id: nil, status: nil, assigned_to_email_address: nil, search: nil, next_token: nil, per_page: nil)
|
|
6
|
+
client.get("/leads/list", camelize_params(
|
|
7
|
+
campaign_id: campaign_id,
|
|
8
|
+
status: status,
|
|
9
|
+
assigned_to_email_address: assigned_to_email_address,
|
|
10
|
+
search: search,
|
|
11
|
+
next_token: next_token,
|
|
12
|
+
per_page: per_page
|
|
13
|
+
))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(lead_id: nil, recipient_id: nil, campaign_id: nil, email_address: nil)
|
|
17
|
+
client.get("/leads/get", camelize_params(
|
|
18
|
+
lead_id: lead_id,
|
|
19
|
+
recipient_id: recipient_id,
|
|
20
|
+
campaign_id: campaign_id,
|
|
21
|
+
email_address: email_address
|
|
22
|
+
))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create(campaign_id:, email_addresses: nil, recipient_ids: nil)
|
|
26
|
+
client.post("/leads/create", camelize_params(
|
|
27
|
+
campaign_id: campaign_id,
|
|
28
|
+
email_addresses: email_addresses,
|
|
29
|
+
recipient_ids: recipient_ids
|
|
30
|
+
))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def close(lead_id: nil, campaign_id: nil, email_address: nil, recipient_id: nil, status: nil)
|
|
34
|
+
client.post("/leads/close", camelize_params(
|
|
35
|
+
lead_id: lead_id,
|
|
36
|
+
campaign_id: campaign_id,
|
|
37
|
+
email_address: email_address,
|
|
38
|
+
recipient_id: recipient_id,
|
|
39
|
+
status: status
|
|
40
|
+
))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def ignore(lead_id: nil, campaign_id: nil, email_address: nil, recipient_id: nil)
|
|
44
|
+
client.post("/leads/ignore", camelize_params(
|
|
45
|
+
lead_id: lead_id,
|
|
46
|
+
campaign_id: campaign_id,
|
|
47
|
+
email_address: email_address,
|
|
48
|
+
recipient_id: recipient_id
|
|
49
|
+
))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def reopen(lead_id: nil, campaign_id: nil, email_address: nil, recipient_id: nil)
|
|
53
|
+
client.post("/leads/reopen", camelize_params(
|
|
54
|
+
lead_id: lead_id,
|
|
55
|
+
campaign_id: campaign_id,
|
|
56
|
+
email_address: email_address,
|
|
57
|
+
recipient_id: recipient_id
|
|
58
|
+
))
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Push < Base
|
|
5
|
+
def create(target_url:, event:, filter: nil)
|
|
6
|
+
client.post("/push/create", camelize_params(target_url: target_url, event: event, filter: filter))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def delete(target_url:)
|
|
10
|
+
client.post("/push/delete", camelize_params(target_url: target_url))
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Recipients < Base
|
|
5
|
+
def add(campaign_id:, addresses: nil, list_of_emails: nil, csv_data: nil, add_as_new_list: nil, truncate_extra_fields: nil)
|
|
6
|
+
client.post("/recipients/add", camelize_params(
|
|
7
|
+
campaign_id: campaign_id,
|
|
8
|
+
addresses: addresses,
|
|
9
|
+
list_of_emails: list_of_emails,
|
|
10
|
+
csv_data: csv_data,
|
|
11
|
+
add_as_new_list: add_as_new_list,
|
|
12
|
+
truncate_extra_fields: truncate_extra_fields
|
|
13
|
+
))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_status(status_id:)
|
|
17
|
+
client.get("/recipients/add-status", camelize_params(status_id: status_id))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def list(campaign_id:, filter: nil, search: nil, next_token: nil, per_page: nil)
|
|
21
|
+
client.get("/recipients/list", camelize_params(
|
|
22
|
+
campaign_id: campaign_id,
|
|
23
|
+
filter: filter,
|
|
24
|
+
search: search,
|
|
25
|
+
next_token: next_token,
|
|
26
|
+
per_page: per_page
|
|
27
|
+
))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def get(recipient_id: nil, campaign_id: nil, email_address: nil)
|
|
31
|
+
client.get("/recipients/get", camelize_params(
|
|
32
|
+
recipient_id: recipient_id,
|
|
33
|
+
campaign_id: campaign_id,
|
|
34
|
+
email_address: email_address
|
|
35
|
+
))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def pause(campaign_id:, email_address:)
|
|
39
|
+
client.post("/recipients/pause", camelize_params(campaign_id: campaign_id, email_address: email_address))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def unpause(campaign_id:, email_address:)
|
|
43
|
+
client.post("/recipients/unpause", camelize_params(campaign_id: campaign_id, email_address: email_address))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def unsubscribe(email_addresses:)
|
|
47
|
+
client.post("/recipients/unsubscribe", camelize_params(email_addresses: email_addresses))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailshake
|
|
4
|
+
class Team < Base
|
|
5
|
+
def list_members(search: nil, next_token: nil, per_page: nil)
|
|
6
|
+
client.get("/team/list-members", camelize_params(search: search, next_token: next_token, per_page: per_page))
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|