mailosaur 6.0.3 → 7.0.2
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 +4 -4
- data/README.md +34 -11
- data/lib/Mailosaur/analysis.rb +3 -8
- data/lib/Mailosaur/files.rb +4 -15
- data/lib/Mailosaur/mailosaur_error.rb +7 -15
- data/lib/Mailosaur/messages.rb +24 -40
- data/lib/Mailosaur/models/search_criteria.rb +11 -0
- data/lib/Mailosaur/servers.rb +7 -36
- data/lib/Mailosaur/version.rb +1 -1
- data/lib/mailosaur.rb +19 -4
- metadata +14 -9
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 798ce47acf047126597a038b0bdb2297f4a4806145674ee116cefcb1e31dd556
         | 
| 4 | 
            +
              data.tar.gz: 5595c1400c4e16d1f0f1f75e44f027809b95d89817890d54695240e053f63a13
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1a193b027b089135e3855ae44abe60c777e3addca743ae48620577aa79b08877d31aa01497381055e64178ce0c848f23530041d6ff70d573fd6054556fdec7c0
         | 
| 7 | 
            +
              data.tar.gz: 71e18e02a530719f12cc506ed6bafda93c0127e8c37f5ac26345659506427453c11e540dc53feafc99b4dd21cbb607a6c07b08ed8229bfa5ec46de5e91f1f011
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            # Mailosaur Ruby Client Library
         | 
| 2 2 |  | 
| 3 | 
            -
            [Mailosaur](https://mailosaur.com)  | 
| 3 | 
            +
            [Mailosaur](https://mailosaur.com) lets you automate email and SMS tests, like account verification and password resets, and integrate these into your CI/CD pipeline.
         | 
| 4 4 |  | 
| 5 | 
            -
            [](https://github.com/mailosaur/mailosaur-ruby/actions)
         | 
| 6 6 |  | 
| 7 7 | 
             
            ## Installation
         | 
| 8 8 |  | 
| @@ -10,29 +10,52 @@ | |
| 10 10 | 
             
            gem install mailosaur
         | 
| 11 11 | 
             
            ```
         | 
| 12 12 |  | 
| 13 | 
            -
            ## Documentation | 
| 13 | 
            +
            ## Documentation
         | 
| 14 14 |  | 
| 15 | 
            -
            [ | 
| 15 | 
            +
            Please see the [Ruby client reference](https://mailosaur.com/docs/email-testing/ruby/client-reference/) for the most up-to-date documentation.
         | 
| 16 16 |  | 
| 17 | 
            -
            ##  | 
| 17 | 
            +
            ## Usage
         | 
| 18 18 |  | 
| 19 | 
            -
             | 
| 19 | 
            +
            example.rb
         | 
| 20 20 |  | 
| 21 | 
            +
            ```ruby
         | 
| 22 | 
            +
            require "mailosaur"
         | 
| 23 | 
            +
            mailosaur = Mailosaur::MailosaurClient.new("YOUR_API_KEY")
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            result = mailosaur.servers.list()
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            print("You have a server called: " + result.items[0].name)
         | 
| 21 28 | 
             
            ```
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ## Development
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            You must have the following prerequisites installed:
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            * [Bundler](https://bundler.io/)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            Install all development dependencies:
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            ```sh
         | 
| 22 39 | 
             
            bundle install
         | 
| 40 | 
            +
            ```
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            The test suite requires the following environment variables to be set:
         | 
| 23 43 |  | 
| 44 | 
            +
            ```sh
         | 
| 45 | 
            +
            export MAILOSAUR_BASE_URL=https://mailosaur.com/
         | 
| 24 46 | 
             
            export MAILOSAUR_API_KEY=your_api_key
         | 
| 25 47 | 
             
            export MAILOSAUR_SERVER=server_id
         | 
| 48 | 
            +
            ```
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            Run all tests:
         | 
| 26 51 |  | 
| 52 | 
            +
            ```sh
         | 
| 27 53 | 
             
            bundle exec rake test
         | 
| 28 54 | 
             
            ```
         | 
| 29 55 |  | 
| 30 | 
            -
             | 
| 56 | 
            +
            Lint code (via Rubocop):
         | 
| 31 57 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
            ```
         | 
| 35 | 
            -
            bundle install
         | 
| 58 | 
            +
            ```sh
         | 
| 36 59 | 
             
            bundle exec rubocop
         | 
| 37 60 | 
             
            ```
         | 
| 38 61 |  | 
    
        data/lib/Mailosaur/analysis.rb
    CHANGED
    
    | @@ -4,8 +4,9 @@ module Mailosaur | |
| 4 4 | 
             
                # Creates and initializes a new instance of the Analysis class.
         | 
| 5 5 | 
             
                # @param conn client connection.
         | 
| 6 6 | 
             
                #
         | 
| 7 | 
            -
                def initialize(conn)
         | 
| 7 | 
            +
                def initialize(conn, handle_http_error)
         | 
| 8 8 | 
             
                  @conn = conn
         | 
| 9 | 
            +
                  @handle_http_error = handle_http_error
         | 
| 9 10 | 
             
                end
         | 
| 10 11 |  | 
| 11 12 | 
             
                # @return [Connection] the client connection.
         | 
| @@ -22,13 +23,7 @@ module Mailosaur | |
| 22 23 | 
             
                #
         | 
| 23 24 | 
             
                def spam(email)
         | 
| 24 25 | 
             
                  response = conn.get 'api/analysis/spam/' + email
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  unless response.status == 200
         | 
| 27 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 28 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 29 | 
            -
                    raise mailosaur_error
         | 
| 30 | 
            -
                  end
         | 
| 31 | 
            -
             | 
| 26 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 32 27 | 
             
                  model = JSON.load(response.body)
         | 
| 33 28 | 
             
                  Mailosaur::Models::SpamAnalysisResult.new(model)
         | 
| 34 29 | 
             
                end
         | 
    
        data/lib/Mailosaur/files.rb
    CHANGED
    
    | @@ -4,8 +4,9 @@ module Mailosaur | |
| 4 4 | 
             
                # Creates and initializes a new instance of the Files class.
         | 
| 5 5 | 
             
                # @param client connection.
         | 
| 6 6 | 
             
                #
         | 
| 7 | 
            -
                def initialize(conn)
         | 
| 7 | 
            +
                def initialize(conn, handle_http_error)
         | 
| 8 8 | 
             
                  @conn = conn
         | 
| 9 | 
            +
                  @handle_http_error = handle_http_error
         | 
| 9 10 | 
             
                end
         | 
| 10 11 |  | 
| 11 12 | 
             
                # @return [Connection] the client connection.
         | 
| @@ -23,13 +24,7 @@ module Mailosaur | |
| 23 24 | 
             
                #
         | 
| 24 25 | 
             
                def get_attachment(id)
         | 
| 25 26 | 
             
                  response = conn.get 'api/files/attachments/' + id
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                  unless response.status == 200
         | 
| 28 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 29 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 30 | 
            -
                    raise mailosaur_error
         | 
| 31 | 
            -
                  end
         | 
| 32 | 
            -
             | 
| 27 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 33 28 | 
             
                  response.body
         | 
| 34 29 | 
             
                end
         | 
| 35 30 |  | 
| @@ -45,13 +40,7 @@ module Mailosaur | |
| 45 40 | 
             
                #
         | 
| 46 41 | 
             
                def get_email(id)
         | 
| 47 42 | 
             
                  response = conn.get 'api/files/email/' + id
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                  unless response.status == 200
         | 
| 50 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 51 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 52 | 
            -
                    raise mailosaur_error
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
             | 
| 43 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 55 44 | 
             
                  response.body
         | 
| 56 45 | 
             
                end
         | 
| 57 46 | 
             
              end
         | 
| @@ -1,23 +1,15 @@ | |
| 1 | 
            -
            require 'json'
         | 
| 2 | 
            -
             | 
| 3 1 | 
             
            module Mailosaur
         | 
| 4 2 | 
             
              class MailosaurError < StandardError
         | 
| 5 | 
            -
                attr_reader : | 
| 6 | 
            -
                attr_reader : | 
| 7 | 
            -
                attr_reader : | 
| 3 | 
            +
                attr_reader :error_type
         | 
| 4 | 
            +
                attr_reader :http_status_code
         | 
| 5 | 
            +
                attr_reader :http_response_body
         | 
| 8 6 |  | 
| 9 | 
            -
                def initialize(message,  | 
| 7 | 
            +
                def initialize(message = '', error_type = '', http_status_code = nil, http_response_body = nil)
         | 
| 10 8 | 
             
                  super(message)
         | 
| 11 9 |  | 
| 12 | 
            -
                  @ | 
| 13 | 
            -
                  @ | 
| 14 | 
            -
                  @ | 
| 15 | 
            -
             | 
| 16 | 
            -
                  unless error_model.nil?
         | 
| 17 | 
            -
                    @type = error_model['type']
         | 
| 18 | 
            -
                    @messages = error_model['messages']
         | 
| 19 | 
            -
                    @model = error_model['model']
         | 
| 20 | 
            -
                  end
         | 
| 10 | 
            +
                  @error_type = error_type
         | 
| 11 | 
            +
                  @http_status_code = http_status_code
         | 
| 12 | 
            +
                  @http_response_body = http_response_body
         | 
| 21 13 | 
             
                end
         | 
| 22 14 | 
             
              end
         | 
| 23 15 | 
             
            end
         | 
    
        data/lib/Mailosaur/messages.rb
    CHANGED
    
    | @@ -1,11 +1,14 @@ | |
| 1 | 
            +
            require 'uri'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Mailosaur
         | 
| 2 4 | 
             
              class Messages
         | 
| 3 5 | 
             
                #
         | 
| 4 6 | 
             
                # Creates and initializes a new instance of the Messages class.
         | 
| 5 7 | 
             
                # @param client connection.
         | 
| 6 8 | 
             
                #
         | 
| 7 | 
            -
                def initialize(conn)
         | 
| 9 | 
            +
                def initialize(conn, handle_http_error)
         | 
| 8 10 | 
             
                  @conn = conn
         | 
| 11 | 
            +
                  @handle_http_error = handle_http_error
         | 
| 9 12 | 
             
                end
         | 
| 10 13 |  | 
| 11 14 | 
             
                # @return [Connection] the client connection.
         | 
| @@ -29,9 +32,9 @@ module Mailosaur | |
| 29 32 | 
             
                #
         | 
| 30 33 | 
             
                def get(server, criteria, timeout: 10_000, received_after: DateTime.now - (1.0 / 24))
         | 
| 31 34 | 
             
                  # Defaults timeout to 10s, receivedAfter to 1h
         | 
| 32 | 
            -
                  raise Mailosaur::MailosaurError.new(' | 
| 35 | 
            +
                  raise Mailosaur::MailosaurError.new('Must provide a valid Server ID.', 'invalid_request') if server.length != 8
         | 
| 33 36 |  | 
| 34 | 
            -
                  result = search(server, criteria, timeout: timeout, received_after: received_after)
         | 
| 37 | 
            +
                  result = search(server, criteria, page: 0, items_per_page: 1, timeout: timeout, received_after: received_after)
         | 
| 35 38 | 
             
                  get_by_id(result.items[0].id)
         | 
| 36 39 | 
             
                end
         | 
| 37 40 |  | 
| @@ -47,13 +50,7 @@ module Mailosaur | |
| 47 50 | 
             
                #
         | 
| 48 51 | 
             
                def get_by_id(id)
         | 
| 49 52 | 
             
                  response = conn.get 'api/messages/' + id
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                  unless response.status == 200
         | 
| 52 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 53 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 54 | 
            -
                    raise mailosaur_error
         | 
| 55 | 
            -
                  end
         | 
| 56 | 
            -
             | 
| 53 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 57 54 | 
             
                  model = JSON.load(response.body)
         | 
| 58 55 | 
             
                  Mailosaur::Models::Message.new(model)
         | 
| 59 56 | 
             
                end
         | 
| @@ -68,13 +65,7 @@ module Mailosaur | |
| 68 65 | 
             
                #
         | 
| 69 66 | 
             
                def delete(id)
         | 
| 70 67 | 
             
                  response = conn.delete 'api/messages/' + id
         | 
| 71 | 
            -
             | 
| 72 | 
            -
                  unless response.status == 204
         | 
| 73 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 74 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 75 | 
            -
                    raise mailosaur_error
         | 
| 76 | 
            -
                  end
         | 
| 77 | 
            -
             | 
| 68 | 
            +
                  @handle_http_error.call(response) unless response.status == 204
         | 
| 78 69 | 
             
                  nil
         | 
| 79 70 | 
             
                end
         | 
| 80 71 |  | 
| @@ -90,21 +81,20 @@ module Mailosaur | |
| 90 81 | 
             
                # pagination.
         | 
| 91 82 | 
             
                # @param items_per_page [Integer] A limit on the number of results to be
         | 
| 92 83 | 
             
                # returned per page. Can be set between 1 and 1000 items, the default is 50.
         | 
| 84 | 
            +
                # @param received_after [DateTime] Limits results to only messages received
         | 
| 85 | 
            +
                # after this date/time.
         | 
| 93 86 | 
             
                #
         | 
| 94 87 | 
             
                # @return [MessageListResult] operation results.
         | 
| 95 88 | 
             
                #
         | 
| 96 | 
            -
                def list(server, page: nil, items_per_page: nil)
         | 
| 89 | 
            +
                def list(server, page: nil, items_per_page: nil, received_after: nil)
         | 
| 97 90 | 
             
                  url = 'api/messages?server=' + server
         | 
| 98 | 
            -
                  url += page ? '&page=' + page : ''
         | 
| 99 | 
            -
                  url += items_per_page ? '&itemsPerPage=' + items_per_page : ''
         | 
| 91 | 
            +
                  url += page ? '&page=' + page.to_s : ''
         | 
| 92 | 
            +
                  url += items_per_page ? '&itemsPerPage=' + items_per_page.to_s : ''
         | 
| 93 | 
            +
                  url += received_after ? '&receivedAfter=' + CGI.escape(received_after.iso8601) : ''
         | 
| 100 94 |  | 
| 101 95 | 
             
                  response = conn.get url
         | 
| 102 96 |  | 
| 103 | 
            -
                  unless response.status == 200
         | 
| 104 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 105 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 106 | 
            -
                    raise mailosaur_error
         | 
| 107 | 
            -
                  end
         | 
| 97 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 108 98 |  | 
| 109 99 | 
             
                  model = JSON.load(response.body)
         | 
| 110 100 | 
             
                  Mailosaur::Models::MessageListResult.new(model)
         | 
| @@ -120,13 +110,7 @@ module Mailosaur | |
| 120 110 | 
             
                #
         | 
| 121 111 | 
             
                def delete_all(server)
         | 
| 122 112 | 
             
                  response = conn.delete 'api/messages?server=' + server
         | 
| 123 | 
            -
             | 
| 124 | 
            -
                  unless response.status == 204
         | 
| 125 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 126 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 127 | 
            -
                    raise mailosaur_error
         | 
| 128 | 
            -
                  end
         | 
| 129 | 
            -
             | 
| 113 | 
            +
                  @handle_http_error.call(response) unless response.status == 204
         | 
| 130 114 | 
             
                  nil
         | 
| 131 115 | 
             
                end
         | 
| 132 116 |  | 
| @@ -148,14 +132,16 @@ module Mailosaur | |
| 148 132 | 
             
                # (in milliseconds).
         | 
| 149 133 | 
             
                # @param received_after [DateTime] Limits results to only messages received
         | 
| 150 134 | 
             
                # after this date/time.
         | 
| 135 | 
            +
                # @param error_on_timeout [Boolean] When set to false, an error will not be
         | 
| 136 | 
            +
                # throw if timeout is reached (default: true).
         | 
| 151 137 | 
             
                #
         | 
| 152 138 | 
             
                # @return [MessageListResult] operation results.
         | 
| 153 139 | 
             
                #
         | 
| 154 | 
            -
                def search(server, criteria, page: nil, items_per_page: nil, timeout: nil, received_after: nil) # rubocop:disable all
         | 
| 140 | 
            +
                def search(server, criteria, page: nil, items_per_page: nil, timeout: nil, received_after: nil, error_on_timeout: true) # rubocop:disable all
         | 
| 155 141 | 
             
                  url = 'api/messages/search?server=' + server
         | 
| 156 142 | 
             
                  url += page ? '&page=' + page.to_s : ''
         | 
| 157 143 | 
             
                  url += items_per_page ? '&itemsPerPage=' + items_per_page.to_s : ''
         | 
| 158 | 
            -
                  url += received_after ? '&receivedAfter=' + received_after.iso8601 : ''
         | 
| 144 | 
            +
                  url += received_after ? '&receivedAfter=' + CGI.escape(received_after.iso8601) : ''
         | 
| 159 145 |  | 
| 160 146 | 
             
                  poll_count = 0
         | 
| 161 147 | 
             
                  start_time = Time.now.to_f
         | 
| @@ -163,11 +149,7 @@ module Mailosaur | |
| 163 149 | 
             
                  loop do
         | 
| 164 150 | 
             
                    response = conn.post url, criteria.to_json
         | 
| 165 151 |  | 
| 166 | 
            -
                    unless response.status == 200
         | 
| 167 | 
            -
                      error_model = JSON.load(response.body)
         | 
| 168 | 
            -
                      mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model) # rubocop:disable Metrics/LineLength
         | 
| 169 | 
            -
                      raise mailosaur_error
         | 
| 170 | 
            -
                    end
         | 
| 152 | 
            +
                    @handle_http_error.call(response) unless response.status == 200
         | 
| 171 153 |  | 
| 172 154 | 
             
                    model = JSON.load(response.body)
         | 
| 173 155 | 
             
                    return Mailosaur::Models::MessageListResult.new(model) if timeout.to_i.zero? || !model['items'].empty?
         | 
| @@ -180,7 +162,9 @@ module Mailosaur | |
| 180 162 |  | 
| 181 163 | 
             
                    ## Stop if timeout will be exceeded
         | 
| 182 164 | 
             
                    if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
         | 
| 183 | 
            -
                       | 
| 165 | 
            +
                      return Mailosaur::Models::MessageListResult.new(model) unless error_on_timeout
         | 
| 166 | 
            +
             | 
| 167 | 
            +
                      raise Mailosaur::MailosaurError.new('No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this).', 'search_timeout')
         | 
| 184 168 | 
             
                    end
         | 
| 185 169 |  | 
| 186 170 | 
             
                    sleep(delay / 1000)
         | 
| @@ -2,11 +2,17 @@ module Mailosaur | |
| 2 2 | 
             
              module Models
         | 
| 3 3 | 
             
                class SearchCriteria < BaseModel
         | 
| 4 4 | 
             
                  def initialize(data = {})
         | 
| 5 | 
            +
                    @sent_from = data['sentFrom']
         | 
| 5 6 | 
             
                    @sent_to = data['sentTo']
         | 
| 6 7 | 
             
                    @subject = data['subject']
         | 
| 7 8 | 
             
                    @body = data['body']
         | 
| 9 | 
            +
                    @match = data['match'] || 'ALL'
         | 
| 8 10 | 
             
                  end
         | 
| 9 11 |  | 
| 12 | 
            +
                  # @return [String] The full email address from which the target email was
         | 
| 13 | 
            +
                  # sent.
         | 
| 14 | 
            +
                  attr_accessor :sent_from
         | 
| 15 | 
            +
             | 
| 10 16 | 
             
                  # @return [String] The full email address to which the target email was
         | 
| 11 17 | 
             
                  # sent.
         | 
| 12 18 | 
             
                  attr_accessor :sent_to
         | 
| @@ -18,6 +24,11 @@ module Mailosaur | |
| 18 24 | 
             
                  # @return [String] The value to seek within the target email's HTML or
         | 
| 19 25 | 
             
                  # text body.
         | 
| 20 26 | 
             
                  attr_accessor :body
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  # @return [String] If set to ALL (default), then only results that match all
         | 
| 29 | 
            +
                  # specified criteria will be returned. If set to ANY, results that match any of the
         | 
| 30 | 
            +
                  # specified criteria will be returned.
         | 
| 31 | 
            +
                  attr_accessor :match
         | 
| 21 32 | 
             
                end
         | 
| 22 33 | 
             
              end
         | 
| 23 34 | 
             
            end
         | 
    
        data/lib/Mailosaur/servers.rb
    CHANGED
    
    | @@ -4,8 +4,9 @@ module Mailosaur | |
| 4 4 | 
             
                # Creates and initializes a new instance of the Servers class.
         | 
| 5 5 | 
             
                # @param client connection.
         | 
| 6 6 | 
             
                #
         | 
| 7 | 
            -
                def initialize(conn)
         | 
| 7 | 
            +
                def initialize(conn, handle_http_error)
         | 
| 8 8 | 
             
                  @conn = conn
         | 
| 9 | 
            +
                  @handle_http_error = handle_http_error
         | 
| 9 10 | 
             
                end
         | 
| 10 11 |  | 
| 11 12 | 
             
                # @return [Connection] the client connection.
         | 
| @@ -21,13 +22,7 @@ module Mailosaur | |
| 21 22 | 
             
                #
         | 
| 22 23 | 
             
                def list
         | 
| 23 24 | 
             
                  response = conn.get 'api/servers'
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                  unless response.status == 200
         | 
| 26 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 27 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 28 | 
            -
                    raise mailosaur_error
         | 
| 29 | 
            -
                  end
         | 
| 30 | 
            -
             | 
| 25 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 31 26 | 
             
                  model = JSON.load(response.body)
         | 
| 32 27 | 
             
                  Mailosaur::Models::ServerListResult.new(model)
         | 
| 33 28 | 
             
                end
         | 
| @@ -43,13 +38,7 @@ module Mailosaur | |
| 43 38 | 
             
                #
         | 
| 44 39 | 
             
                def create(server_create_options)
         | 
| 45 40 | 
             
                  response = conn.post 'api/servers', server_create_options.to_json
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  unless response.status == 200
         | 
| 48 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 49 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 50 | 
            -
                    raise mailosaur_error
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 41 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 53 42 | 
             
                  model = JSON.load(response.body)
         | 
| 54 43 | 
             
                  Mailosaur::Models::Server.new(model)
         | 
| 55 44 | 
             
                end
         | 
| @@ -66,13 +55,7 @@ module Mailosaur | |
| 66 55 | 
             
                #
         | 
| 67 56 | 
             
                def get(id)
         | 
| 68 57 | 
             
                  response = conn.get 'api/servers/' + id
         | 
| 69 | 
            -
             | 
| 70 | 
            -
                  unless response.status == 200
         | 
| 71 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 72 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 73 | 
            -
                    raise mailosaur_error
         | 
| 74 | 
            -
                  end
         | 
| 75 | 
            -
             | 
| 58 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 76 59 | 
             
                  model = JSON.load(response.body)
         | 
| 77 60 | 
             
                  Mailosaur::Models::Server.new(model)
         | 
| 78 61 | 
             
                end
         | 
| @@ -89,13 +72,7 @@ module Mailosaur | |
| 89 72 | 
             
                #
         | 
| 90 73 | 
             
                def update(id, server)
         | 
| 91 74 | 
             
                  response = conn.put 'api/servers/' + id, server.to_json
         | 
| 92 | 
            -
             | 
| 93 | 
            -
                  unless response.status == 200
         | 
| 94 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 95 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 96 | 
            -
                    raise mailosaur_error
         | 
| 97 | 
            -
                  end
         | 
| 98 | 
            -
             | 
| 75 | 
            +
                  @handle_http_error.call(response) unless response.status == 200
         | 
| 99 76 | 
             
                  model = JSON.load(response.body)
         | 
| 100 77 | 
             
                  Mailosaur::Models::Server.new(model)
         | 
| 101 78 | 
             
                end
         | 
| @@ -110,13 +87,7 @@ module Mailosaur | |
| 110 87 | 
             
                #
         | 
| 111 88 | 
             
                def delete(id)
         | 
| 112 89 | 
             
                  response = conn.delete 'api/servers/' + id
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                  unless response.status == 204
         | 
| 115 | 
            -
                    error_model = JSON.load(response.body)
         | 
| 116 | 
            -
                    mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
         | 
| 117 | 
            -
                    raise mailosaur_error
         | 
| 118 | 
            -
                  end
         | 
| 119 | 
            -
             | 
| 90 | 
            +
                  @handle_http_error.call(response) unless response.status == 204
         | 
| 120 91 | 
             
                  nil
         | 
| 121 92 | 
             
                end
         | 
| 122 93 |  | 
    
        data/lib/Mailosaur/version.rb
    CHANGED
    
    
    
        data/lib/mailosaur.rb
    CHANGED
    
    | @@ -50,22 +50,22 @@ module Mailosaur | |
| 50 50 |  | 
| 51 51 | 
             
                # @return [Analysis] analysis
         | 
| 52 52 | 
             
                def analysis
         | 
| 53 | 
            -
                  @analysis ||= Analysis.new(connection)
         | 
| 53 | 
            +
                  @analysis ||= Analysis.new(connection, method(:handle_http_error))
         | 
| 54 54 | 
             
                end
         | 
| 55 55 |  | 
| 56 56 | 
             
                # @return [Files] files
         | 
| 57 57 | 
             
                def files
         | 
| 58 | 
            -
                  @files ||= Files.new(connection)
         | 
| 58 | 
            +
                  @files ||= Files.new(connection, method(:handle_http_error))
         | 
| 59 59 | 
             
                end
         | 
| 60 60 |  | 
| 61 61 | 
             
                # @return [Messages] messages
         | 
| 62 62 | 
             
                def messages
         | 
| 63 | 
            -
                  @messages ||= Messages.new(connection)
         | 
| 63 | 
            +
                  @messages ||= Messages.new(connection, method(:handle_http_error))
         | 
| 64 64 | 
             
                end
         | 
| 65 65 |  | 
| 66 66 | 
             
                # @return [Servers] servers
         | 
| 67 67 | 
             
                def servers
         | 
| 68 | 
            -
                  @servers ||= Servers.new(connection)
         | 
| 68 | 
            +
                  @servers ||= Servers.new(connection, method(:handle_http_error))
         | 
| 69 69 | 
             
                end
         | 
| 70 70 |  | 
| 71 71 | 
             
                private
         | 
| @@ -78,5 +78,20 @@ module Mailosaur | |
| 78 78 | 
             
                    }
         | 
| 79 79 | 
             
                  }).tap { |conn| conn.basic_auth(@api_key, '') }
         | 
| 80 80 | 
             
                end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def handle_http_error(response)
         | 
| 83 | 
            +
                  case response.status
         | 
| 84 | 
            +
                  when 400
         | 
| 85 | 
            +
                    raise Mailosaur::MailosaurError.new('Request had one or more invalid parameters.', 'invalid_request', response.status, response.body)
         | 
| 86 | 
            +
                  when 401
         | 
| 87 | 
            +
                    raise Mailosaur::MailosaurError.new('Authentication failed, check your API key.', 'authentication_error', response.status, response.body)
         | 
| 88 | 
            +
                  when 403
         | 
| 89 | 
            +
                    raise Mailosaur::MailosaurError.new('Insufficient permission to perform that task.', 'permission_error', response.status, response.body)
         | 
| 90 | 
            +
                  when 404
         | 
| 91 | 
            +
                    raise Mailosaur::MailosaurError.new('Request did not find any matching resources.', 'invalid_request', response.status, response.body)
         | 
| 92 | 
            +
                  else
         | 
| 93 | 
            +
                    raise Mailosaur::MailosaurError.new('An API error occurred, see httpResponse for further information.', 'api_error', response.status, response.body)
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
                end
         | 
| 81 96 | 
             
              end
         | 
| 82 97 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: mailosaur
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 7.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 | 
            -
            - Mailosaur | 
| 7 | 
            +
            - Mailosaur
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-10-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -144,7 +144,8 @@ dependencies: | |
| 144 144 | 
             
                - - ">="
         | 
| 145 145 | 
             
                  - !ruby/object:Gem::Version
         | 
| 146 146 | 
             
                    version: 3.2.7
         | 
| 147 | 
            -
            description: Ruby  | 
| 147 | 
            +
            description: The Mailosaur Ruby library lets you integrate email and SMS testing into
         | 
| 148 | 
            +
              your continuous integration process.
         | 
| 148 149 | 
             
            email: code@mailosaur.com
         | 
| 149 150 | 
             
            executables: []
         | 
| 150 151 | 
             
            extensions: []
         | 
| @@ -179,10 +180,15 @@ files: | |
| 179 180 | 
             
            - lib/Mailosaur/servers.rb
         | 
| 180 181 | 
             
            - lib/Mailosaur/version.rb
         | 
| 181 182 | 
             
            - lib/mailosaur.rb
         | 
| 182 | 
            -
            homepage: https://mailosaur.com
         | 
| 183 | 
            +
            homepage: https://mailosaur.com/
         | 
| 183 184 | 
             
            licenses:
         | 
| 184 185 | 
             
            - MIT
         | 
| 185 | 
            -
            metadata: | 
| 186 | 
            +
            metadata:
         | 
| 187 | 
            +
              bug_tracker_uri: https://github.com/mailosaur/mailosaur-ruby/issues
         | 
| 188 | 
            +
              documentation_uri: https://mailosaur.com/docs/email-testing/ruby/
         | 
| 189 | 
            +
              github_repo: ssh://github.com/mailosaur/mailosaur-ruby
         | 
| 190 | 
            +
              homepage_uri: https://mailosaur.com/
         | 
| 191 | 
            +
              source_code_uri: https://github.com/mailosaur/mailosaur-ruby
         | 
| 186 192 | 
             
            post_install_message: 
         | 
| 187 193 | 
             
            rdoc_options: []
         | 
| 188 194 | 
             
            require_paths:
         | 
| @@ -198,9 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 198 204 | 
             
                - !ruby/object:Gem::Version
         | 
| 199 205 | 
             
                  version: '0'
         | 
| 200 206 | 
             
            requirements: []
         | 
| 201 | 
            -
             | 
| 202 | 
            -
            rubygems_version: 2.7.7
         | 
| 207 | 
            +
            rubygems_version: 3.1.2
         | 
| 203 208 | 
             
            signing_key: 
         | 
| 204 209 | 
             
            specification_version: 4
         | 
| 205 | 
            -
            summary: Ruby  | 
| 210 | 
            +
            summary: The Mailosaur Ruby library
         | 
| 206 211 | 
             
            test_files: []
         |