Sha256: 0284c8ac1769cc80a9419dd3753fa5093655c479bd8ff1479e9b43bbc9d262f7

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# encoding: UTF-8

require 'contactology/issues'

module Contactology
  ##
  # Contains the campaign send request results which indicate success or
  # failure, as well as any issues found with the campaign.
  #
  class SendResult
    attr_reader :issues

    def initialize(response)
      load_response response
    end

    ##
    # Public: Indicates whether or not the send was successful
    #
    # Returns true when successful.
    # Returns false when unsuccessful.
    #
    def successful?
      !!@success
    end

    ##
    # Public: Returns the spam score of the campaign.
    #
    # Returns a numeric from 0 to 100 (where higher is better).
    #
    def score
      @issues.score
    end


    private


    def load_response(response)
      unless erred_response?(response)
        @success = response['success']
        @issues = Issues.new(response['issues'])
      else
        @success = false
        @issues = Issues.new({'issues' => [{'text' => response['message']}]})
      end
    end

    def erred_response?(response)
      response['result'] && response['result'] == 'error'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contactology-1.0.0 lib/contactology/send_result.rb
contactology-0.1.2 lib/contactology/send_result.rb