Class: PowerReviews::Sync
- Inherits:
-
Object
- Object
- PowerReviews::Sync
- Defined in:
- lib/power_reviews/sync.rb
Overview
Downloads the ftp file and stores it in the correct location unzipped
Constant Summary collapse
Class Method Summary collapse
- .configure ⇒ Object
-
.execute ⇒ Object
Execute the necessary actions.
-
.start {|syncer, config| ... } ⇒ Object
Given the environment loads up the yaml file and creates a new instance.
Class Method Details
.configure ⇒ Object
51 52 53 |
# File 'lib/power_reviews/sync.rb', line 51 def configure @config ||= YAML::load(File.open("#{RAILS_ROOT}/config/power_reviews.yml"))[Rails.env] || {} end |
.execute ⇒ Object
Execute the necessary actions
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/power_reviews/sync.rb', line 20 def execute self.start do |client, config| zip_path = "#{Rails.root}/public/system/reviews.zip" unless client.done? FileUtils.mkdir_p(File.dirname(zip_path)) # we need the correct path to be setup client.copy_zip(zip_path) `cd #{File.dirname(zip_path)} && unzip -o #{zip_path}` client.done! end # zip up the powerreviews data tell the client to store it data_path = "#{RAILS_ROOT}/tmp/review_data.csv" File.open(data_path, 'w') do |f| f.puts PowerReviews::Feed.process end client.copy_data_feed(data_path) end end |
.start {|syncer, config| ... } ⇒ Object
Given the environment loads up the yaml file and creates a new instance
44 45 46 47 48 49 |
# File 'lib/power_reviews/sync.rb', line 44 def start config = self.configure syncer = PROTOCOLS[config.delete('protocol').intern].new(config) yield syncer, config syncer.cleanup end |