bamboozled_panda 0.0.4.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bamboozled_panda.rb +29 -35
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 563a27fd0076ac7712924748bc1ed3011fa6ff14
4
- data.tar.gz: 67281d2d4f5a8b39cf6be3d5f73e8d754bfec2ea
3
+ metadata.gz: f61c5d5917926b5e91354f0c390fd2d0bd88cf70
4
+ data.tar.gz: 53b7e47f2c91fffa17d26171c30fca191481981a
5
5
  SHA512:
6
- metadata.gz: 9e986b6b49b1b4f89c4547bf37f2a7379b86dc8fbdaed437a346654b56d6ccb44856ccf5d3b06385b8f6a43bc8cb888ac626018056cf8ee295792c8b0f21c135
7
- data.tar.gz: c3a96b4810c0722dc060b2b0001eaa0dcfb4e1f96a6164f77b877343451d8044983ca7b5976de4753a8a8cbfd0a9f0686f601f8d616301cc269972e2bc2d6f3d
6
+ metadata.gz: f246940cc9997d8f4747f1615a76041395bdae093a077a7121208535a57eb6f05ea0c9f2e440378bc87a81d6cbb0e3a07a5c54f1845b0323be6abf6501a495d1
7
+ data.tar.gz: 46407ecebe0e8873fd3b82a51babc1a613be964ed007d0718d6ca47fb3eac7dd677f38b71c30e3a619fdacd384e6c74f2b08f29f3fb2cb10179b819400765bdf
@@ -7,11 +7,17 @@ module BamboozledPanda
7
7
  # Panda Pay takes 1% + 2.9% + 30c per donation from credit/debit card donations
8
8
  # 1% + 25c per donation from ACH donations, but to get this we need to talk to them more
9
9
 
10
+ def self.set_key(secret_key)
11
+ @secret_key = secret_key
12
+ end
13
+
10
14
  # this is used to create a "pool" of money from which we will take when using `transfer_to_grant`
11
- def self.create_donation(amount, source, email, secret_key)
15
+ def self.create_donation(amount, source, email)
16
+ raise "Must set secret key with set_key" unless @secret_key
17
+
12
18
  uri = URI.parse("https://api.pandapay.io/v1/donations")
13
19
  request = Net::HTTP::Post.new(uri)
14
- request.basic_auth(secret_key, '')
20
+ request.basic_auth(@secret_key, '')
15
21
  request.set_form_data(
16
22
  "amount" => amount,
17
23
  "currency" => "usd",
@@ -33,10 +39,12 @@ module BamboozledPanda
33
39
  # I used the id of the California Community College Charity by default
34
40
  # This is where we actually send money to a charity
35
41
  # PandaPay does not send an email after this function
36
- def self.create_grant(amount, charity_id = "68-0412350", secret_key)
42
+ def self.create_grant(amount, charity_id = "68-0412350")
43
+ raise "Must set secret key with set_key" unless @secret_key
44
+
37
45
  uri = URI.parse("https://api.pandapay.io/v1/grants")
38
46
  request = Net::HTTP::Post.new(uri)
39
- request.basic_auth(secret_key, '')
47
+ request.basic_auth(@secret_key, '')
40
48
  request.set_form_data(
41
49
  "amount" => amount,
42
50
  "destination" => charity_id
@@ -53,10 +61,12 @@ module BamboozledPanda
53
61
  {code: response.code, body: JSON.parse(response.body)}
54
62
  end
55
63
 
56
- def self.create_customer(email, source_token, secret_key)
64
+ def self.create_customer(email, source_token)
65
+ raise "Must set secret key with set_key" unless @secret_key
66
+
57
67
  uri = URI.parse("https://api.pandapay.io/v1/customers")
58
68
  request = Net::HTTP::Post.new(uri)
59
- request.basic_auth(secret_key, '')
69
+ request.basic_auth(@secret_key, '')
60
70
  request.set_form_data(
61
71
  "email" => email,
62
72
  "source" => source
@@ -73,10 +83,12 @@ module BamboozledPanda
73
83
  {code: response.code, body: JSON.parse(response.body)}
74
84
  end
75
85
 
76
- def self.get(resource, secret_key)
86
+ def self.get(resource)
87
+ raise "Must set secret key with set_key" unless @secret_key
88
+
77
89
  uri = URI.parse("https://api.pandapay.io/v1/#{resource}")
78
90
  request = Net::HTTP::Get.new(uri)
79
- request.basic_auth(secret_key, '')
91
+ request.basic_auth(@secret_key, '')
80
92
 
81
93
  req_options = {
82
94
  use_ssl: uri.scheme == "https"
@@ -89,41 +101,23 @@ module BamboozledPanda
89
101
  response
90
102
  end
91
103
 
92
- def self.get_customers(secret_key)
93
- customers = get('customers', secret_key)
104
+ def self.get_customers
105
+ customers = get('customers')
94
106
  {code: customers.code, body: JSON.parse(customers.body)}
95
107
  end
96
108
 
97
- def self.get_grants(secret_key)
98
- grants = get('grants', secret_key)
109
+ def self.get_grants
110
+ grants = get('grants')
99
111
  {code: grants.code, body: JSON.parse(grants.body)}
100
112
  end
101
113
 
102
- def self.get_donations(secret_key)
103
- donations = get('donations', secret_key)
114
+ def self.get_donations
115
+ donations = get('donations')
104
116
  {code: donations.code, body: JSON.parse(donations.body)}
105
117
  end
106
118
 
107
- def self.get_available_funds(secret_key)
108
- donations = get('donations', secret_key)
109
- grants = get('grants', secret_key)
110
-
111
- total_donations = 0
112
- if donations.code == "200"
113
- donations_json = JSON.parse(donations.body)
114
- donations_json['data'].each do |donation|
115
- total_donations += donation['donation_after_fees']
116
- end
117
- end
118
-
119
- total_grants = 0
120
- if grants.code == "200"
121
- grants_json = JSON.parse(grants.body)
122
- grants_json['data'].each do |grant|
123
- total_grants += grant['amount'] if grant['status'] == 'pending'
124
- end
125
- end
126
-
127
- total_donations - total_grants
119
+ def self.get_available_funds
120
+ balance = get('balance')
121
+ (JSON.parse(balance.body))["total_unallocated_donations_amount"]
128
122
  end
129
123
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bamboozled_panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaiser Pister