Class: Fastlane::Helper::GlotPressDownloader

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb

Overview

A helper class to download files from GlotPress with proper error handling and retry mechanism

Constant Summary collapse

AUTO_RETRY_SLEEP_TIME =
20
MAX_AUTO_RETRY_ATTEMPTS =
30

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, locale:, auto_retry: false) ⇒ GlotPressDownloader

Initialize a new GlotPressDownloader

Parameters:

  • url (String)

    The URL to download from

  • locale (String)

    The locale being downloaded (for logging purposes)

  • auto_retry (Boolean) (defaults to: false)

    Whether to automatically retry on rate limiting (429 errors)



21
22
23
24
25
26
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 21

def initialize(url:, locale:, auto_retry: false)
  @url = url
  @locale = locale
  @auto_retry = auto_retry
  @auto_retry_attempt_counter = 0
end

Instance Attribute Details

#auto_retryObject (readonly)

Returns the value of attribute auto_retry.



13
14
15
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 13

def auto_retry
  @auto_retry
end

#auto_retry_attempt_counterObject (readonly)

Returns the value of attribute auto_retry_attempt_counter.



13
14
15
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 13

def auto_retry_attempt_counter
  @auto_retry_attempt_counter
end

#localeObject (readonly)

Returns the value of attribute locale.



13
14
15
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 13

def locale
  @locale
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 13

def url
  @url
end

Class Method Details

.download(url:, locale:, auto_retry: false) {|String| ... } ⇒ Object

Convenience class method to download in a single call

Parameters:

  • url (String)

    The URL to download from

  • locale (String)

    The locale being downloaded (for logging purposes)

  • auto_retry (Boolean) (defaults to: false)

    Whether to automatically retry on rate limiting (429 errors)

Yields:

  • (String)

    The response body if the download was successful

Returns:

  • The result of the block if provided, or true/false indicating success if no block provided



37
38
39
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 37

def self.download(url:, locale:, auto_retry: false, &)
  new(url: url, locale: locale, auto_retry: auto_retry).download(&)
end

Instance Method Details

#download {|String| ... } ⇒ Object

Downloads data from GlotPress

Yields:

  • (String)

    The response body if the download was successful

Returns:

  • The result of the block if provided, or true/false indicating success if no block provided



46
47
48
49
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/glotpress_downloader.rb', line 46

def download(&)
  @auto_retry_attempt_counter = 0 # Reset counter only at start of download
  download_from_url(@url, &)
end