Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

now delivers the data feed on every sync

  • Loading branch information...
commit 2271c666bfce19bacac1e6e4a26bc769f2979275 1 parent 8d76b7f
@beaucollins authored
View
4 generators/power_reviews/templates/config/power_reviews.yml
@@ -1,4 +1,4 @@
-# For retrieving the zip file from PowerReviews
+# For retrieving the zip file from PowerReviews and delivering your updated data feed
#
#
@@ -6,11 +6,13 @@ development:
protocol: cp
zip: test/k2skis.zip
done: test/k2skis_done.txt
+ datafeed: test/k2skis_data.zip
production:
protocol: ftp
zip: k2skis.zip
done: k2skis_done.txt
+ data_feed: k2skis_data.zip
# host: partners.powerreviews.com
# username: user
# password: passy
View
14 generators/power_reviews/templates/lib/tasks/power_reviews_tasks.rake
@@ -1,19 +1,13 @@
-# desc "Explaining what the task does"
-# task :power_reviews do
-# # Task goes here
-# end
namespace :power_reviews do
- desc "Generates the product data feed in csv format"
+ desc "Outputs the PowerReviews feed in CSV format"
task :feed => :environment do
- puts "Generating Power Reviews product feed"
- PowerReviews::Feed.process
- puts "Completed"
+ puts PowerReviews::Feed.process
end
- desc "Copy the zip file from the ftp and unpack it"
+ desc "Copy the zip file from the ftp and unpack it then deliver the product feed"
task :sync => :environment do
- puts "Fetching power review data"
+ puts "Syncing PowerReviews data"
PowerReviews::Sync.execute
puts "Completed"
end
View
5 lib/power_reviews/feed.rb
@@ -1,3 +1,5 @@
+require "faster_csv"
+
module PowerReviews
# Collects the feed data then outputs to CSV file for delivery to the power review peeps
@@ -28,8 +30,7 @@ def self.process
end
def to_csv
- require 'fastercsv'
- FasterCSV.open("#{RAILS_ROOT}/tmp/power_reviews.csv", 'w') do |csv|
+ @csv ||= FasterCSV.generate do |csv|
csv << FeedItem.field_names
@items.each do |item|
csv << item.values
View
3  lib/power_reviews/protocols/base.rb
@@ -24,6 +24,9 @@ def copy_zip(to)
puts 'This is the base class'
end
+ def copy_data_feed(from)
+ puts 'This is the base class'
+ end
# do any cleanup necessary
def cleanup
View
4 lib/power_reviews/protocols/cp.rb
@@ -16,6 +16,10 @@ def copy_zip(to)
FileUtils.cp(@config['zip'], to)
end
+ def copy_data_feed(from)
+ # do nothing, leave the zip where it is
+ end
+
end
end
end
View
5 lib/power_reviews/protocols/ftp.rb
@@ -20,6 +20,11 @@ def copy_zip(to)
client.getbinaryfile(@config['zip'], to)
end
+ # Puts the data_feed on the specified ftp server
+ def copy_data_feed(from)
+ client.putbinaryfile(@config['data_feed'])
+ end
+
# do any cleanup necessary
def cleanup
@client.close
View
9 lib/power_reviews/sync.rb
@@ -1,6 +1,7 @@
require 'power_reviews/protocols/base'
require 'power_reviews/protocols/cp'
require 'power_reviews/protocols/ftp'
+require 'power_reviews/feed'
module PowerReviews
# Downloads the ftp file and stores it in the correct location unzipped
@@ -27,6 +28,14 @@ def self.execute
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
+ `cd #{File.dirname(data_path)} && zip #{config['data_feed']}`
+ client.copy_data_feed("#{RAILS_ROOT}/tmp/#{config['data_feed']}")
+
end
end
View
4 power_reviews.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{power_reviews}
- s.version = "0.1.1"
+ s.version = "0.2.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Beau Collins"]
- s.date = %q{2009-09-29}
+ s.date = %q{2009-10-21}
s.description = %q{Tools and library for integrating Power Reviews into a rails website.}
s.email = %q{beaucollins@gmail.com}
s.extra_rdoc_files = [
View
1  test/power_reviews_test.rb
@@ -2,7 +2,6 @@
require 'power_reviews'
class PowerReviewsTest < ActiveSupport::TestCase
- # Replace this with your real tests.
should "have itemdata with correct attributes" do
item = PowerReviews::FeedItem.new
assert PowerReviews::FeedItem::FIELDS.is_a?(Array)
Please sign in to comment.
Something went wrong with that request. Please try again.