slidepay 0.0.6 → 0.0.7

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: cd62eeffb82c24dd9a5b13c668a23360ef24518c
4
- data.tar.gz: f923dc072e19a532cfa02fbc895624f0875ee314
3
+ metadata.gz: 0717f747633f7aa532d21e58b8867ac449c4bcfe
4
+ data.tar.gz: c1a4afcf7d8c27775bd2e91b5288dcd27eec5141
5
5
  SHA512:
6
- metadata.gz: fc7c0e792d1345f7a27386e6cf723a1fc14beb1913a7a59da43ae07dfaace5f21b51a61a0ae9926ac58b287cba041de1816c1c88d363dfc13769170ac8f9b26b
7
- data.tar.gz: 1d853ef6581545a605a0b31f861b2001fa05599e108d296216ef889f306767e5b78a48773f1964cc775c95836614b4af5adaddc32b92e85bd516dd536628f0e9
6
+ metadata.gz: 6066b6d41e7909b954fc490a1d94927e8691c372f6ed331298a57ae0423c0db87be3da2fd401dfa7d0f649f606fb2693017c6e3f50f765542f19331dfd9f2b87
7
+ data.tar.gz: 3b89bd21f9ba4de0c611d89dd533ad65735382ccdc34b5f1ad22526d5c914bb14a4c0b503a916afb04a71f7680ba061305fcfaeb6d5fad2af594fb523d4ac4a2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Slidepay Ruby Sdk
4
4
 
5
- [![Build Status](https://travis-ci.org/SlidePay/slidepay-ruby-sdk.png)](https://travis-ci.org/SlidePay/slidepay-ruby-sdk) [![Code Climate](https://codeclimate.com/repos/5236cb7013d6371e46004010/badges/f963bebb1565c5419c78/gpa.png)](https://codeclimate.com/repos/5236cb7013d6371e46004010/feed)
5
+ [![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
7
  First version of the SlidePay Ruby SDK
8
8
 
@@ -59,7 +59,7 @@ SlidePay.authenticate(email, password)
59
59
  You can retrieve a token for use in any context with the retrieve_token method, which is similar to SlidePay.authenticate except that it returns the token string and does not set a global token value.
60
60
 
61
61
  ```ruby
62
- SlidePay.authenticate(email, password)
62
+ SlidePay.retrieve_token(email, password)
63
63
  ```
64
64
 
65
65
  These fields can also be used on an instance or per-request level by either passing them into the SlidePay module request methods as a field in a hash, or by assigning instance variables on a SlidePay::Client.
@@ -74,13 +74,101 @@ SlidePay.get(path: "payment/#{payment_id}", api_key: "MY_API_KEY")
74
74
 
75
75
  ## Resources
76
76
 
77
- SlidePay::ApiResources are classes that encapsulate RESTful API resources. API interaction relative to these resources is handled by the following descriptive methods:
77
+ The Ruby SDK provides explicit interfaces to the following SlidePay resources:
78
+ - api_key through the [ApiKey](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/api_key.rb) class
79
+ - bank_account through the [BankAccount](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/bank_account.rb) class
80
+ - payment through the [Payment](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/payment.rb) class
81
+ - user_master through the [UserMaster](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/user_master.rb) class
82
+ - customer through the [Customer](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/customer.rb) class
83
+
84
+ All of the above resource classes inherit class- and instance-level functionality from [SlidePay::ApiResource](https://github.com/SlidePay/slidepay-ruby-sdk/blob/master/lib/slidepay/resources/api_resource.rb).
85
+
86
+ As a result, each resource class provides common searching and CRUD functionality.
87
+
88
+ ## Search
89
+
90
+ Each ApiResource offers several class-level search methods:
91
+
92
+ - find(search_filter_array)
93
+ - find_where(value_hash)
94
+ - find_between(start_value_hash, end_value_hash)
95
+ - find_greater_than(value_hash)
96
+ - find_less_than(value_hash)
97
+
98
+ Each of these methods will return an array of zero or more instances of the ApiResource class.
99
+
100
+ ### find(search_filter_array)
101
+
102
+ ```find``` is a flexible interface for placing restrictions on a search. Search parameters must be supplied in the form of a [search filter array](https://getcube.atlassian.net/wiki/display/CDP/search_filter+and+search_filter_array). To supply them, pass an array of search filter Hashes as the first parameter.
103
+
104
+ ```ruby
105
+
106
+ # Find users whose first name contains "at"
107
+ users = SlidePay::UserMaster.find(field: "first_name", condition: "contains", value: "at")
108
+
109
+ # Find all users whose first name is "Matt"
110
+ users = SlidePay::UserMaster.find(field: "first_name", condition: "equals", value: "Matt")
111
+
112
+ ```
113
+
114
+ ### find_where(value_hash)
115
+
116
+ ```find_where``` allows you to specify equality constraints in your search. For instance, the following example is equivalent to the second ```find``` example above.
117
+
118
+ ```ruby
119
+
120
+ # Find all users whose first name is "Matt"
121
+ users = SlidePay::UserMaster.find_where(first_name: "Matt")
122
+
123
+ ```
124
+
125
+ ### find_greater_than(value_hash) and find_less_than(value_hash)
126
+
127
+ ```find_greater_than``` and ```find_less_than``` allow searching for resources with values greater than or less than what is provided in the hash.
128
+
129
+ ```ruby
130
+
131
+ # Find all payments greater than $200.00
132
+ payments = SlidePay::Payment.find_greater_than(amount: 200.00)
133
+
134
+ # Find all payments less than $10.00
135
+ payments = SlidePay::Payment.find_less_than(amount: 10.00)
136
+
137
+ # Find all users created after 10/12/2013 at 12:00 AM
138
+ users = SlidePay::UserMaster.find_greater_than(created: "10/12/2013")
139
+
140
+ # Find all users created before 10/05/2013 at 12:00 AM
141
+ users = SlidePay::UserMaster.find_less_than(created: "10/05/2013")
142
+
143
+ ```
144
+
145
+ ### find_between(start_value_hash, end_value_hash)
146
+
147
+ ```find_between``` takes two value hashes as arguments to combine the functionality of find_greater_than and find_less_than.
148
+
149
+ ```ruby
150
+
151
+ # Find all payments made between 10/05/2013 and 10/12/2013
152
+ start_values = { created: "10/05/2013" }
153
+ end_values = { created: "10/12/2013" }
154
+ payments = SlidePay::Payment.find_between(start_values, end_values)
155
+
156
+ # Find all payments between $3.00 and $10.00
157
+ start_values = { amount: 3.00 }
158
+ end_values = { amount: 10.00 }
159
+ payments = SlidePay::Payment.find_between(start_values, end_values)
160
+
161
+ ```
162
+
163
+ ## CRUD (Create, Read, Update, Delete)
164
+
165
+ Each ApiResource class provides RESTful CRUD functionality through the following instance methods:
78
166
 
79
167
  - ```save ```
80
168
  - ```destroy ```
81
169
  - ```retrieve ```
82
170
 
83
- The ```save``` method can handle both creation, via POST, and updating, via PUT, and determines which verb is appropriate by the ```ApiResource.is_new?``` method, which checks for the presence of an id in the resource.
171
+ The ```save``` method can handle both creation via POST, and updating via PUT. It determines which verb is appropriate by the ```ApiResource.is_new?``` method, which checks for data in the appropriate *_id field of the resource.
84
172
 
85
173
  ## Payments
86
174
 
@@ -105,13 +193,27 @@ SlidePay.post(path: 'payment/refund/#{payment_id}')
105
193
 
106
194
  ## Testing
107
195
 
196
+ ### Basics
197
+
108
198
  Test are in the spec directory, and can be run from the root of the repository:
109
199
 
110
200
  ```bash
111
201
  $ rspec spec
112
202
  ```
113
203
 
114
- Some tests will require that you have an active SlidePay account on the development server, and that you supply those credentials in an ```environment.rb``` file in the root of this repository.
204
+ ### Automatic Testing
205
+
206
+ There is also a Guardfile in the root directory of the library that will help test changes automatically. If you intend to modify this code, we highly recommend you configure [Guard](https://github.com/guard/guard) on your system to make use of this.
207
+
208
+ Once installed, run the Guard monitor from the root of the repository:
209
+
210
+ ```bash
211
+ $ guard
212
+ ```
213
+
214
+ ### Scenarios Requiring Account Information
215
+
216
+ Some tests, the ones in the scenarios directory, will require that you have an active SlidePay account on the development server, and that you supply those credentials in an ```environment.rb``` file in the root of this repository.
115
217
 
116
218
  Your populated environment.rb should look something like this:
117
219
 
@@ -124,8 +226,6 @@ ENV["api_key"] = "super-secret-api-key-that-you-never-share"
124
226
 
125
227
  ## Notes
126
228
 
127
- The SlidePay::Client class is largely untested and likely non-functional.
128
-
129
229
  Though this document rarely mentions authentication in most examples following the section above dedicated to it, an api_key or token, and an endpoint, may be supplied to any object or module that can perform an API request. This flexibility allows for interacting with a single instance of a single ApiResource class without having to use the SlidePay module methods directly, or having to use an instance of the SlidePay::Client class. It also accommodates those developers who may wish to authenticate many SlidePay accounts within a single thread, such as inside a request context of a Rails application, or in a scheduled task, without having to repeatedly set the SlidePay.token or SlidePay.api_key global values.
130
230
 
131
231
  ## License
@@ -119,17 +119,23 @@ module SlidePay
119
119
  end
120
120
 
121
121
  class << self
122
- def retrieve(token=nil, api_key=nil, endpoint=nil)
123
- response = SlidePay.get(path: self::URL_ROOT, token: token, api_key: api_key, endpoint: endpoint)
124
-
125
- results = []
122
+ def api_resource_array_from_response(response)
123
+ resources_array = []
126
124
  if response.was_successful? and response.data != nil
127
125
  data = response.data
128
126
  data.each do |resource_hash|
129
- results.push self.new(resource_hash)
127
+ resources_array.push self.new(resource_hash)
130
128
  end
131
129
  end
132
- results
130
+
131
+ resources_array
132
+ end
133
+
134
+
135
+ def retrieve(token=nil, api_key=nil, endpoint=nil)
136
+ response = SlidePay.get(path: self::URL_ROOT, token: token, api_key: api_key, endpoint: endpoint)
137
+
138
+ return api_resource_array_from_response(response)
133
139
  end
134
140
 
135
141
  def find(search_params, token=nil, api_key=nil, endpoint=nil)
@@ -141,17 +147,9 @@ module SlidePay
141
147
  elsif not search_params.is_a? Array
142
148
  raise Exception.new("Invalid or no search filter supplied.")
143
149
  end
144
-
145
- search_results = []
146
150
  response = SlidePay.put(path: self::URL_ROOT, data: search_params.to_json, token: token, api_key: api_key, endpoint: endpoint)
147
- if response.was_successful? and response.data != nil
148
- data = response.data
149
- data.each do |resource_hash|
150
- search_results.push self.new(resource_hash)
151
- end
152
- end
153
151
 
154
- search_results
152
+ return api_resource_array_from_response(response)
155
153
  end
156
154
 
157
155
  def find_where(search_params, token=nil, api_key=nil, endpoint=nil)
@@ -160,16 +158,7 @@ module SlidePay
160
158
  sfa.push(field: k, condition: "equals", value: v)
161
159
  end
162
160
 
163
- search_results = []
164
- response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
165
- if response.was_successful? and response.data != nil
166
- data = response.data
167
- data.each do |resource_hash|
168
- search_results.push self.new(resource_hash)
169
- end
170
- end
171
-
172
- search_results
161
+ return find(sfa, token, api_key, endpoint)
173
162
  end
174
163
 
175
164
  def find_between(start_params, end_params, token=nil, api_key=nil, endpoint=nil)
@@ -182,16 +171,7 @@ module SlidePay
182
171
  sfa.push(field: k, condition: "less_than", value: v)
183
172
  end
184
173
 
185
- search_results = []
186
- response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
187
- if response.was_successful? and response.data != nil
188
- data = response.data
189
- data.each do |resource_hash|
190
- search_results.push self.new(resource_hash)
191
- end
192
- end
193
-
194
- search_results
174
+ return find(sfa, token, api_key, endpoint)
195
175
  end
196
176
 
197
177
  def find_greater_than(search_params, token=nil, api_key=nil, endpoint=nil)
@@ -200,16 +180,7 @@ module SlidePay
200
180
  sfa.push(field: k, condition: "greater_than", value: v)
201
181
  end
202
182
 
203
- search_results = []
204
- response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
205
- if response.was_successful? and response.data != nil
206
- data = response.data
207
- data.each do |resource_hash|
208
- search_results.push self.new(resource_hash)
209
- end
210
- end
211
-
212
- search_results
183
+ return find(sfa, token, api_key, endpoint)
213
184
  end
214
185
 
215
186
  def find_less_than(search_params, token=nil, api_key=nil, endpoint=nil)
@@ -218,16 +189,7 @@ module SlidePay
218
189
  sfa.push(field: k, condition: "less_than", value: v)
219
190
  end
220
191
 
221
- search_results = []
222
- response = SlidePay.put(path: self::URL_ROOT, data: sfa.to_json, token: token, api_key: api_key, endpoint: endpoint)
223
- if response.was_successful? and response.data != nil
224
- data = response.data
225
- data.each do |resource_hash|
226
- search_results.push self.new(resource_hash)
227
- end
228
- end
229
-
230
- search_results
192
+ return find(sfa, token, api_key, endpoint)
231
193
  end
232
194
  end
233
195
 
@@ -0,0 +1,11 @@
1
+ module SlidePay
2
+ class ApiKey < ApiResource
3
+ def initialize(values_hash={})
4
+ @url_root = "customer"
5
+ @id_attribute = "customer_id"
6
+
7
+ super(values_hash)
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SlidePay
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slidepay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Rothstein
@@ -160,6 +160,7 @@ files:
160
160
  - lib/slidepay/resources/api_key.rb
161
161
  - lib/slidepay/resources/api_resource.rb
162
162
  - lib/slidepay/resources/bank_account.rb
163
+ - lib/slidepay/resources/customer.rb
163
164
  - lib/slidepay/resources/payment.rb
164
165
  - lib/slidepay/resources/user_master.rb
165
166
  - lib/slidepay/response.rb