paypal-report 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # PayPal Report
2
2
 
3
3
  A little lightweight wrapper for [Paypal's Report API](https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_Reporting_Guide.pdf).
4
- All three major API methods `run_report_request`, `get_meta_data_request` and `get_data_request` are exposed. On top of that, higher methods provide extra functionality. For now, this only _daily_ reports.
4
+ All three major API methods `run_report_request`, `get_meta_data_request` and `get_data_request` are exposed. On top of that, higher methods provide extra functionality. For now, this _daily_, _monthly_ and _summery_ reports.
5
5
 
6
6
 
7
7
  ## Usage
@@ -13,7 +13,7 @@ Example usage, receiving all report from today:
13
13
 
14
14
  As an example, the gem provides a small command line tool to easily get today's earnings. Usage:
15
15
 
16
- paypal-report-daily -a <partner> -v <vendor> -u <user> -p <password>
16
+ paypal-report daily -a <partner> -v <vendor> -u <user> -p <password>
17
17
 
18
18
 
19
19
  ## Todo
@@ -21,7 +21,7 @@ Gem is in an early stage, so lots of stuff to do:
21
21
 
22
22
  - introduce more higher level functions (e.g. period)
23
23
  - add tests
24
- - add examples
24
+ - add more examples
25
25
 
26
26
 
27
27
  ## Contributing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bin/paypal-report ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'date'
4
+ require 'optparse'
5
+ require 'paypal/report'
6
+
7
+ partner = vendor = user = password = nil
8
+ time = Date.today.prev_day.strftime("%Y-%m-%d")
9
+
10
+ prev_month = Date.today.prev_month
11
+ start_date = Date.parse("#{prev_month.year}-#{prev_month.month}-01")
12
+ next_month = start_date.next_month.prev_day
13
+ end_date = Date.parse("#{prev_month.year}-#{prev_month.month}-#{next_month.day}")
14
+
15
+ start_date = start_date.strftime("%Y-%m-%d 00:00:00")
16
+ end_date = end_date.strftime("%Y-%m-%d 23:59:59")
17
+
18
+ opts = ARGV.options do |opts|
19
+ opts.on("-p", "--password=PASSWORD", "Password - required!") { |p| password = p}
20
+ opts.on("-u", "--user=USER", "User - default: #{user}") { |u| user = u}
21
+ opts.on("-v", "--vendor=VENDOR", "Vendor - default: #{vendor}") { |v| vendor = v}
22
+ opts.on("-a", "--partner=PARTNER", "Partner - default: #{partner}") { |a| partner = a}
23
+
24
+ opts.on("-d", "--date=DATE", "Date - default: #{time}") { |t| time = t}
25
+
26
+ opts.on("-f", "--start_date=DATE", "Date - default: #{start_date}") { |t| start_date = t}
27
+ opts.on("-t", "--end_date=DATE", "Date - default: #{end_date}") { |t| end_date = t}
28
+
29
+ opts.on_tail("-h", "--help", "Show this help message.") { $stderr.puts opts; exit }
30
+ end
31
+ opts.parse!
32
+
33
+ abort "No password given: \n #{opts}" unless password
34
+
35
+ api = Paypal::Report.new(user, password, vendor, partner)
36
+
37
+ if ARGV.include?('daily')
38
+ amount = 0
39
+ report = api.daily(time, 5000)
40
+ report.each do |row|
41
+ amount += row[6].to_i
42
+ end
43
+
44
+ puts "Report for #{time}: #{report.size} Entries - #{amount / 100.0} EUR"
45
+ end
46
+
47
+ if ARGV.include?('monthly')
48
+ amount = 0
49
+ report = api.monthly(start_date, end_date, 5000)
50
+ report.each do |row|
51
+ amount += row[6].to_i
52
+ end
53
+
54
+ puts "Report for #{start_date} - #{end_date}: #{report.size} Entries - #{amount / 100.0} EUR"
55
+ end
data/lib/paypal/report.rb CHANGED
@@ -2,6 +2,7 @@ require 'net/https'
2
2
  require 'uri'
3
3
  require 'builder'
4
4
  require 'rexml/document'
5
+ require 'date'
5
6
 
6
7
  module Paypal
7
8
  class Report
@@ -10,9 +11,9 @@ module Paypal
10
11
  def initialize(user, password, vendor, partner = 'PayPalUK')
11
12
  @user, @password, @vendor, @partner = user, password, vendor, partner
12
13
  end
13
-
14
+
14
15
  #high level functions
15
- def daily(time = Time.now, page_size = 50)
16
+ def daily(time = Date.today, page_size = 50)
16
17
  time = time.strftime("%Y-%m-%d") unless time.is_a?(String)
17
18
  report_id = run_report_request('DailyActivityReport', {'report_date' => time}, page_size)
18
19
 
@@ -24,7 +25,38 @@ module Paypal
24
25
  end
25
26
  data
26
27
  end
27
-
28
+
29
+ def monthly(start_date, end_date = Date.today, page_size = 50)
30
+ start_date = Date.parse(start_date) if start_date.is_a?(String)
31
+ start_date = start_date.to_date if start_date.is_a?(Time)
32
+
33
+ end_date = Date.parse(end_date) if end_date.is_a?(String)
34
+ end_date = end_date.to_date if end_date.is_a?(Time)
35
+
36
+ data = []
37
+ while(start_date <= end_date)
38
+ puts start_date.strftime("%Y-%m-%d")
39
+ data += daily(start_date, page_size)
40
+ start_date = start_date.next_day
41
+ end
42
+ data
43
+ end
44
+
45
+ def transaction_summary(start_date, end_date = Time.now, page_size = 50)
46
+ start_date = start_date.strftime("%Y-%m-%d 00:00:00") unless start_date.is_a?(String)
47
+ end_date = end_date.strftime("%Y-%m-%d 23:59:59") unless end_date.is_a?(String)
48
+ report_id = run_report_request('TransactionSummaryReport', {'start_date' => start_date, 'end_date' => end_date}, page_size)
49
+
50
+ meta_data = get_meta_data_request(report_id)
51
+
52
+ data = []
53
+ meta_data["numberOfPages"].to_i.times do |page_num|
54
+ data += get_data_request(report_id, page_num + 1) #it's zero indexed
55
+ end
56
+ data
57
+ end
58
+
59
+
28
60
  #low level functions
29
61
  def run_report_request(report_name, report_params = {}, page_size = 50)
30
62
  response = request 'runReportRequest' do |xml|
@@ -2,13 +2,13 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = "paypal-report"
6
- s.version = File.read("VERSION").to_s
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = ["SoundCloud", "Tobias Bielohlawek"]
9
- s.email = %q{tobi@soundcloud.com}
10
- s.homepage = "http://github.com/rngtng/paypal-report"
11
- s.summary = %q{A little lightweight wrapper for Paypal's Report API.}
5
+ s.name = "paypal-report"
6
+ s.version = File.read("VERSION").to_s
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["SoundCloud", "Tobias Bielohlawek"]
9
+ s.email = %q{tobi@soundcloud.com}
10
+ s.homepage = "http://github.com/rngtng/paypal-report"
11
+ s.summary = %q{A little lightweight wrapper for Paypal's Report API.}
12
12
 
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: paypal-report
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - SoundCloud
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-25 00:00:00 +02:00
15
- default_executable:
14
+ date: 2011-05-30 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: builder
@@ -28,7 +27,7 @@ dependencies:
28
27
  description:
29
28
  email: tobi@soundcloud.com
30
29
  executables:
31
- - paypal-report-daily
30
+ - paypal-report
32
31
  extensions: []
33
32
 
34
33
  extra_rdoc_files: []
@@ -41,11 +40,10 @@ files:
41
40
  - README.md
42
41
  - Rakefile
43
42
  - VERSION
44
- - bin/paypal-report-daily
43
+ - bin/paypal-report
45
44
  - lib/paypal.rb
46
45
  - lib/paypal/report.rb
47
46
  - paypal-report.gemspec
48
- has_rdoc: true
49
47
  homepage: http://github.com/rngtng/paypal-report
50
48
  licenses: []
51
49
 
@@ -69,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
67
  requirements: []
70
68
 
71
69
  rubyforge_project:
72
- rubygems_version: 1.6.2
70
+ rubygems_version: 1.8.4
73
71
  signing_key:
74
72
  specification_version: 3
75
73
  summary: A little lightweight wrapper for Paypal's Report API.
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'paypal/report'
5
-
6
- partner = vendor = user = password = nil
7
- time = (Time.now - 60*60*24).strftime("%Y-%m-%d")
8
-
9
- opts = ARGV.clone.options do |opts|
10
- opts.on("-p", "--password=PASSWORD", "Password - required!") { |p| password = p}
11
- opts.on("-d", "--date=DATE", "Date - default: #{time}") { |t| time = t}
12
- opts.on("-u", "--user=USER", "User - default: #{user}") { |u| user = u}
13
- opts.on("-v", "--vendor=VENDOR", "Vendor - default: #{vendor}") { |v| vendor = v}
14
- opts.on("-a", "--partner=PARTNER", "Partner - default: #{partner}") { |a| partner = a}
15
-
16
- opts.on_tail("-h", "--help", "Show this help message.") { $stderr.puts opts; exit }
17
- end
18
- opts.parse!
19
-
20
- abort "No password given: \n #{opts}" unless password
21
-
22
- api = Paypal::Report.new(user, password, vendor, partner)
23
-
24
- amount = 0
25
- report = api.daily(time, 5000)
26
- report.each do |row|
27
- amount += row[6].to_i
28
- end
29
-
30
- puts "Report for #{time}: #{report.size} Entries - #{amount / 100.0} EUR"