class AppleSlice::Email

Constants

ITUNES_URL_FORMAT
STATUS_CONTENT_TO_STATUS

Attributes

body[R]
id[RW]

Public Class Methods

new(body) click to toggle source
# File lib/appleslice/email.rb, line 21
def initialize(body)
  @body = body
  @noko = Nokogiri::HTML.fragment(@body)
end

Public Instance Methods

app_apple_id() click to toggle source
# File lib/appleslice/email.rb, line 63
def app_apple_id
  if rejected?
    params = URI.parse(resolution_center_url).query
    CGI::parse(params)['adamId'].first
  else
    find_td('App Apple ID:')
  end
end
app_name() click to toggle source
# File lib/appleslice/email.rb, line 54
def app_name
  if rejected?
    letter = @noko.css('#rejectionEmail p')[1]
    letter.content.split("Your app ")[-1].split(' has been reviewed')[0]
  else
    find_td('App Name: ').strip
  end
end
app_sku() click to toggle source
# File lib/appleslice/email.rb, line 44
def app_sku
  return nil if rejected?
  find_td('App SKU: ')
end
app_version_number() click to toggle source
# File lib/appleslice/email.rb, line 49
def app_version_number
  return nil if rejected?
  find_td('App Version Number: ')
end
itunes_url() click to toggle source
# File lib/appleslice/email.rb, line 40
def itunes_url
  ITUNES_URL_FORMAT % app_apple_id
end
rejected?() click to toggle source
# File lib/appleslice/email.rb, line 77
def rejected?
  review_status == :rejected
end
resolution_center_url() click to toggle source
# File lib/appleslice/email.rb, line 72
def resolution_center_url
  return nil unless rejected?
  @noko.css('#rejectionEmail a').first[:href]
end
review_status() click to toggle source
# File lib/appleslice/email.rb, line 26
def review_status
  if @body.include?('we are unable to post this version.')
    return :rejected
  end

  status_content = @noko.search('p').first.content.downcase
  status = STATUS_CONTENT_TO_STATUS[status_content]
  status || begin
    message = "Unknown email type - content: #{status_content}"
    message = "Unknown email type - content: #{status_content} - id: #{self.id}" if self.id
    raise UnknownEmailTypeError, message
  end
end
scheduled_maintenance?() click to toggle source
# File lib/appleslice/email.rb, line 81
def scheduled_maintenance?
  @body.include?("will undergo scheduled maintenance on ")
end

Private Instance Methods

find_td(prefix) click to toggle source
# File lib/appleslice/email.rb, line 86
def find_td(prefix)
  matches = @noko.search('td').select { |n|
    n.content.start_with?(prefix)
  }
  raise BadDataError, "Multiple matches for TD prefix #{prefix}" if matches.count > 1
  match = matches.first
  match.content.split(prefix)[-1]
end