Sha256: 54fef88ec5382d1a3ab0c0dc3084c37045afc1b734e72b6a66c6c0e1cab97b71

Contents?: true

Size: 1.36 KB

Versions: 18

Compression:

Stored size: 1.36 KB

Contents

require 'time'

module Postmark
  class Bounce

    attr_reader :email, :bounced_at, :type, :details, :name, :id, :server_id, :tag, :message_id, :subject

    def initialize(values = {})
      values = Postmark::HashHelper.to_ruby(values)
      @id = values[:id]
      @email = values[:email]
      @bounced_at = Time.parse(values[:bounced_at])
      @type = values[:type]
      @name = values[:name]
      @details = values[:details]
      @tag = values[:tag]
      @dump_available = values[:dump_available]
      @inactive = values[:inactive]
      @can_activate = values[:can_activate]
      @message_id = values[:message_id]
      @subject = values[:subject]
    end

    def inactive?
      !!@inactive
    end

    def can_activate?
      !!@can_activate
    end

    def dump
      Postmark.api_client.dump_bounce(id)[:body]
    end

    def activate
      Bounce.new(Postmark.api_client.activate_bounce(id))
    end

    def dump_available?
      !!@dump_available
    end

    class << self
      def find(id)
        Bounce.new(Postmark.api_client.get_bounce(id))
      end

      def all(options = {})
        options[:count]  ||= 30
        options[:offset] ||= 0
        Postmark.api_client.get_bounces(options).map do |bounce_json|
          Bounce.new(bounce_json)
        end
      end

      def tags
        Postmark.api_client.get_bounced_tags
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
postmark-1.7.1 lib/postmark/bounce.rb
postmark-1.7.0 lib/postmark/bounce.rb
postmark-1.6.0 lib/postmark/bounce.rb
postmark-1.5.0 lib/postmark/bounce.rb
postmark-1.4.3 lib/postmark/bounce.rb
postmark-1.4.2 lib/postmark/bounce.rb
postmark-1.4.1 lib/postmark/bounce.rb
postmark-1.4.0 lib/postmark/bounce.rb
postmark-1.3.1 lib/postmark/bounce.rb
postmark-1.3.0 lib/postmark/bounce.rb
postmark-1.2.1 lib/postmark/bounce.rb
postmark-1.2.0 lib/postmark/bounce.rb
postmark-1.1.2 lib/postmark/bounce.rb
postmark-1.1.1 lib/postmark/bounce.rb
postmark-1.1.0 lib/postmark/bounce.rb
postmark-1.0.2 lib/postmark/bounce.rb
postmark-1.0.1 lib/postmark/bounce.rb
postmark-1.0.0 lib/postmark/bounce.rb