Repository navigation
Add Accounts API #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Accounts API #84
Changes from 3 commits
4a61821
fc47609
318cdce
e84d004
e9a617a
691d1f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| require 'mailtrap' | ||
|
|
||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| account_id = 3229 | ||
| accounts = Mailtrap::AccountsAPI.new(account_id, client) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need an account id to list accounts? |
||
|
|
||
| # Set your API credentials as environment variables | ||
| # export MAILTRAP_API_KEY='your-api-key' | ||
| # export MAILTRAP_ACCOUNT_ID=your-account-id | ||
|
|
||
| # accounts = Mailtrap::AccountsAPI.new | ||
|
|
||
| # Get all accounts | ||
| accounts.list | ||
| # => [#<struct Mailtrap::Account id=123456, name="My Account", access_levels=[1000]>] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,18 @@ | |
| require_relative 'mailtrap/mail' | ||
| require_relative 'mailtrap/errors' | ||
| require_relative 'mailtrap/version' | ||
| require_relative 'mailtrap/email_templates_api' | ||
| require_relative 'mailtrap/accounts_api' | ||
| require_relative 'mailtrap/contacts_api' | ||
| require_relative 'mailtrap/contact_lists_api' | ||
| require_relative 'mailtrap/contact_fields_api' | ||
| require_relative 'mailtrap/contact_imports_api' | ||
| require_relative 'mailtrap/suppressions_api' | ||
| require_relative 'mailtrap/sending_domains_api' | ||
| require_relative 'mailtrap/projects_api' | ||
| require_relative 'mailtrap/email_templates_api' | ||
| require_relative 'mailtrap/inboxes_api' | ||
| require_relative 'mailtrap/projects_api' | ||
| require_relative 'mailtrap/sandbox_messages_api' | ||
| require_relative 'mailtrap/sandbox_attachments_api' | ||
| require_relative 'mailtrap/suppressions_api' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please fix this mess
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DagonWat could you please minimise changes in this file?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my bad! Fixed |
||
| require_relative 'mailtrap/sending_domains_api' | ||
|
|
||
| module Mailtrap | ||
| # @!macro api_errors | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Фссщгте | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/d26921ca2a48f-get-all-accounts | ||
| # @attr_reader id [Integer] The account ID | ||
| # @attr_reader name [String] The account name | ||
| # @attr_reader access_levels [Array] The account access levels | ||
| # | ||
| Account = Struct.new( | ||
| :id, | ||
| :name, | ||
| :access_levels, | ||
| keyword_init: true | ||
| ) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'account' | ||
|
|
||
| module Mailtrap | ||
| class AccountsAPI | ||
| include BaseAPI | ||
|
|
||
| self.response_class = Account | ||
|
|
||
| # Lists all accounts | ||
| # @return [Array<Account>] Array of accounts | ||
| # @!macro api_errors | ||
| def list | ||
| base_list | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def base_path | ||
| '/api/accounts' | ||
| end | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mailtrap::Account do | ||
| describe '#initialize' do | ||
| subject(:account) { described_class.new(attributes) } | ||
|
|
||
| let(:attributes) do | ||
| { | ||
| id: '123456', | ||
| name: 'Account 1', | ||
| access_levels: [ | ||
| 1000 | ||
| ] | ||
| } | ||
| end | ||
|
|
||
| it 'creates a project with all attributes' do | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| expect(account).to match_struct( | ||
| id: '123456', | ||
| name: 'Account 1', | ||
| access_levels: [1000] | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mailtrap::AccountsAPI, :vcr do | ||
| subject(:accounts_api) { described_class.new(account_id, client) } | ||
|
|
||
| let(:account_id) { ENV.fetch('MAILTRAP_ACCOUNT_ID', 1_111_111) } | ||
| let(:client) { Mailtrap::Client.new(api_key: ENV.fetch('MAILTRAP_API_KEY', 'local-api-key')) } | ||
|
|
||
| describe '#list' do | ||
| subject(:list) { accounts_api.list } | ||
|
|
||
| it 'maps response data to Account objects' do | ||
| expect(list).to all(be_a(Mailtrap::Account)) | ||
| expect(list.size).to eq(1) | ||
| end | ||
|
|
||
| context 'when api key is incorrect' do | ||
| let(:client) { Mailtrap::Client.new(api_key: 'incorrect-api-key') } | ||
|
|
||
| it 'raises authorization error' do | ||
| expect { list }.to raise_error do |error| | ||
| expect(error).to be_a(Mailtrap::AuthorizationError) | ||
| expect(error.message).to include('Incorrect API token') | ||
| expect(error.messages.any? { |msg| msg.include?('Incorrect API token') }).to be true | ||
| end | ||
| end | ||
|
Comment on lines
+20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for the AuthorizationError class definition
find . -name "*.rb" -type f | xargs rg -l "class AuthorizationError"Repository: mailtrap/mailtrap-ruby Length of output: 90 🏁 Script executed: #!/bin/bash
# Look for error class definitions in the mailtrap directory structure
fd -e rb "error" --path "*mailtrap*" -type fRepository: mailtrap/mailtrap-ruby Length of output: 299 🏁 Script executed: #!/bin/bash
# Search for AuthorizationError class and its attributes
rg -n "class AuthorizationError" -A 30 --type rubyRepository: mailtrap/mailtrap-ruby Length of output: 965 🏁 Script executed: #!/bin/bash
# Also search for any definition of 'messages' or 'details' attributes in error classes
rg -n "(attr_reader|attr_accessor|def messages|def details)" --type ruby -B 3 -A 1 | head -100Repository: mailtrap/mailtrap-ruby Length of output: 7635 🏁 Script executed: #!/bin/bash
# View the entire errors.rb file to see the Error base class definition
cat -n lib/mailtrap/errors.rbRepository: mailtrap/mailtrap-ruby Length of output: 1174 🏁 Script executed: #!/bin/bash
# Search for Error class definition and attributes
rg -n "class Error" -A 25 --type ruby lib/mailtrap/errors.rbRepository: mailtrap/mailtrap-ruby Length of output: 845 Specify error type in The Pass the expected error type and message pattern directly to ♻️ Proposed fix- expect { list }.to raise_error do |error|
- expect(error).to be_a(Mailtrap::AuthorizationError)
- expect(error.message).to include('Incorrect API token')
- expect(error.messages.any? { |msg| msg.include?('Incorrect API token') }).to be true
- end
+ expect { list }.to raise_error(Mailtrap::AuthorizationError, /Incorrect API token/) do |error|
+ expect(error.messages).to include(a_string_including('Incorrect API token'))
+ end🤖 Prompt for AI Agents |
||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you wanted to fix "Action Mailer", didnt you?