slidepay 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf7619f4c541983edb493fb3caa136c4c1eb1d4
4
- data.tar.gz: 3af9338097e72789975c082244ffdce80af315b9
3
+ metadata.gz: 4fd5c93874d452c096489e21fc5e21299a402b6d
4
+ data.tar.gz: 831e67be3a2080f47b5d3bac38ca22c5989ddea7
5
5
  SHA512:
6
- metadata.gz: 17a174b5c5e057bb323fded70397604d7c788821929495ac917ad75d2dfb0ab67ec88d9e63b75b8e79672213521ccb46be8b0a153528fb2fea4e82eeb432be43
7
- data.tar.gz: 908c1acf7987fd88dda966228a5a67c8bb6e46ad00043ae61fbd5e06928b01a88e41040ce2016df71dd0975a9bb5e7545452521dffac58f9712562fed436c1b2
6
+ metadata.gz: 6c58e8724d17eb29812939567f60abcffea199e703842dfe3edfd61ba7761eb2da8a5fe748ab845ead0d48b77cf915e329303a829cc6c23b8fd75ad0b8664c89
7
+ data.tar.gz: 80276a5604efaa119532f372e4bcad0f6b4efd4cf557ccf03c0f81e9e79c257daf1f723891a5d0e9da5d7879fb6cff7eed6c9361875377076c172638139cc853
data/Guardfile CHANGED
@@ -6,4 +6,5 @@ guard 'rspec', :version => 2 do
6
6
  watch(%r{^lib/.+\.rb$})
7
7
  watch(%r{^lib/slidepay/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
8
  watch(%r{^lib/slidepay/resources/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch(%r{^lib/slidepay/reports/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
10
  end
data/README.md CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/slidepay.png)](http://badge.fury.io/rb/slidepay) [![Build Status](https://travis-ci.org/SlidePay/slidepay-ruby-sdk.png)](https://travis-ci.org/SlidePay/slidepay-ruby-sdk) [![Code Climate](https://codeclimate.com/github/SlidePay/slidepay-ruby-sdk.png)](https://codeclimate.com/github/SlidePay/slidepay-ruby-sdk)
6
6
 
7
- First version of the SlidePay Ruby SDK
7
+ ## Using the Gem
8
+
9
+ Add the following line to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'slidepay'
13
+ ```
8
14
 
9
15
  ## Dependencies
10
16
 
@@ -191,6 +197,62 @@ p.refund()
191
197
  SlidePay.post(path: 'payment/refund/#{payment_id}')
192
198
  ```
193
199
 
200
+ ## Reports
201
+
202
+ The SlidePay reports allow broader views into a user's data. The reports retrieve this data based on constraints supplied in the Report class constructor.
203
+
204
+ We currently expose two reports through the Ruby library: an Account Report and a Payment Report.
205
+
206
+ ### Account Report
207
+
208
+ The account report gives a view into the current state of the SlidePay user's account.
209
+
210
+ The only valid constraint for this report is on location_id, and may be supplied in the ways illustrated below.
211
+
212
+ ```ruby
213
+
214
+ # Pass the location_id constraint in as an integer
215
+ account_report = SlidePay::AccountReport.new(14)
216
+ account_report.retrieve()
217
+
218
+ # Pass the location_id constraint in as a string
219
+ account_report = SlidePay::AccountReport.new("14")
220
+ account_report.retrieve()
221
+
222
+ # Pass the location_id constraint in as a hash
223
+ account_report = SlidePay::AccountReport.new(location_id: 14)
224
+ account_report.retrieve()
225
+
226
+ ```
227
+
228
+ ### Payment Report
229
+
230
+ The payment report gives a detailed view into the past payments for an account. The report can be constrained in many dimensions using one or more [```search_filters```](https://getcube.atlassian.net/wiki/display/CDP/search_filter+and+search_filter_array).
231
+
232
+ Search filters are optional, should be supplied on object instantiation, and can be supplied through a hash (if there is only one), or as an array (for > 0 search filters).
233
+
234
+ ```ruby
235
+
236
+ # Supply no search filter to retrieve all payment data accessible by the currently authenticated account
237
+ payment_report = SlidePay::PaymentReport.new()
238
+ payment_report.retrieve()
239
+
240
+ # Supply a single search filter as a hash
241
+ single_time_search_filter = {field: "created", condition: "greater_than", value: "12/12/2013"}
242
+ payment_report = SlidePay::PaymentReport.new(single_time_search_filter)
243
+ payment_report.retrieve()
244
+
245
+ # Supply multiple search filters in an array
246
+ search_filter_array = []
247
+ search_filter_array.push({field: "created", condition: "greater_than", value: "10/12/2013"})
248
+ search_filter_array.push({field: "created", condition: "less_than", value: "12/12/2013"})
249
+ search_filter_array.push({field: "amount", condition: "greater_than", value: 1.01})
250
+
251
+ payment_report = SlidePay::PaymentReport.new(search_filter_array)
252
+ payment_report.retrieve()
253
+
254
+ ```
255
+
194
256
  ## Testing
195
257
 
196
258
  ### Basics
data/TODO.md ADDED
@@ -0,0 +1,12 @@
1
+ [ ] Reports
2
+ ---------------
3
+ [ ] Account
4
+ [ ] Payment
5
+
6
+ [ ] ACH
7
+ ---------------
8
+ [ ] Retrieval
9
+ [ ] Settlement
10
+ [ ] Balance
11
+ -- Speculative
12
+ [ ] Credit
data/lib/slidepay.rb CHANGED
@@ -21,6 +21,14 @@ require "slidepay/resources/customer"
21
21
  require "slidepay/resources/location"
22
22
  require "slidepay/resources/company"
23
23
 
24
+ # Reporting
25
+ require "slidepay/reports/report"
26
+ require "slidepay/reports/put_report"
27
+ require "slidepay/reports/post_report"
28
+ require "slidepay/reports/account_report"
29
+ require "slidepay/reports/payment_report"
30
+
31
+
24
32
  module SlidePay
25
33
  class << self
26
34
  attr_accessor :token, :api_key, :endpoint
@@ -0,0 +1,17 @@
1
+ module SlidePay
2
+ class AccountReport < PostReport
3
+ def initialize(options={})
4
+ @url = "report/account"
5
+
6
+ if options.is_a? String or options.is_a? Integer
7
+ @sfa = [{field: "location_id", condition: "equals", value: options}]
8
+ elsif options['location_id'] != nil or options[:location_id] != nil
9
+ @sfa = [{field: "location_id", condition: "equals", value: options['location_id'] || options[:location_id]}]
10
+ else
11
+ @sfa = []
12
+ end
13
+
14
+ super(@sfa)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module SlidePay
2
+ class PaymentReport < PostReport
3
+ def initialize(options={})
4
+ @url = "report/payment"
5
+
6
+ super(options)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ module SlidePay
2
+ class PostReport < Report
3
+ def initialize(options={})
4
+ @report_type = :post
5
+
6
+ super(options)
7
+ end
8
+
9
+ private
10
+
11
+ def data_from_sfa(options={})
12
+ return {
13
+ csv: options[:csv] || false,
14
+ email_address: options[:email_address] || nil,
15
+ html: options[:html] || false,
16
+ raw_data: options[:raw_data] || true,
17
+ sfa: @sfa
18
+ }.to_json
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module SlidePay
2
+ class PutReport < Report
3
+ def initialize(options={})
4
+ @report_type = :put
5
+
6
+ super(options)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,53 @@
1
+ module SlidePay
2
+ class Report < Hash
3
+ attr_accessor :sfa
4
+ attr_accessor :url
5
+ attr_accessor :report_type
6
+
7
+ attr_accessor :token, :api_key, :endpoint
8
+
9
+ def initialize(search_params={})
10
+ # Initialize search_filter_arrays
11
+ if search_params.is_a? Hash
12
+ @sfa = [search_params]
13
+ elsif search_params.is_a? Array
14
+ @sfa = search_params
15
+ else
16
+ @sfa = []
17
+ end
18
+ end
19
+
20
+ def retrieve(options={})
21
+ token = @token || options[:token]
22
+ api_key = @api_key || options[:api_key]
23
+ endpoint = @endpoint || options[:endpoint]
24
+
25
+ if @report_type == :put
26
+ response = SlidePay.put(path: @url, data: data_from_sfa, token: token, api_key: api_key, endpoint: endpoint)
27
+ elsif @report_type == :post
28
+ response = SlidePay.post(path: @url, data: data_from_sfa, token: token, api_key: api_key, endpoint: endpoint)
29
+ end
30
+
31
+ if response.was_successful?
32
+ populate_from_response(response)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ # Override this for specialty reports
39
+ def data_from_sfa
40
+ return @sfa.to_json
41
+ end
42
+
43
+ def populate_from_response(response)
44
+ if response.data.instance_of? Array
45
+ self.merge! response.data.first
46
+ elsif response.data.instance_of? Hash
47
+ self.merge! response.data
48
+ else
49
+ raise Exception.new("Report was unsuccessful.")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module SlidePay
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -0,0 +1,27 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'spec'))
3
+
4
+ require 'multi_json'
5
+ require 'slidepay'
6
+ require 'spec_helper'
7
+
8
+ include SlidePay
9
+
10
+ SlidePay.configure(development: true)
11
+ SlidePay.api_key = ENV["api_key"]
12
+
13
+ RestClient.proxy = "http://127.0.0.1:8888"
14
+
15
+
16
+ puts "Retrieving account report with no search filters:"
17
+ puts "======================================================================"
18
+
19
+ account_report = SlidePay::AccountReport.new(14)
20
+ account_report.retrieve()
21
+
22
+ if account_report.empty?
23
+ puts "Account report returned empty nothing."
24
+ else
25
+ puts "Account report: "
26
+ puts "#{account_report}"
27
+ end
@@ -0,0 +1,27 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'spec'))
3
+
4
+ require 'multi_json'
5
+ require 'slidepay'
6
+ require 'spec_helper'
7
+
8
+ include SlidePay
9
+
10
+ SlidePay.configure(development: true)
11
+ SlidePay.api_key = ENV["api_key"]
12
+
13
+ # RestClient.proxy = "http://127.0.0.1:8888"
14
+
15
+
16
+ puts "Retrieving payment report with no search filters:"
17
+ puts "======================================================================"
18
+
19
+ payment_report = SlidePay::PaymentReport.new([field: "created", condition: "greater_than", value: "12/12/2013"])
20
+ payment_report.retrieve()
21
+
22
+ if payment_report.empty?
23
+ puts "Payment report returned nothing."
24
+ else
25
+ puts "Payment report: "
26
+ puts "#{payment_report}"
27
+ end
@@ -0,0 +1,68 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::AccountReport do
5
+ def request_params(data)
6
+ return { path: "report/account", data: data, token: nil, api_key: nil, endpoint: nil }
7
+ end
8
+
9
+ def sfa(location_id)
10
+ [field: "location_id", condition: "equals", value: location_id]
11
+ end
12
+
13
+ def search_filter_data(location_id)
14
+ return {
15
+ csv: false,
16
+ email_address: nil,
17
+ html: false,
18
+ raw_data: true,
19
+ sfa: sfa(location_id)
20
+ }.to_json
21
+ end
22
+
23
+
24
+ it "should be a post report" do
25
+ r = SlidePay::AccountReport.new()
26
+ expect(r.report_type).to eq(:post)
27
+ end
28
+
29
+ it "should be retrieve from the account_report url" do
30
+ r = SlidePay::AccountReport.new()
31
+ expect(r.url).to eq('report/account')
32
+ end
33
+
34
+ describe "initialize" do
35
+ it "should interpret a string as a location_id" do
36
+ location_id = "12"
37
+ r = SlidePay::AccountReport.new(location_id)
38
+ request_info = request_params(search_filter_data(location_id))
39
+ SlidePay.should_receive(:post).with(request_info).and_return(a_response_object)
40
+ r.retrieve()
41
+ end
42
+
43
+ it "should interpret an integer as a location_id" do
44
+ location_id = 12
45
+ r = SlidePay::AccountReport.new(location_id)
46
+ request_info = request_params(search_filter_data(location_id))
47
+ SlidePay.should_receive(:post).with(request_info).and_return(a_response_object)
48
+ r.retrieve()
49
+ end
50
+
51
+ it "should take a hash with a string for a key" do
52
+ location_id = 12
53
+ r = SlidePay::AccountReport.new({ "location_id" => location_id })
54
+ request_info = request_params(search_filter_data(location_id))
55
+ SlidePay.should_receive(:post).with(request_info).and_return(a_response_object)
56
+ r.retrieve()
57
+ end
58
+
59
+ it "should take a hash with a symbol for a key" do
60
+ location_id = 12
61
+ r = SlidePay::AccountReport.new(location_id: location_id)
62
+ request_info = request_params(search_filter_data(location_id))
63
+ SlidePay.should_receive(:post).with(request_info).and_return(a_response_object)
64
+ r.retrieve()
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,14 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::PaymentReport do
5
+ it "should be a post report" do
6
+ r = SlidePay::PaymentReport.new([])
7
+ expect(r.report_type).to eq(:post)
8
+ end
9
+
10
+ it "should be retrieve from the payment_report url" do
11
+ r = SlidePay::PaymentReport.new([])
12
+ expect(r.url).to eq('report/payment')
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::PostReport do
5
+ def sfa
6
+ [field: "created", condition: "greater_than", value: "12/12/2013"]
7
+ end
8
+
9
+ def search_filter_data
10
+ return {
11
+ csv: false,
12
+ email_address: nil,
13
+ html: false,
14
+ raw_data: true,
15
+ sfa: sfa
16
+ }.to_json
17
+ end
18
+
19
+ it "should have a report_type" do
20
+ b = SlidePay::PostReport.new([])
21
+ expect(b.report_type).to eq(:post)
22
+ end
23
+
24
+ it "should use a special type of report data structure" do
25
+ b = SlidePay::PostReport.new(sfa)
26
+ SlidePay.should_receive(:post).with(path: nil, data: search_filter_data, token: nil, api_key: nil, endpoint: nil).and_return(a_response_object)
27
+ b.retrieve()
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ describe SlidePay::PutReport do
5
+ it "should have a report_type" do
6
+ b = SlidePay::PutReport.new([])
7
+ expect(b.report_type).to eq(:put)
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ require "slidepay"
2
+ require "spec_helper"
3
+
4
+ def example_search_filter
5
+ return { field: "created", condition: "equals", value: "12/01/2013"}
6
+ end
7
+
8
+ describe SlidePay::Report do
9
+ it "should accept an array on instantiation" do
10
+ b = SlidePay::Report.new([])
11
+ expect(b.sfa).to eq([])
12
+ end
13
+
14
+ it "should accept a hash on instantiation" do
15
+ b = SlidePay::Report.new(example_search_filter)
16
+ expect(b.sfa).to eq([example_search_filter])
17
+ end
18
+
19
+ describe "retrieve" do
20
+ it "should make a put request if report_type is :put" do
21
+ b = SlidePay::Report.new(example_search_filter)
22
+ b.report_type = :put
23
+
24
+ SlidePay.should_receive(:put).and_return(a_response_object)
25
+ b.retrieve()
26
+ end
27
+
28
+ it "should make a post request if report_type is :post" do
29
+ b = SlidePay::Report.new(example_search_filter)
30
+ b.report_type = :post
31
+
32
+ SlidePay.should_receive(:post).and_return(a_response_object)
33
+ b.retrieve()
34
+ end
35
+
36
+ it "should pass the report url and search filter array to the request method" do
37
+ b = SlidePay::Report.new(example_search_filter)
38
+ b.report_type = :put
39
+ b.url = "EXAMPLE_URL"
40
+
41
+ retrieve_params = { path: "EXAMPLE_URL", data: [example_search_filter].to_json, token: nil, api_key: nil, endpoint: nil }
42
+
43
+ SlidePay.should_receive(:put).with(retrieve_params).and_return(a_response_object)
44
+ b.retrieve()
45
+ end
46
+
47
+ it "should populate the report object from the response" do
48
+ b = SlidePay::Report.new([])
49
+ b.report_type = :put
50
+ b.url = "DOG_REPORT_URL"
51
+
52
+ retrieve_params = { path: "EXAMPLE_URL", data: [].to_json, options: {} }
53
+
54
+ SlidePay.should_receive(:put).and_return(a_response_object)
55
+ b.retrieve()
56
+
57
+ expect(b["id"]).to eq("1")
58
+ expect(b["name"]).to eq("Dog the Bounty Hunter")
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slidepay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Rothstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -154,9 +154,15 @@ files:
154
154
  - LICENSE
155
155
  - README.md
156
156
  - Rakefile
157
+ - TODO.md
157
158
  - lib/slidepay.rb
158
159
  - lib/slidepay/client.rb
159
160
  - lib/slidepay/config.rb
161
+ - lib/slidepay/reports/account_report.rb
162
+ - lib/slidepay/reports/payment_report.rb
163
+ - lib/slidepay/reports/post_report.rb
164
+ - lib/slidepay/reports/put_report.rb
165
+ - lib/slidepay/reports/report.rb
160
166
  - lib/slidepay/resources/api_key.rb
161
167
  - lib/slidepay/resources/api_resource.rb
162
168
  - lib/slidepay/resources/bank_account.rb
@@ -168,20 +174,27 @@ files:
168
174
  - lib/slidepay/response.rb
169
175
  - lib/slidepay/util.rb
170
176
  - lib/slidepay/version.rb
177
+ - scenarios/account_report_retrieve.rb
171
178
  - scenarios/company_retrieve.rb
172
179
  - scenarios/example.rb
173
180
  - scenarios/location_retrieve.rb
174
181
  - scenarios/payment_find_where_id.rb
175
182
  - scenarios/payment_find_where_under_review.rb
183
+ - scenarios/payment_report_retrieve.rb
176
184
  - scenarios/use_api_resource_for_arbitrary_object.rb
177
185
  - scenarios/user_master_find_with_first_name_fragment.rb
178
186
  - scenarios/user_master_retrieve.rb
179
187
  - slidepay.gemspec
188
+ - spec/account_report_spec.rb
180
189
  - spec/api_key_spec.rb
181
190
  - spec/api_resource_spec.rb
182
191
  - spec/bank_account_spec.rb
183
192
  - spec/client_spec.rb
193
+ - spec/payment_report_spec.rb
184
194
  - spec/payment_spec.rb
195
+ - spec/post_report_spec.rb
196
+ - spec/put_report_spec.rb
197
+ - spec/report_spec.rb
185
198
  - spec/response_spec.rb
186
199
  - spec/slidepay_spec.rb
187
200
  - spec/spec_helper.rb
@@ -210,11 +223,16 @@ signing_key:
210
223
  specification_version: 4
211
224
  summary: SlidePay Ruby SDK
212
225
  test_files:
226
+ - spec/account_report_spec.rb
213
227
  - spec/api_key_spec.rb
214
228
  - spec/api_resource_spec.rb
215
229
  - spec/bank_account_spec.rb
216
230
  - spec/client_spec.rb
231
+ - spec/payment_report_spec.rb
217
232
  - spec/payment_spec.rb
233
+ - spec/post_report_spec.rb
234
+ - spec/put_report_spec.rb
235
+ - spec/report_spec.rb
218
236
  - spec/response_spec.rb
219
237
  - spec/slidepay_spec.rb
220
238
  - spec/spec_helper.rb