stbaldricks 4.3.2.alpha.2 → 4.3.2.alpha.3

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
- SHA1:
3
- metadata.gz: ef908b5c141cd2bf03331174a10b6ccf4e155689
4
- data.tar.gz: 764cc9475e5afac35f4627209de0241f0be504f7
2
+ SHA256:
3
+ metadata.gz: e7ebf05a1a594e783ea1d0a2e197218f6ed3db74ce3bbf66347fb163900f2031
4
+ data.tar.gz: 3bc73caf5de5a61ced06fc71fbc58f08fc83834c246f278f1d07d8e4d8b534bb
5
5
  SHA512:
6
- metadata.gz: ca151c0b8fef81fc77b27477d4d523d24ed42cb35643725f854ae562db315fd0ae6950dcff2c84fda7bce3ac8a366ce2a58645a2f18d9797678250761be6f899
7
- data.tar.gz: 86a5c59a61aaf63c451097bf54ec9d3b53b49435cc8b0f459da980f7b68a642990d877933913e3872fd7ef100e9e450856b3ce18c266aedc5dc84d8281f0487b
6
+ metadata.gz: 4395a6188163ccdcf14582c7f1d096fcf4b91e9c5f694a9752fdb3639fed40e0dcca07a4ac7bf71c2e489f26d310eb9d3dd2eb6108460078234f5d5913d91315
7
+ data.tar.gz: f218d92e2b9631a12581778d71def4fbc6a27ed6581519fb8ff60ef3a436746b1c384cbacb9c6bd3fa2d75d9c4086d2d01036c97b69590783a44e6179407ba73
data/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # St. Baldrick's Ruby SDK
2
+
3
+ ### Installation
4
+ `gem install stbaldricks`
5
+
6
+ ### Configuration
7
+ * The sdk is configured using environment variables.
8
+ * Required configurations:
9
+ ```
10
+ API_ENDPOINT="https://stbaldricks.org/api"
11
+ API_KEY="abc123"
12
+ ```
13
+
14
+ ### Usage
15
+ * Require the gem
16
+ `require 'stbaldricks'`
17
+
18
+ * Configure the log level (optional)
19
+ `SBF::Client::Configuration.logger.level = ::Logger::WARN`
20
+
21
+ * **NOTE** the sdk does not raise execptions for failed requests. This is to allow for more complex logic around error scenarios.
22
+ * If you would like the client to raise errors by default you can wrap your requests in a helper
23
+ ``` ruby
24
+ def request_helper
25
+ # Yield to the block to execute the request
26
+ client_response = yield
27
+
28
+ # If there was an error, raise it to the error handling block
29
+ if client_response.error?
30
+ puts "Error received from API. (code: #{client_response.http_code})"
31
+ puts JSON.pretty_generate(client_response.to_hash)
32
+
33
+ raise "Error received from API"
34
+ end
35
+
36
+ # Otherwise simply return the client data
37
+ client_response.data
38
+ end
39
+ ```
40
+
41
+ #### Default Entity Actions
42
+ ##### Lookup
43
+ * Use `aggregate` to perform actions like gathering the size of a data set without returning all of the rows
44
+ ``` ruby
45
+ active_donation_count = request_helper {
46
+ SBF::Client::Donation.aggregate([status: :active], {id: :count})
47
+ }
48
+ puts "Beginning number of active donations: #{active_donation_count[:id]}"
49
+ ```
50
+
51
+ * Use `get` to get an entity by it's id fields
52
+ ``` ruby
53
+ existing_donation = request_helper { SBF::Client::Donation.get(188) }
54
+ puts "Donation: #{JSON.pretty_generate(existing_donation.to_hash)}"
55
+ ```
56
+
57
+ #### Creation
58
+ * To create an entity, create the object using `new` and persist the object to the database using `save`
59
+ ``` ruby
60
+ # Find a random, active user to use as the recipient
61
+ existing_participant = request_helper { SBF::Client::Participant.find({status: SBF::Client::Participant::Status::ACTIVE}) }[:results].sample
62
+ recipient = SBF::Client::Donation::PartialParticipant.new(id: existing_participant.id)
63
+
64
+ # Create a new donor profile. This will be saved at the same time as the donation
65
+ # TODO: Create HowCreated of mobile?
66
+ donor = SBF::Client::Donation::FullPerson.new(
67
+ status: SBF::Client::Person::Status::ACTIVE,
68
+ gender: SBF::Client::Person::Gender::NOT_SELECTED,
69
+ how_created: SBF::Client::Person::HowCreated::FAST_DONATION,
70
+ name_pieces: SBF::Client::NamePieces.new(
71
+ first_name: 'Foo',
72
+ last_name: 'Testerman'
73
+ ),
74
+ email_addresses: {
75
+ primary: SBF::Client::EmailAddress.new(
76
+ type: SBF::Client::EmailAddress::Type::PERSONAL,
77
+ email_address: 'foo.testerman@abcd.ef'
78
+ )
79
+ },
80
+ opt_out_settings: {
81
+ email_mass_online: true
82
+ }
83
+ )
84
+
85
+ # Payment details may be provided if the charging is completed.
86
+ # Otherwise a nonce should be used which will be settled when the donation is saved
87
+ payment_details = SBF::Client::Payment::CreditCardDetails.new(
88
+ authorization_id: 'abc123',
89
+ cardholder_name: 'Foo Testerman',
90
+ card_type: 'Visa',
91
+ expiration_date: '02/2027',
92
+ card_number: '************1234'
93
+ )
94
+
95
+ # Create the donation object itself. Status should be active unless this is a `submit cash` type donation.
96
+ donation = SBF::Client::FullDonation.new(
97
+ status: SBF::Client::Donation::Status::ACTIVE,
98
+ amount: 50.00,
99
+ display_name: 'Test Display Name',
100
+ is_unrecognized: false,
101
+ how_created: SBF::Client::Donation::HowCreated::MOBILE,
102
+ donor: donor,
103
+ recipient: recipient,
104
+ payment_details: payment_details
105
+ )
106
+
107
+ request_helper { donation.save }
108
+ puts "Added donation #{donation.id}"
109
+ ```
110
+
111
+ #### Search Actions
112
+ ##### Text search
113
+ ``` ruby
114
+ # Find all participants or fundraisers with 'John' in the searchable fields
115
+ model_types = [SBF::Client::Search::Type::PARTICIPANT, SBF::Client::Search::Type::FUNDRAISER]
116
+ participants_and_fundraisers = request_helper { SBF::Client::Search.find(model_types, 'John')}[:results]
117
+ puts JSON.pretty_generate(participants_and_fundraisers)
118
+ ```
119
+
120
+ ##### Filtered Search
121
+ ``` ruby
122
+ # Find all active events, teams, and fundraisers at the railyard event
123
+ railyard_event = request_helper { SBF::Client::Event.find(venue: {location: {name: {like: "%Rail%"}}}, year: 2017) }[:results].first
124
+
125
+ model_types = [SBF::Client::Search::Type::EVENT, SBF::Client::Search::Type::TEAM, SBF::Client::Search::Type::FUNDRAISER]
126
+ filter = {
127
+ and: [
128
+ {column: 'status_id', operator: 'equals', value: SBF::Client::Search::Status::ACTIVE},
129
+ {column: 'event_id', operator: 'equals', value: railyard_event.id},
130
+ {column: 'event_year', operator: 'equals', value: railyard_event.year}
131
+ ]
132
+ }
133
+
134
+ entities_at_the_railyard = request_helper { SBF::Client::Search.find(model_types, nil, filter, nil, limit: 20) }[:results]
135
+ puts JSON.pretty_generate(entities_at_the_railyard)
136
+ ```
137
+
138
+ ##### Geocode Search
139
+ ``` ruby
140
+ # Find all active participants with 10 miles of Lincoln, NE
141
+ require 'geocoder'
142
+ data = Geocoder::Lookup.get(:google).search("Lincoln, NE").first
143
+ lat = data.latitude.round(6)
144
+ lon = data.longitude.round(6)
145
+ geo_location = {lat: lat, lon: lon, distance: 200}
146
+
147
+ model_type = SBF::Client::Search::Type::PARTICIPANT
148
+
149
+ filter = {and: [{column: 'status_id', operator: 'equals', value: SBF::Client::Search::Status::ACTIVE}]}
150
+
151
+ active_participant_within_10_mi = request_helper { SBF::Client::Search.find(model_type, nil, filter, geo_location, limit: 2) }[:results]
152
+ puts JSON.pretty_generate(active_participant_within_10_mi)
153
+ ```
154
+
@@ -147,6 +147,32 @@ module SBF
147
147
  end
148
148
  end
149
149
 
150
+ class FullPerson < SBF::Client::FullPerson
151
+ attr_reader :type
152
+
153
+ def type
154
+ SBF::Client::Donation::DonorType::INDIVIDUAL
155
+ end
156
+ end
157
+
158
+ class PartialPerson < SBF::Client::PartialPerson
159
+ attr_reader :type
160
+
161
+ def type
162
+ SBF::Client::Donation::DonorType::INDIVIDUAL
163
+ end
164
+ end
165
+
166
+ class FullOrganization < SBF::Client::FullPerson
167
+ attr_reader :type
168
+ private :type
169
+ end
170
+
171
+ class PartialOrganization < SBF::Client::PartialPerson
172
+ attr_reader :type
173
+ private :type
174
+ end
175
+
150
176
  class RecognitionCard < SBF::Client::BaseEntity
151
177
  class Recipient < SBF::Client::BaseEntity
152
178
  attr_reader :name
@@ -302,18 +328,18 @@ module SBF
302
328
  [
303
329
  [
304
330
  ->(v) { v[:type] == SBF::Client::Donation::DonorType::INDIVIDUAL },
305
- 'SBF::Client::FullPerson',
306
- 'SBF::Client::PartialPerson'
331
+ 'SBF::Client::Donation::FullPerson',
332
+ 'SBF::Client::Donation::PartialPerson'
307
333
  ],
308
334
  [
309
335
  ->(v) { v[:type] == SBF::Client::Donation::DonorType::BUSINESS },
310
- 'SBF::Client::FullOrganization',
311
- 'SBF::Client::PartialOrganization'
336
+ 'SBF::Client::Donation::FullOrganization',
337
+ 'SBF::Client::Donation::PartialOrganization'
312
338
  ],
313
339
  [
314
340
  ->(v) { v[:type] == SBF::Client::Donation::DonorType::ORGANIZATION_FOUNDATION },
315
- 'SBF::Client::FullOrganization',
316
- 'SBF::Client::PartialOrganization'
341
+ 'SBF::Client::Donation::FullOrganization',
342
+ 'SBF::Client::Donation::PartialOrganization'
317
343
  ]
318
344
  ],
319
345
  optional: true
@@ -1,5 +1,5 @@
1
1
  module SBF
2
2
  module Client
3
- VERSION = '4.3.2.alpha.2'
3
+ VERSION = '4.3.2.alpha.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stbaldricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2.alpha.2
4
+ version: 4.3.2.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-14 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - LICENSE
77
+ - README.md
77
78
  - lib/stbaldricks.rb
78
79
  - lib/stbaldricks/api.rb
79
80
  - lib/stbaldricks/client.rb
@@ -215,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
216
  version: 1.3.1
216
217
  requirements: []
217
218
  rubyforge_project:
218
- rubygems_version: 2.6.12
219
+ rubygems_version: 2.7.0
219
220
  signing_key:
220
221
  specification_version: 4
221
222
  summary: St. Baldrick's Foundation Ruby Client Library