Skip to content

Commit f2e568f

Browse files
authored
Merge pull request #78 from mailtrap/add-projects-api
Add Sandbox Projects API
2 parents d4259c5 + 193fee3 commit f2e568f

61 files changed

Lines changed: 2241 additions & 4298 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,7 @@ client.send_batch(
105105
)
106106
```
107107

108-
### Email Templates API
109-
110-
```ruby
111-
require 'mailtrap'
112-
113-
client = Mailtrap::Client.new(api_key: 'your-api-key')
114-
templates = Mailtrap::EmailTemplatesAPI.new 3229, client
115-
116-
templates.create(
117-
name: 'Welcome Email',
118-
subject: 'Welcome to Mailtrap!',
119-
body_html: '<h1>Hello</h1>',
120-
body_text: 'Hello',
121-
category: 'welcome'
122-
)
123-
```
108+
### Usage Examples
124109

125110
Refer to the [`examples`](examples) folder for more examples:
126111

@@ -129,6 +114,7 @@ Refer to the [`examples`](examples) folder for more examples:
129114
- [Batch Sending](examples/batch.rb)
130115
- [ActionMailer](examples/action_mailer.rb)
131116
- [Email Templates API](examples/email_templates_api.rb)
117+
- [Projects API](examples/projects_api.rb)
132118

133119
### Content-Transfer-Encoding
134120

@@ -178,12 +164,18 @@ If you use classes which have `Sending` namespace, remove the namespace like in
178164

179165
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
180166

181-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
167+
To install this gem onto your local machine, run `bundle exec rake install`.
168+
169+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
182170

183171
## Contributing
184172

185173
Bug reports and pull requests are welcome on [GitHub](https://github.com/mailtrap/mailtrap-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
186174

175+
All contributions are required to have rspec tests covering its functionality.
176+
177+
Please be sure to update [README](README.md) with new examples and features when applicable.
178+
187179
## License
188180

189181
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

examples/projects_api.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'mailtrap'
2+
3+
account_id = 3229
4+
client = Mailtrap::Client.new(api_key: 'your-api-key')
5+
projects_api = Mailtrap::ProjectsAPI.new(account_id, client)
6+
7+
# Set your API credentials as environment variables
8+
# export MAILTRAP_API_KEY='your-api-key'
9+
# export MAILTRAP_ACCOUNT_ID=your-account-id
10+
#
11+
# projects_api = Mailtrap::ProjectsAPI.new
12+
13+
# Get all projects
14+
projects_api.list
15+
16+
# Create a new project
17+
project = projects_api.create(
18+
name: 'Example Project'
19+
)
20+
21+
# Get a project
22+
project = projects_api.get(project.id)
23+
24+
# Update a project
25+
project = projects_api.update(project.id, name: 'New Project name')
26+
27+
# Delete a project
28+
projects_api.delete(project.id)

lib/mailtrap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require_relative 'mailtrap/contact_fields_api'
1111
require_relative 'mailtrap/contact_imports_api'
1212
require_relative 'mailtrap/suppressions_api'
13+
require_relative 'mailtrap/projects_api'
1314

1415
module Mailtrap
1516
# @!macro api_errors

lib/mailtrap/contact.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,5 @@ def initialize(options)
2929
def newly_created?
3030
@action != 'updated'
3131
end
32-
33-
# @return [Hash] The contact attributes as a hash
34-
def to_h
35-
super.compact
36-
end
3732
end
3833
end

lib/mailtrap/contact_field.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ module Mailtrap
99
# Allowed values: text, integer, float, boolean, date
1010
# @attr_reader merge_tag [String] Personalize your campaigns by adding a merge tag.
1111
# This field will be replaced with unique contact details for each recipient (max 80 characters)
12-
ContactField = Struct.new(:id, :name, :data_type, :merge_tag, keyword_init: true) do
13-
# @return [Hash] The contact field attributes as a hash
14-
def to_h
15-
super.compact
16-
end
17-
end
12+
ContactField = Struct.new(:id, :name, :data_type, :merge_tag, keyword_init: true)
1813
end

lib/mailtrap/contact_import.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,5 @@ module Mailtrap
1414
:updated_contacts_count,
1515
:contacts_over_limit_count,
1616
keyword_init: true
17-
) do
18-
# @return [Hash] The contact attributes as a hash
19-
def to_h
20-
super.compact
21-
end
22-
end
17+
)
2318
end

lib/mailtrap/contact_list.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@ module Mailtrap
55
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/6ec7a37234af2-contact-list
66
# @attr_reader id [Integer] The contact list ID
77
# @attr_reader name [String] The name of the contact list
8-
ContactList = Struct.new(:id, :name, keyword_init: true) do
9-
# @return [Hash] The contact list attributes as a hash
10-
def to_h
11-
super.compact
12-
end
13-
end
8+
ContactList = Struct.new(:id, :name, keyword_init: true)
149
end

lib/mailtrap/email_template.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,5 @@ module Mailtrap
2626
:created_at,
2727
:updated_at,
2828
keyword_init: true
29-
) do
30-
# @return [Hash] The template attributes as a hash
31-
def to_h
32-
super.compact
33-
end
34-
end
29+
)
3530
end

lib/mailtrap/inbox.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# frozen_string_literal: true
2+
3+
module Mailtrap
4+
# Data Transfer Object for Inbox
5+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
6+
# @attr_reader id [Integer] The inbox ID
7+
# @attr_reader name [String] The inbox name
8+
# @attr_reader username [String] The inbox username
9+
# @attr_reader password [String, nil] The inbox password
10+
# @attr_reader max_size [Integer] The maximum inbox size in MB
11+
# @attr_reader status [String] The inbox status
12+
# @attr_reader email_username [String] The email username
13+
# @attr_reader email_username_enabled [Boolean] Whether the email username is enabled
14+
# @attr_reader sent_messages_count [Integer] The count of sent messages
15+
# @attr_reader forwarded_messages_count [Integer] The count of forwarded messages
16+
# @attr_reader used [Integer] The used inbox size in MB
17+
# @attr_reader forward_from_email_address [String] The forwarding email address
18+
# @attr_reader project_id [Integer] The associated project ID
19+
# @attr_reader domain [String] The inbox domain
20+
# @attr_reader pop3_domain [String] The POP3 domain
21+
# @attr_reader email_domain [String] The email domain
22+
# @attr_reader api_domain [String] The API domain
23+
# @attr_reader emails_count [Integer] The total number of emails
24+
# @attr_reader emails_unread_count [Integer] The number of unread emails
25+
# @attr_reader last_message_sent_at [String, nil] The timestamp of the last sent message
26+
# @attr_reader smtp_ports [Array<Integer>] The list of SMTP ports
27+
# @attr_reader pop3_ports [Array<Integer>] The list of POP3 ports
28+
# @attr_reader max_message_size [Integer] The maximum message size in MB
29+
# @attr_reader permissions [Hash] List of permissions
30+
Inbox = Struct.new(
31+
:id,
32+
:name,
33+
:username,
34+
:password,
35+
:max_size,
36+
:status,
37+
:email_username,
38+
:email_username_enabled,
39+
:sent_messages_count,
40+
:forwarded_messages_count,
41+
:used,
42+
:forward_from_email_address,
43+
:project_id,
44+
:domain,
45+
:pop3_domain,
46+
:email_domain,
47+
:api_domain,
48+
:emails_count,
49+
:emails_unread_count,
50+
:last_message_sent_at,
51+
:smtp_ports,
52+
:pop3_ports,
53+
:max_message_size,
54+
:permissions,
55+
keyword_init: true
56+
)
57+
end

lib/mailtrap/project.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module Mailtrap
4+
# Data Transfer Object for Project
5+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
6+
# @attr_reader id [Integer] The project ID
7+
# @attr_reader name [String] The project name
8+
# @attr_reader share_links [Hash] Admin and viewer share links
9+
# @attr_reader inboxes [Array<Mailtrap::Inbox>] Array of inboxes
10+
# @attr_reader permissions [Hash] List of permissions
11+
#
12+
Project = Struct.new(
13+
:id,
14+
:name,
15+
:share_links,
16+
:inboxes,
17+
:permissions,
18+
keyword_init: true
19+
)
20+
end

0 commit comments

Comments
 (0)