Sha256: d00dbb7b58d82e8add105d5553e5321ae7f0eb5d5990d0b7e1fb75e6d8b0a4d3

Contents?: true

Size: 1.34 KB

Versions: 18

Compression:

Stored size: 1.34 KB

Contents

require 'time'

module Postmark
  class Bounce

    attr_reader :email, :bounced_at, :type, :description, :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]
      @description = values[:description]
      @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
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
postmark-1.24.0 lib/postmark/bounce.rb
postmark-1.23.0 lib/postmark/bounce.rb
postmark-1.22.3 lib/postmark/bounce.rb
postmark-1.22.2 lib/postmark/bounce.rb
postmark-1.22.1 lib/postmark/bounce.rb
postmark-1.22.0 lib/postmark/bounce.rb
postmark-1.21.8 lib/postmark/bounce.rb
postmark-1.21.7 lib/postmark/bounce.rb
postmark-1.21.6 lib/postmark/bounce.rb
postmark-1.21.5 lib/postmark/bounce.rb
postmark-1.21.4 lib/postmark/bounce.rb
postmark-1.21.3 lib/postmark/bounce.rb
postmark-1.21.2 lib/postmark/bounce.rb
postmark-1.21.1 lib/postmark/bounce.rb
postmark-1.21.0 lib/postmark/bounce.rb
postmark-1.20.0 lib/postmark/bounce.rb
postmark-1.19.2 lib/postmark/bounce.rb
postmark-1.19.1 lib/postmark/bounce.rb