83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/codes/itunes_connect.rb', line 83
def display(args)
Helper.log.info 'Displaying remaining number of codes promo'
fetch_app_data args
output_file_path = Pathname.new(args[:output_file_path]) if args[:output_file_path]
output_file_path ||= Pathname.new(File.join(Dir.getwd, "#{@app_identifier || @app_id}_codes_info.txt"))
fail 'Insufficient permissions to write to output file'.red if File.exist?(output_file_path) && !File.writable?(output_file_path)
visit PROMO_URL.gsub('[[app_id]]', @app_id.to_s).gsub('[[platform]]', @platform)
begin
text_fields = wait_for_elements('input[type=text]')
rescue
raise "Could not open details page for app #{app_identifier}. Are you sure you are using the correct apple account and have access to this app?".red
end
fail 'There should only be a single text input field to specify the number of codes'.red unless text_fields.count == 1
remaining_divs = wait_for_elements('div#codes_0')
fail 'There should only be a single text div containing the number of remaining codes'.red unless remaining_divs.count == 1
remaining = remaining_divs.first.text.split(' ')[0]
bytes_written = File.write(output_file_path.to_s, remaining, mode: 'a+')
Helper.log.warn 'Could not write your codes to the codes_info.txt file, but you can still access them from iTunes Connect later' if bytes_written == 0
Helper.log.info "Added information of quantity of remaining codes to '#{output_file_path}'".green unless bytes_written == 0
puts remaining
end
|