<commit_before>require 'spec_helper'

describe 'Accessing server resources using the API' do

  let(:api_client) { Postmark::ApiClient.new(ENV['POSTMARK_API_KEY']) }
  let(:recipient) { ENV['POSTMARK_CI_RECIPIENT'] }
  let(:message) {
    {
      :from => "<EMAIL>",
      :to => recipient,
      :subject => "Mail::Message object",
      :text_body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " \
                    "sed do eiusmod tempor incididunt ut labore et dolore " \
                    "magna aliqua."
    }
  }

  context 'Messages API' do

    def with_retries(max_retries = 10, wait_seconds = 3)
      yield
    rescue => e
      retries = retries ? retries + 1 : 1
      if retries < max_retries
        sleep wait_seconds
        retry
      else
        raise e
      end
    end

    it 'is possible to send a message and access its details via the Messages API' do
      response = api_client.deliver(message)
      message = with_retries {
        api_client.get_message(response[:message_id])
      }
      expect(message[:recipients]).to include(recipient)
    end

    it 'is possible to send a message and dump it via the Messages API' do
      response = api_client.deliver(message)
      dump = with_retries {
        api_client.dump_message(response[:message_id])<commit_msg>Increase the number of retries for API requests.<commit_after>require 'spec_helper'

describe 'Accessing server resources using the API' do

  let(:api_client) { Postmark::ApiClient.new(ENV['POSTMARK_API_KEY']) }
  let(:recipient) { ENV['POSTMARK_CI_RECIPIENT'] }
  let(:message) {
    {
      :from => "<EMAIL>",
      :to => recipient,
      :subject => "Mail::Message object",
      :text_body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " \
                    "sed do eiusmod tempor incididunt ut labore et dolore " \
                    "magna aliqua."
    }
  }

  context 'Messages API' do

    def with_retries(max_retries = 20, wait_seconds = 3)
      yield
    rescue => e
      retries = retries ? retries + 1 : 1
      if retries < max_retries
        sleep wait_seconds
        retry
      else
        raise e
      end
    end

    it 'is possible to send a message and access its details via the Messages API' do
      response = api_client.deliver(message)
      message = with_retries {
        api_client.get_message(response[:message_id])
      }
      expect(message[:recipients]).to include(recipient)
    end

    it 'is possible to send a message and dump it via the Messages API' do
      response = api_client.deliver(message)
      dump = with_retries {
        api_client.dump_message(response[:message_id])
{'fraction_non_alphanumeric': 0.0916573138795361, 'fraction_numerical': 0.0037411148522259632, 'mean_word_length': 2.560585885486019, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098212', 'n_tokens_mistral': 843, 'n_tokens_neox': 809, 'n_words': 234}