lib/paypal/report.rb in paypal-report-0.1.0 vs lib/paypal/report.rb in paypal-report-0.1.1
- old
+ new
@@ -1,20 +1,21 @@
require 'net/https'
require 'uri'
require 'builder'
require 'rexml/document'
+require 'date'
module Paypal
class Report
API_URL = 'https://payments-reports.paypal.com/reportingengine'
def initialize(user, password, vendor, partner = 'PayPalUK')
@user, @password, @vendor, @partner = user, password, vendor, partner
end
-
+
#high level functions
- def daily(time = Time.now, page_size = 50)
+ def daily(time = Date.today, page_size = 50)
time = time.strftime("%Y-%m-%d") unless time.is_a?(String)
report_id = run_report_request('DailyActivityReport', {'report_date' => time}, page_size)
meta_data = get_meta_data_request(report_id)
@@ -22,10 +23,41 @@
meta_data["numberOfPages"].to_i.times do |page_num|
data += get_data_request(report_id, page_num + 1) #it's zero indexed
end
data
end
-
+
+ def monthly(start_date, end_date = Date.today, page_size = 50)
+ start_date = Date.parse(start_date) if start_date.is_a?(String)
+ start_date = start_date.to_date if start_date.is_a?(Time)
+
+ end_date = Date.parse(end_date) if end_date.is_a?(String)
+ end_date = end_date.to_date if end_date.is_a?(Time)
+
+ data = []
+ while(start_date <= end_date)
+ puts start_date.strftime("%Y-%m-%d")
+ data += daily(start_date, page_size)
+ start_date = start_date.next_day
+ end
+ data
+ end
+
+ def transaction_summary(start_date, end_date = Time.now, page_size = 50)
+ start_date = start_date.strftime("%Y-%m-%d 00:00:00") unless start_date.is_a?(String)
+ end_date = end_date.strftime("%Y-%m-%d 23:59:59") unless end_date.is_a?(String)
+ report_id = run_report_request('TransactionSummaryReport', {'start_date' => start_date, 'end_date' => end_date}, page_size)
+
+ meta_data = get_meta_data_request(report_id)
+
+ data = []
+ meta_data["numberOfPages"].to_i.times do |page_num|
+ data += get_data_request(report_id, page_num + 1) #it's zero indexed
+ end
+ data
+ end
+
+
#low level functions
def run_report_request(report_name, report_params = {}, page_size = 50)
response = request 'runReportRequest' do |xml|
xml.reportName report_name
report_params.each do |name, value|