Sha256: 0fbb6ce19770fbb9561a7926b6c4a780c965b7bdb9e7640497b19d5e371fa66b

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

require 'time'

module Postmark
  class Bounce

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

    def initialize(values = {})
      @id             = values["ID"]
      @email          = values["Email"]
      @bounced_at     = Time.parse(values["BouncedAt"])
      @type           = values["Type"]
      @name           = values["Name"]
      @details        = values["Details"]
      @tag            = values["Tag"]
      @dump_available = values["DumpAvailable"]
      @inactive       = values["Inactive"]
      @can_activate   = values["CanActivate"]
    end

    def inactive?
      !!@inactive
    end

    def can_activate?
      !!@can_activate
    end

    def dump
      Postmark::HttpClient.get("bounces/#{id}/dump")["Body"]
    end

    def activate
      Bounce.new(Postmark::HttpClient.put("bounces/#{id}/activate")["Bounce"])
    end

    def dump_available?
      !!@dump_available
    end

    class << self
      def find(id)
        Bounce.new(Postmark::HttpClient.get("bounces/#{id}"))
      end

      def all(options = {})
        options[:count]  ||= 30
        options[:offset] ||= 0
        Postmark::HttpClient.get("bounces", options)['Bounces'].map { |bounce_json| Bounce.new(bounce_json) }
      end

      def tags
        Postmark::HttpClient.get("bounces/tags")
      end
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
postmark-0.9.13 lib/postmark/bounce.rb
postmark-0.9.12 lib/postmark/bounce.rb
postmark-0.9.11 lib/postmark/bounce.rb
postmark-0.9.10 lib/postmark/bounce.rb
postmark-0.9.9 lib/postmark/bounce.rb
postmark-0.9.8 lib/postmark/bounce.rb
postmark-0.9.6 lib/postmark/bounce.rb
postmark-0.9.5 lib/postmark/bounce.rb
postmark-0.9.4 lib/postmark/bounce.rb
postmark-0.9.3 lib/postmark/bounce.rb
postmark-0.9.2 lib/postmark/bounce.rb
postmark-0.9.1 lib/postmark/bounce.rb