Class: ThreeSixty::Account
- Inherits:
-
Core::Account
- Object
- Core::Account
- ThreeSixty::Account
- Defined in:
- lib/three-sixty/account.rb
Constant Summary
Constants inherited from Core::Account
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#report_generating_backoff ⇒ Object
readonly
Returns the value of attribute report_generating_backoff.
Instance Method Summary collapse
- #download_campaign_ids ⇒ Object
- #download_campaigns(campaign_ids) ⇒ Object
- #download_campaigns_to_file(campaign_ids, opts = {}) ⇒ Object
- #exclude_ip_list ⇒ Object
-
#initialize(client, opts = {}) ⇒ Account
constructor
A new instance of Account.
Methods inherited from Core::Account
#client_login, #get_all_objects, #get_campaign_id_list, #get_exclude_ip, #get_file_state, #get_info
Constructor Details
#initialize(client, opts = {}) ⇒ Account
Returns a new instance of Account.
11 12 13 14 15 16 17 18 |
# File 'lib/three-sixty/account.rb', line 11 def initialize(client, opts = {}) opts = .update(opts) @report_generating_backoff = opts[:report_generating_backoff] @logger = opts[:logger] || client.logger super(client) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/three-sixty/account.rb', line 9 def logger @logger end |
#report_generating_backoff ⇒ Object (readonly)
Returns the value of attribute report_generating_backoff.
9 10 11 |
# File 'lib/three-sixty/account.rb', line 9 def @report_generating_backoff end |
Instance Method Details
#download_campaign_ids ⇒ Object
20 21 22 |
# File 'lib/three-sixty/account.rb', line 20 def download_campaign_ids get_campaign_id_list["campaignIdList"] end |
#download_campaigns(campaign_ids) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/three-sixty/account.rb', line 24 def download_campaigns(campaign_ids) file_id = get_all_objects(campaign_ids)['fileId'] retry_number = 0 file_state = get_file_state(file_id) while (file_state["isGenerated"]) begin @logger.debug "Waiting for report #{file_id} on retry number #{retry_number}" sleep .call(retry_number) retry_number += 1 file_state = get_file_state(file_id) rescue TypeError => e e. = "Waiting too long to generate the report #{file_id}" # Re-raise with a better error message raise e end end @logger.info "Found file #{file_state["filePath"]} with size #{"%.2f" % (file_state["fileSize"] / 2**20)} MB" download_filestream(file_state["filePath"]) { |chunk| yield chunk } @logger.info "Finished downloading file #{file_state["filePath"]}" end |
#download_campaigns_to_file(campaign_ids, opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/three-sixty/account.rb', line 46 def download_campaigns_to_file(campaign_ids, opts = {}) download_dir = opts[:download_dir] || "/tmp" file = opts[:filename] || File.join(download_dir, "306_campaigns_" << SecureRandom.uuid << ".csv") filemode = opts[:encoding].nil? ? 'w' : "w:#{opts[:encoding]}" @logger.debug "Creating file #{file} with filemode #{filemode}" File.open(file, filemode) do |fs| download_campaigns(campaign_ids) do |content| fs.write content end end @logger.info "Finished downloading file to #{file}" file end |
#exclude_ip_list ⇒ Object
63 64 65 |
# File 'lib/three-sixty/account.rb', line 63 def exclude_ip_list get_exclude_ip["excludeIpList"] end |