sinatra-hexacta 1.4.3 → 1.4.4
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/lib/sinatra/extensions/mailsender.rb +35 -11
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 309f78d43f4e7447e920edaa8e90d36f4992e1cdc0fde8a40ee7ad8f0e17498a
         | 
| 4 | 
            +
              data.tar.gz: 66e5d4cceb9b6bf3e1f83919bc2f0962827ef6fba83d459eec4aceea85ac6675
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8c0c94b820a01db53ae1450f5dd014ca2d1541b6c9f2bb1a0f216e6579b64352ef59bfb2940e405e69a8ae7f19eef4b0f3e434d178a51d75cf3bfe75751b019e
         | 
| 7 | 
            +
              data.tar.gz: 3536f3971f4cb17aa0674a496b98d33d2794a0dfe84bf5418ce88b8b4b9e65354d7a7784226b2bf3378cf9de4a775d9f72ef740280b4afc6c0d134c8f5e55e74
         | 
| @@ -20,16 +20,32 @@ class MailSender | |
| 20 20 | 
             
                http.start { |http| http.request(request) }
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 | 
            +
             | 
| 23 24 | 
             
              def _authorize_mail
         | 
| 24 25 | 
             
                params = [ [ "grant_type", "password" ], [ "client_id", "MailApp" ], [ "client_secret", "MailAppPRD2018!" ] ]
         | 
| 25 | 
            -
                 | 
| 26 | 
            +
                retry_times = 0
         | 
| 27 | 
            +
                begin
         | 
| 28 | 
            +
                  response = _do_connect("https://comunicacion.hexacta.com:4443/apptoken",params)
         | 
| 29 | 
            +
                rescue StandardError => bang
         | 
| 30 | 
            +
                  response = nil
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                until response.is_a?( Net::HTTPSuccess ) || retry_times > 10 do
         | 
| 33 | 
            +
                  begin
         | 
| 34 | 
            +
                    retry_times = retry_times + 1
         | 
| 35 | 
            +
                    sleep(retry_times)
         | 
| 36 | 
            +
                    response = _do_connect("https://comunicacion.hexacta.com:4443/apptoken",params)
         | 
| 37 | 
            +
                  rescue StandardError => bang
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 26 40 | 
             
                if( response.is_a?( Net::HTTPSuccess ) )
         | 
| 27 41 | 
             
                  token = JSON.parse(response.body)
         | 
| 28 42 | 
             
                  @access_token = token["access_token"]
         | 
| 29 43 | 
             
                  @refresh_token = token["refresh_token"]
         | 
| 30 44 | 
             
                  @expire  = DateTime.parse(token[".expires"])
         | 
| 45 | 
            +
                  return true
         | 
| 31 46 | 
             
                else
         | 
| 32 47 | 
             
                  NotificationSender.instance.send_error(nil,'Authorize mail failed',response.body)
         | 
| 48 | 
            +
                  return false
         | 
| 33 49 | 
             
                end
         | 
| 34 50 | 
             
              end
         | 
| 35 51 |  | 
| @@ -54,26 +70,34 @@ class MailSender | |
| 54 70 | 
             
              end
         | 
| 55 71 |  | 
| 56 72 | 
             
              def _expired?
         | 
| 57 | 
            -
                expire.nil? || DateTime.now < expire
         | 
| 73 | 
            +
                @expire.nil? || DateTime.now < @expire
         | 
| 58 74 | 
             
              end
         | 
| 59 75 |  | 
| 76 | 
            +
             | 
| 60 77 | 
             
              def do_send(mail)
         | 
| 61 | 
            -
                 | 
| 62 | 
            -
                  if _expired?
         | 
| 63 | 
            -
                    _authorize_mail
         | 
| 64 | 
            -
                  end
         | 
| 78 | 
            +
                authorized = _expired?? _authorize_mail : true
         | 
| 65 79 |  | 
| 80 | 
            +
                if authorized
         | 
| 66 81 | 
             
                  params = [ [ "ApplicationCode", 2009 ], [ "Name", mail.template ], [ "Subject", mail.subject ], [ "EmailAddress", mail.from ] ]
         | 
| 67 82 | 
             
                  params = params + _build_map_values(mail.values) + _build_to_map(mail.to)
         | 
| 68 83 |  | 
| 69 | 
            -
                   | 
| 70 | 
            -
             | 
| 84 | 
            +
                  retry_times = 0
         | 
| 85 | 
            +
                  begin
         | 
| 86 | 
            +
                    response = _do_connect("https://comunicacion.hexacta.com:4444/api/app/TemplateNotification/SendMail",params,@access_token)
         | 
| 87 | 
            +
                  rescue StandardError => bang
         | 
| 88 | 
            +
                    response = nil
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
                  until response.is_a?( Net::HTTPSuccess ) || retry_times > 10 do
         | 
| 91 | 
            +
                    begin
         | 
| 92 | 
            +
                      retry_times = retry_times + 1
         | 
| 93 | 
            +
                      sleep(retry_times)
         | 
| 94 | 
            +
                      response = _do_connect("https://comunicacion.hexacta.com:4444/api/app/TemplateNotification/SendMail",params,@access_token)
         | 
| 95 | 
            +
                    rescue StandardError => bang
         | 
| 96 | 
            +
                    end
         | 
| 97 | 
            +
                  end
         | 
| 71 98 | 
             
                  if( !response.is_a?( Net::HTTPSuccess ) )
         | 
| 72 99 | 
             
                    NotificationSender.instance.send_error(nil,'Send mail failed',response.body)
         | 
| 73 100 | 
             
                  end
         | 
| 74 | 
            -
                rescue StandardError => error
         | 
| 75 | 
            -
                  message = error.backtrace.join(',');
         | 
| 76 | 
            -
                  NotificationSender.instance.send_error(nil,"Mail send error",message)
         | 
| 77 101 | 
             
                end
         | 
| 78 102 | 
             
              end
         | 
| 79 103 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sinatra-hexacta
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.4. | 
| 4 | 
            +
              version: 1.4.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marco Zanger
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2021- | 
| 11 | 
            +
            date: 2021-05-07 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: sucker_punch
         |