| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  | require "hbc/system_command" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  | module Hbc | 
					
						
							|  |  |  |   class DSL | 
					
						
							|  |  |  |     class Appcast | 
					
						
							| 
									
										
										
										
											2017-10-04 15:47:53 +02:00
										 |  |  |       attr_reader :uri, :checkpoint, :parameters | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 15:47:53 +02:00
										 |  |  |       def initialize(uri, **parameters) | 
					
						
							|  |  |  |         @uri        = URI(uri) | 
					
						
							|  |  |  |         @parameters = parameters | 
					
						
							|  |  |  |         @checkpoint = parameters[:checkpoint] | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |       def calculate_checkpoint | 
					
						
							| 
									
										
										
										
											2017-08-08 18:10:13 +02:00
										 |  |  |         curl_executable, *args = curl_args( | 
					
						
							| 
									
										
										
										
											2017-10-04 15:47:53 +02:00
										 |  |  |           "--compressed", "--location", "--fail", uri, | 
					
						
							| 
									
										
										
										
											2017-08-08 18:10:13 +02:00
										 |  |  |           user_agent: :fake | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         result = SystemCommand.run(curl_executable, args: args, print_stderr: false) | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         checkpoint = if result.success? | 
					
						
							| 
									
										
										
										
											2017-01-22 21:56:54 +01:00
										 |  |  |           processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}m, "") | 
					
						
							| 
									
										
										
										
											2017-01-22 04:28:33 +01:00
										 |  |  |           Digest::SHA2.hexdigest(processed_appcast_text) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           checkpoint: checkpoint, | 
					
						
							|  |  |  |           command_result: result, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def to_yaml | 
					
						
							| 
									
										
										
										
											2017-10-04 15:47:53 +02:00
										 |  |  |         [uri, parameters].to_yaml | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def to_s | 
					
						
							| 
									
										
										
										
											2017-10-04 15:47:53 +02:00
										 |  |  |         uri.to_s | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |