bamboozled_panda 0.0.2 → 0.0.3

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 +77 -2
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9f46a46814694e243f1dd816aa62d3f774d8516
4
- data.tar.gz: a8ee6f3e10384de217c656e09754331153a683b6
3
+ metadata.gz: dfe3e06d8db0f6c50332003deae1eaa01f441471
4
+ data.tar.gz: b5fa1f6aa3019d656aa6fc0cd1efe93edd13d4e1
5
5
  SHA512:
6
- metadata.gz: 08cd8d0a8a1f7244d0647fce0a5f8643c9d84f96b49075346efbd85f66825e5e88d1fac3596faa10e745464e4bcb74c2558a44eed393abe9eb04c35f12efbb54
7
- data.tar.gz: a818f4bc98b2fa6d3b60f9d79aa65a127e9386e9a992dc6c79216d4ebd9ccf4e554689a45da46f6f32581c6bf70d20f218120200e5a3b91199154f16f792ac14
6
+ metadata.gz: 0c568b3fcd77808113f82f4936d2186c33a77ef8be0ef37c4b94d9c1540a12e37d2d4159773849a39cb764b3c1dc3fba847a3e3b3ea019070cbb0caaa955ff36
7
+ data.tar.gz: ffdc6fab4b74a467131ebfe4de4d70367f894a4ded3fbaf0e6177c65b4ea23d22489e992eb1352f3eed3e2b0a2d92f4a864e2eabf6cd5d80034b3774ef22ea6e
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  require 'net/http'
2
3
  require 'uri'
3
4
 
@@ -26,7 +27,7 @@ module BamboozledPanda
26
27
  http.request(request)
27
28
  end
28
29
 
29
- [response.code, response.body]
30
+ {code: response.code, body: JSON.parse(response.body)}
30
31
  end
31
32
 
32
33
  # I used the id of the California Community College Charity by default
@@ -49,6 +50,80 @@ module BamboozledPanda
49
50
  http.request(request)
50
51
  end
51
52
 
52
- [response.code, response.body]
53
+ {code: response.code, body: JSON.parse(response.body)}
54
+ end
55
+
56
+ def self.create_customer(email, source_token, secret_key)
57
+ uri = URI.parse("https://api.pandapay.io/v1/customers")
58
+ request = Net::HTTP::Post.new(uri)
59
+ request.basic_auth(secret_key, '')
60
+ request.set_form_data(
61
+ "email" => email,
62
+ "source" => source
63
+ )
64
+
65
+ req_options = {
66
+ use_ssl: uri.scheme == "https"
67
+ }
68
+
69
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
70
+ http.request(request)
71
+ end
72
+
73
+ {code: response.code, body: JSON.parse(response.body)}
74
+ end
75
+
76
+ def self.get(resource, secret_key)
77
+ uri = URI.parse("https://api.pandapay.io/v1/#{resource}")
78
+ request = Net::HTTP::Get.new(uri)
79
+ request.basic_auth(secret_key, '')
80
+
81
+ req_options = {
82
+ use_ssl: uri.scheme == "https"
83
+ }
84
+
85
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
86
+ http.request(request)
87
+ end
88
+
89
+ response
90
+ end
91
+
92
+ def self.get_customers(secret_key)
93
+ customers = get('customers', secret_key)
94
+ {code: customers.code, body: JSON.parse(customers.body)}
95
+ end
96
+
97
+ def self.get_grants(secret_key)
98
+ grants = get('grants', secret_key)
99
+ {code: grants.code, body: JSON.parse(grants.body)}
100
+ end
101
+
102
+ def self.get_donations(secret_key)
103
+ donations = get('donations', secret_key)
104
+ {code: donations.code, body: JSON.parse(donations.body)}
105
+ end
106
+
107
+ def self.get_unallocated_donation_amount(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
53
128
  end
54
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bamboozled_panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaiser Pister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-28 00:00:00.000000000 Z
11
+ date: 2017-08-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple, easy to use, ruby wrapper for the Panda Pay API
14
14
  email: pisterk@gmail.com