-
Notifications
You must be signed in to change notification settings - Fork 7
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 all 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,13 @@ | ||
| require 'mailtrap' | ||
|
|
||
| client = Mailtrap::Client.new(api_key: 'your-api-key') | ||
| accounts = Mailtrap::AccountsAPI.new(client) | ||
|
|
||
| # Set your API credentials as environment variables | ||
| # export MAILTRAP_API_KEY='your-api-key' | ||
|
|
||
| # 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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mailtrap | ||
| # Data Transfer Object for Account | ||
| # @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,33 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'base_api' | ||
| require_relative 'account' | ||
|
|
||
| module Mailtrap | ||
| class AccountsAPI | ||
| include BaseAPI | ||
|
|
||
| self.response_class = Account | ||
|
|
||
| attr_reader :client | ||
|
|
||
| # @param client [Mailtrap::Client] The client instance | ||
| # @raise [ArgumentError] If account_id is nil | ||
| def initialize(client = Mailtrap::Client.new) | ||
| @client = client | ||
| end | ||
|
|
||
| # 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 an account with all attributes' do | ||
| 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,28 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Mailtrap::AccountsAPI, :vcr do | ||
| subject(:accounts_api) { described_class.new(client) } | ||
|
|
||
| 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?