stbaldricks 12.12.0 → 12.13.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/lib/stbaldricks/configuration.rb +2 -2
  3. data/lib/stbaldricks/default_logger.rb +2 -2
  4. data/lib/stbaldricks/endpoints/blog_post.rb +8 -8
  5. data/lib/stbaldricks/endpoints/communicate.rb +1 -1
  6. data/lib/stbaldricks/endpoints/config.rb +1 -1
  7. data/lib/stbaldricks/endpoints/deduplicator_match.rb +2 -2
  8. data/lib/stbaldricks/endpoints/kid.rb +1 -1
  9. data/lib/stbaldricks/endpoints/lib/entity.rb +13 -11
  10. data/lib/stbaldricks/endpoints/newsletter_recipient.rb +11 -5
  11. data/lib/stbaldricks/endpoints/participant.rb +3 -3
  12. data/lib/stbaldricks/endpoints/photo.rb +5 -4
  13. data/lib/stbaldricks/endpoints/search.rb +2 -2
  14. data/lib/stbaldricks/endpoints/user.rb +1 -1
  15. data/lib/stbaldricks/entities/batch.rb +3 -5
  16. data/lib/stbaldricks/entities/blog_post.rb +1 -7
  17. data/lib/stbaldricks/entities/campaign.rb +6 -13
  18. data/lib/stbaldricks/entities/challenge.rb +4 -6
  19. data/lib/stbaldricks/entities/challenger.rb +4 -6
  20. data/lib/stbaldricks/entities/concerns/entity_response_concern.rb +1 -1
  21. data/lib/stbaldricks/entities/config.rb +3 -8
  22. data/lib/stbaldricks/entities/contact.rb +4 -7
  23. data/lib/stbaldricks/entities/contact_group.rb +2 -2
  24. data/lib/stbaldricks/entities/deduplicator_history.rb +1 -6
  25. data/lib/stbaldricks/entities/deduplicator_match.rb +4 -7
  26. data/lib/stbaldricks/entities/disease.rb +2 -5
  27. data/lib/stbaldricks/entities/document_library.rb +3 -8
  28. data/lib/stbaldricks/entities/document_library_category.rb +1 -4
  29. data/lib/stbaldricks/entities/donation.rb +12 -18
  30. data/lib/stbaldricks/entities/donor.rb +1 -5
  31. data/lib/stbaldricks/entities/event.rb +32 -43
  32. data/lib/stbaldricks/entities/event_application.rb +6 -10
  33. data/lib/stbaldricks/entities/event_donation_summary.rb +2 -5
  34. data/lib/stbaldricks/entities/event_participant_summary.rb +1 -3
  35. data/lib/stbaldricks/entities/event_supporter.rb +3 -3
  36. data/lib/stbaldricks/entities/fund.rb +6 -23
  37. data/lib/stbaldricks/entities/fundraiser.rb +16 -29
  38. data/lib/stbaldricks/entities/grant.rb +12 -25
  39. data/lib/stbaldricks/entities/institution.rb +3 -4
  40. data/lib/stbaldricks/entities/international_partner.rb +4 -16
  41. data/lib/stbaldricks/entities/kid.rb +11 -28
  42. data/lib/stbaldricks/entities/kid_honor.rb +1 -0
  43. data/lib/stbaldricks/entities/kid_institution.rb +2 -2
  44. data/lib/stbaldricks/entities/lib/address.rb +3 -6
  45. data/lib/stbaldricks/entities/lib/alternate_shipping_address.rb +1 -3
  46. data/lib/stbaldricks/entities/lib/base.rb +47 -39
  47. data/lib/stbaldricks/entities/lib/collection.rb +2 -2
  48. data/lib/stbaldricks/entities/lib/email_address.rb +1 -2
  49. data/lib/stbaldricks/entities/lib/fundraising_page.rb +1 -2
  50. data/lib/stbaldricks/entities/lib/location.rb +1 -0
  51. data/lib/stbaldricks/entities/lib/milestone.rb +1 -3
  52. data/lib/stbaldricks/entities/lib/name.rb +2 -2
  53. data/lib/stbaldricks/entities/lib/not_implemented_object.rb +1 -1
  54. data/lib/stbaldricks/entities/lib/permissions.rb +2 -4
  55. data/lib/stbaldricks/entities/lib/phone.rb +2 -3
  56. data/lib/stbaldricks/entities/lib/third_party_media.rb +1 -5
  57. data/lib/stbaldricks/entities/lib/top_level.rb +1 -1
  58. data/lib/stbaldricks/entities/matching_gift_company.rb +16 -39
  59. data/lib/stbaldricks/entities/memorial.rb +9 -14
  60. data/lib/stbaldricks/entities/message.rb +4 -15
  61. data/lib/stbaldricks/entities/organization.rb +11 -17
  62. data/lib/stbaldricks/entities/page.rb +9 -15
  63. data/lib/stbaldricks/entities/participant.rb +18 -28
  64. data/lib/stbaldricks/entities/participant_donation_summary.rb +2 -4
  65. data/lib/stbaldricks/entities/person.rb +22 -26
  66. data/lib/stbaldricks/entities/person_donation_by_year_summary.rb +1 -2
  67. data/lib/stbaldricks/entities/photo.rb +5 -11
  68. data/lib/stbaldricks/entities/recurring_gift.rb +10 -18
  69. data/lib/stbaldricks/entities/response.rb +1 -0
  70. data/lib/stbaldricks/entities/search.rb +30 -168
  71. data/lib/stbaldricks/entities/section.rb +1 -4
  72. data/lib/stbaldricks/entities/shave_schedule.rb +4 -13
  73. data/lib/stbaldricks/entities/summary.rb +1 -7
  74. data/lib/stbaldricks/entities/team.rb +12 -16
  75. data/lib/stbaldricks/entities/team_donation_summary.rb +2 -4
  76. data/lib/stbaldricks/request.rb +2 -2
  77. data/lib/stbaldricks/version.rb +1 -1
  78. metadata +83 -277
  79. data/lib/stbaldricks_factories.rb +0 -5
  80. data/spec/factories/address.rb +0 -14
  81. data/spec/factories/campaign/totals.rb +0 -9
  82. data/spec/factories/campaign.rb +0 -9
  83. data/spec/factories/challenge.rb +0 -19
  84. data/spec/factories/challenger.rb +0 -33
  85. data/spec/factories/collection.rb +0 -17
  86. data/spec/factories/contact.rb +0 -18
  87. data/spec/factories/contact_group.rb +0 -18
  88. data/spec/factories/diagnosis.rb +0 -12
  89. data/spec/factories/disease.rb +0 -11
  90. data/spec/factories/donation/participant.rb +0 -27
  91. data/spec/factories/donation.rb +0 -68
  92. data/spec/factories/donor.rb +0 -13
  93. data/spec/factories/email_address.rb +0 -11
  94. data/spec/factories/error.rb +0 -9
  95. data/spec/factories/event/coach_tracking/coaching_interactions.rb +0 -12
  96. data/spec/factories/event/coach_tracking/plaque.rb +0 -12
  97. data/spec/factories/event/coach_tracking/proceeds.rb +0 -12
  98. data/spec/factories/event/coach_tracking.rb +0 -18
  99. data/spec/factories/event/contacts/contact.rb +0 -17
  100. data/spec/factories/event/contacts/name_pieces.rb +0 -12
  101. data/spec/factories/event/contacts.rb +0 -16
  102. data/spec/factories/event/photos.rb +0 -12
  103. data/spec/factories/event/totals.rb +0 -15
  104. data/spec/factories/event/venue/location.rb +0 -18
  105. data/spec/factories/event/venue/social.rb +0 -16
  106. data/spec/factories/event/venue.rb +0 -16
  107. data/spec/factories/event.rb +0 -66
  108. data/spec/factories/event_application.rb +0 -34
  109. data/spec/factories/event_supporter.rb +0 -19
  110. data/spec/factories/fund.rb +0 -18
  111. data/spec/factories/fundraiser/photos.rb +0 -12
  112. data/spec/factories/fundraiser/policies.rb +0 -11
  113. data/spec/factories/fundraiser/totals.rb +0 -11
  114. data/spec/factories/fundraiser.rb +0 -24
  115. data/spec/factories/fundraising_page.rb +0 -29
  116. data/spec/factories/grant.rb +0 -22
  117. data/spec/factories/grant_institution.rb +0 -17
  118. data/spec/factories/institution.rb +0 -18
  119. data/spec/factories/kid/custom_institution.rb +0 -12
  120. data/spec/factories/kid.rb +0 -58
  121. data/spec/factories/kid_honor.rb +0 -16
  122. data/spec/factories/kid_institution.rb +0 -23
  123. data/spec/factories/lib/faker_patch.rb +0 -27
  124. data/spec/factories/lib/helpers.rb +0 -7
  125. data/spec/factories/location.rb +0 -17
  126. data/spec/factories/memorial/photos.rb +0 -14
  127. data/spec/factories/memorial/totals.rb +0 -11
  128. data/spec/factories/memorial/tribute.rb +0 -19
  129. data/spec/factories/memorial.rb +0 -22
  130. data/spec/factories/message.rb +0 -31
  131. data/spec/factories/milestone.rb +0 -15
  132. data/spec/factories/name_pieces.rb +0 -24
  133. data/spec/factories/newsletter_recipient.rb +0 -13
  134. data/spec/factories/organization/addresses.rb +0 -16
  135. data/spec/factories/organization/email_addresses.rb +0 -14
  136. data/spec/factories/organization/phone_numbers.rb +0 -14
  137. data/spec/factories/organization.rb +0 -34
  138. data/spec/factories/page.rb +0 -5
  139. data/spec/factories/participant/photos.rb +0 -14
  140. data/spec/factories/participant/policies.rb +0 -12
  141. data/spec/factories/participant/rankings/ranking.rb +0 -12
  142. data/spec/factories/participant/rankings.rb +0 -16
  143. data/spec/factories/participant/roles/role.rb +0 -154
  144. data/spec/factories/participant/roles.rb +0 -37
  145. data/spec/factories/participant/totals.rb +0 -11
  146. data/spec/factories/participant.rb +0 -95
  147. data/spec/factories/payment.rb +0 -13
  148. data/spec/factories/permissions.rb +0 -12
  149. data/spec/factories/person/addresses.rb +0 -16
  150. data/spec/factories/person/email_addresses.rb +0 -14
  151. data/spec/factories/person/phone_numbers.rb +0 -14
  152. data/spec/factories/person/policies.rb +0 -13
  153. data/spec/factories/person.rb +0 -22
  154. data/spec/factories/phone.rb +0 -11
  155. data/spec/factories/photo.rb +0 -11
  156. data/spec/factories/photos.rb +0 -9
  157. data/spec/factories/recurring_gift.rb +0 -22
  158. data/spec/factories/researcher.rb +0 -15
  159. data/spec/factories/response.rb +0 -38
  160. data/spec/factories/search_event.rb +0 -19
  161. data/spec/factories/search_fundraiser.rb +0 -15
  162. data/spec/factories/search_kid.rb +0 -13
  163. data/spec/factories/search_participant.rb +0 -15
  164. data/spec/factories/search_team.rb +0 -13
  165. data/spec/factories/shave_schedule/time_selection_permissions.rb +0 -12
  166. data/spec/factories/shave_schedule.rb +0 -33
  167. data/spec/factories/team/photos.rb +0 -12
  168. data/spec/factories/team/rankings/ranking.rb +0 -12
  169. data/spec/factories/team/rankings.rb +0 -15
  170. data/spec/factories/team/totals.rb +0 -14
  171. data/spec/factories/team.rb +0 -43
  172. data/spec/factories/third_party_media.rb +0 -12
  173. data/spec/factories/treatment_status.rb +0 -10
  174. data/spec/factories/user.rb +0 -14
  175. data/spec/factories/venue.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d02819f8acc7f8c7feac0bbe0208b2abd20bc8077a5126e95d20119d7132d768
4
- data.tar.gz: 26f43c53a869711e1891e9c450dbb50963830dbc9909365dc5c1aab4d5d3c2c1
3
+ metadata.gz: 245302bdc6a65163dffea2f75735ba07daa8841d5582f0e3dacbcbbf8e32fde8
4
+ data.tar.gz: 4cd771daeb0c896961732a33730f37ed3da73f401801fe82033d4f99791c4b89
5
5
  SHA512:
6
- metadata.gz: 54866211921b359cfd993abce7689813b56a726ce8ac838e48faa5c51cac037c2f09decfebaeca5391f97882c5891af7a31c7e913eb346e8e9321d855ff34a28
7
- data.tar.gz: 48785dbb05cc04fc6320e579f99f02061315a459de7f9dc2ba956fd06b34370010f7224aef27630f0493c7939441c6e7b7264ac078fd013feaecf804b3ddb38e
6
+ metadata.gz: 5f9ef91371ce8ed1713fcc139b46a602d0d0e39aa30a153ec6f8428ce1691645213211c3f83974d08b6eb1b323e9ce8c0bd3ab3afa42116d32fc911a35e7857e
7
+ data.tar.gz: fb9fe4e5d14c9f3b04229d469ac1b3c16f5cb74a78108f13744435bf5cc9fc1779765d5c73573d4bc542aa24a9682b707b82602abd93b1fbfab3b5a9f28b7b7a
@@ -16,11 +16,11 @@ module SBF
16
16
  end
17
17
 
18
18
  def self.base_uri
19
- @base_uri ||= ENV['API_ENDPOINT'] || DEFAULT_API_ENDPOINT
19
+ @base_uri ||= ENV.fetch('API_ENDPOINT', DEFAULT_API_ENDPOINT)
20
20
  end
21
21
 
22
22
  def self.general_token
23
- @general_token ||= ENV['API_KEY'] || raise(SBF::Client::Configuration::Error.new('general_token', 'must be set'))
23
+ @general_token ||= ENV.fetch('API_KEY', nil) || raise(SBF::Client::Configuration::Error.new('general_token', 'must be set'))
24
24
  end
25
25
 
26
26
  def self.request_id
@@ -3,7 +3,7 @@ require 'logger'
3
3
  module SBF
4
4
  module Client
5
5
  module DefaultLogger
6
- def self.instance(default_stream = STDOUT)
6
+ def self.instance(default_stream = $stdout)
7
7
  formatter = proc { |severity, datetime, _, msg|
8
8
  # ruby logger docs suggested this method for escaping messages since messages may contain user input
9
9
  # and are not escaped by default.
@@ -16,7 +16,7 @@ module SBF
16
16
 
17
17
  logger.formatter = formatter
18
18
  logger.level = ::Logger::DEBUG
19
- logger.level = ENV['SBF_CLIENT_LOG_LEVEL'] || ::Logger::DEBUG
19
+ logger.level = ENV.fetch('SBF_CLIENT_LOG_LEVEL', ::Logger::DEBUG)
20
20
  logger
21
21
  end
22
22
  end
@@ -27,17 +27,17 @@ module SBF
27
27
  end
28
28
  end
29
29
 
30
- def find_by_term(term, order = {}, limit = 10, offset = 0, show_hidden = true)
30
+ def find_by_term(term, order = {}, limit = 10, offset = 0, show_hidden: true)
31
31
  # Build the parameter list for search; an empty find is supported
32
32
  filter = {}
33
33
  filter[:type] = FILTER_BY_TERM
34
34
  filter[:term] = term unless term.empty?
35
35
  filter[:show_hidden] = show_hidden
36
36
 
37
- find(filter, order, limit, offset)
37
+ find(filter: filter, order: order, limit: limit, offset: offset)
38
38
  end
39
39
 
40
- def find_by_author(author, order = {}, limit = 10, offset = 0, show_hidden = true)
40
+ def find_by_author(author, order = {}, limit = 10, offset = 0, show_hidden: true)
41
41
  raise SBF::Client::Error, 'Must provide author for the query' if author.empty?
42
42
 
43
43
  filter = {}
@@ -45,10 +45,10 @@ module SBF
45
45
  filter[:term] = author
46
46
  filter[:show_hidden] = show_hidden
47
47
 
48
- find(filter, order, limit, offset)
48
+ find(filter: filter, order: order, limit: limit, offset: offset)
49
49
  end
50
50
 
51
- def find_by_category(category, order = {}, limit = 10, offset = 0, show_hidden = true)
51
+ def find_by_category(category, order = {}, limit = 10, offset = 0, show_hidden: true)
52
52
  raise SBF::Client::Error, 'Must provide category for the query' if category.empty?
53
53
 
54
54
  filter = {}
@@ -56,10 +56,10 @@ module SBF
56
56
  filter[:term] = category
57
57
  filter[:show_hidden] = show_hidden
58
58
 
59
- find(filter, order, limit, offset)
59
+ find(filter: filter, order: order, limit: limit, offset: offset)
60
60
  end
61
61
 
62
- def find_by_tag(tag, order = {}, limit = 10, offset = 0, show_hidden = true)
62
+ def find_by_tag(tag, order = {}, limit = 10, offset = 0, show_hidden: true)
63
63
  raise SBF::Client::Error, 'Must provide tag for the query' if tag.empty?
64
64
 
65
65
  filter = {}
@@ -67,7 +67,7 @@ module SBF
67
67
  filter[:term] = tag
68
68
  filter[:show_hidden] = show_hidden
69
69
 
70
- find(filter, order, limit, offset)
70
+ find(filter: filter, order: order, limit: limit, offset: offset)
71
71
  end
72
72
  end
73
73
  end
@@ -48,7 +48,7 @@ module SBF
48
48
  group_id: group_id
49
49
  )
50
50
  parsed_response_body = JSON.parse(response.body).symbolize!
51
- parsed_response_body.map! { |c| SBF::Client::Contact.new(c) } if ok?(response)
51
+ parsed_response_body.map! { |c| SBF::Client::Contact.new(c, clear_changes: false) } if ok?(response)
52
52
 
53
53
  handle_parsed_response(parsed_response_body, response)
54
54
  end
@@ -11,7 +11,7 @@ module SBF
11
11
  raise SBF::Client::StandardError, 'Unable to retrieve settings from the api' unless ok?(response)
12
12
 
13
13
  # re-call initalize with the new api data. This should re-set all of the instance variables on the instance
14
- entity.send(:initialize, parsed_response_body)
14
+ entity.send(:initialize, parsed_response_body, clear_changes: false)
15
15
  end
16
16
  end
17
17
  end
@@ -3,7 +3,7 @@ require 'stbaldricks/endpoints/lib/entity'
3
3
  module SBF
4
4
  module Client
5
5
  class DeduplicatorMatchEndpoint < SBF::Client::EntityEndpoint
6
- def checkout(filter = [], order = {}, limit = 20, offset = 0, with = {})
6
+ def checkout(filter: [], order: {}, limit: 20, offset: 0, with: {})
7
7
  filter = filter.to_json unless filter.is_a? String
8
8
  order = order.to_json unless order.is_a? String
9
9
  with = normalize_with(with)
@@ -15,7 +15,7 @@ module SBF
15
15
  parsed_response_body = JSON.parse(response.body).symbolize!
16
16
 
17
17
  if ok?(response)
18
- parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data, true) }
18
+ parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data, clear_changes: true) }
19
19
  SBF::Client::EntityCollection.new(parsed_response_body[:results], parsed_response_body[:total_count])
20
20
  else
21
21
  parsed_response_body = JSON.parse(response.body).symbolize!
@@ -12,7 +12,7 @@ module SBF
12
12
  parsed_response_body = JSON.parse(response.body).symbolize!
13
13
 
14
14
  if ok?(response)
15
- parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data) }
15
+ parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data, clear_changes: false) }
16
16
  SBF::Client::EntityCollection.new(parsed_response_body[:results], parsed_response_body[:total_count])
17
17
  else
18
18
  parsed_response_body = JSON.parse(response.body).symbolize!
@@ -10,8 +10,7 @@ require 'json'
10
10
  module SBF
11
11
  module Client
12
12
  class EntityEndpoint
13
- attr_reader :orig_target_class
14
- attr_reader :base_uri
13
+ attr_reader :orig_target_class, :base_uri
15
14
 
16
15
  def initialize(target_class)
17
16
  @orig_target_class = target_class
@@ -34,7 +33,7 @@ module SBF
34
33
  # @param with [Hash] The optional entity fields to include in the response
35
34
  # @return entity [SBF::Client::BaseEntity]
36
35
  def create(entity_or_hash, with = {})
37
- entity = entity_or_hash.is_a?(Hash) ? target_class.new(entity_or_hash) : entity_or_hash
36
+ entity = entity_or_hash.is_a?(Hash) ? target_class.new(entity_or_hash, clear_changes: false) : entity_or_hash
38
37
  raise SBF::Client::Error, 'Invalid Entity' unless entity.is_a?(SBF::Client::BaseEntity)
39
38
 
40
39
  with = normalize_with(with, entity)
@@ -50,10 +49,11 @@ module SBF
50
49
  # @param with [Hash] The optional entity fields to include in the response
51
50
  # @return entity [SBF::Client::BaseEntity]
52
51
  def update(id = nil, entity_or_hash = nil, with = {})
53
- if entity_or_hash.is_a?(SBF::Client::BaseEntity)
52
+ case entity_or_hash
53
+ when SBF::Client::BaseEntity
54
54
  # If someone has passed in an entity, just convert it to a hash
55
55
  data = entity_or_hash.dirty_data
56
- elsif entity_or_hash.is_a?(Hash)
56
+ when Hash
57
57
  # If someone has passed in a hash, make sure all of it's values match fields in the entity class
58
58
  data = sanitize(entity_or_hash)
59
59
  else
@@ -89,7 +89,7 @@ module SBF
89
89
  end
90
90
 
91
91
  # Calls the find route for the entity.
92
- def find(filter = [], order = {}, limit = 20, offset = 0, with = {})
92
+ def find(filter: [], order: {}, limit: 20, offset: 0, with: {})
93
93
  filter = filter.to_json unless filter.is_a? String
94
94
  order = order.to_json unless order.is_a? String
95
95
  with = normalize_with(with)
@@ -98,7 +98,9 @@ module SBF
98
98
  parsed_response_body = JSON.parse(response.body).symbolize!
99
99
 
100
100
  if ok?(response)
101
- parsed_response_body[:results].map! { |entity_data| target_class.new(entity_data, true) }
101
+ parsed_response_body[:results].map! do |entity_data|
102
+ target_class.new(entity_data, clear_changes: true)
103
+ end
102
104
  SBF::Client::EntityCollection.new(parsed_response_body[:results], parsed_response_body[:total_count])
103
105
  else
104
106
  parsed_response_body = JSON.parse(response.body).symbolize!
@@ -113,7 +115,7 @@ module SBF
113
115
 
114
116
  # Calls the find route for the entity.
115
117
  def find_first(filter = [], order = {}, with = {})
116
- response = find(filter, order, 1, 0, with)
118
+ response = find(filter: filter, order: order, limit: 1, with: with)
117
119
  if response.is_a?(SBF::Client::EntityCollection)
118
120
  response.empty? ? nil : response.first
119
121
  else
@@ -148,7 +150,7 @@ module SBF
148
150
 
149
151
  def target_class
150
152
  class_name_pieces = @orig_target_class.to_s.split('::')
151
- full_name = (class_name_pieces[0..-2] + ['Full' + class_name_pieces.last]).join('::')
153
+ full_name = (class_name_pieces[0..-2] + ["Full#{class_name_pieces.last}"]).join('::')
152
154
  Object.const_defined?(full_name) ? Object.const_get(full_name) : @orig_target_class
153
155
  end
154
156
  private :target_class
@@ -247,7 +249,7 @@ module SBF
247
249
  entity_or_hash.send(:initialize_attributes, new_data)
248
250
  entity = entity_or_hash
249
251
  else
250
- entity = target_class.new(new_data)
252
+ entity = target_class.new(new_data, clear_changes: false)
251
253
  end
252
254
 
253
255
  # Reload entity and its sub-entities so that no fields have a 'changed' state
@@ -256,7 +258,7 @@ module SBF
256
258
  entity
257
259
  else
258
260
  error = SBF::Client::ApiErrorEntity.new(parsed_response_body.merge(http_code: response.code))
259
- entity = entity_or_hash.is_a?(SBF::Client::BaseEntity) ? entity_or_hash : target_class.new(entity_or_hash)
261
+ entity = entity_or_hash.is_a?(SBF::Client::BaseEntity) ? entity_or_hash : target_class.new(entity_or_hash, clear_changes: false)
260
262
  entity.add_errors(error)
261
263
  entity.errors_http_code = response.code
262
264
 
@@ -3,9 +3,14 @@ require 'stbaldricks/endpoints/lib/entity'
3
3
  module SBF
4
4
  module Client
5
5
  class NewsletterRecipientEndpoint < EntityEndpoint
6
- def subscribe(entity_or_email, first_name = nil, last_name = nil, welcome_email = true)
6
+ def subscribe(entity_or_email, first_name = nil, last_name = nil, welcome_email: true)
7
7
  if entity_or_email.is_a?(String) && entity_or_email && first_name && last_name
8
- entity = target_class.new(email_address: entity_or_email, first_name: first_name, last_name: last_name, welcome_email: welcome_email)
8
+ entity = target_class.new({
9
+ email_address: entity_or_email,
10
+ first_name: first_name,
11
+ last_name: last_name,
12
+ welcome_email: welcome_email
13
+ }, clear_changes: false)
9
14
  elsif entity_or_email.is_a?(SBF::Client::BaseEntity)
10
15
  entity = entity_or_email
11
16
  else
@@ -21,9 +26,10 @@ module SBF
21
26
  end
22
27
 
23
28
  def unsubscribe(entity_or_email)
24
- if entity_or_email.is_a?(String)
25
- entity = target_class.new(email_address: entity_or_email)
26
- elsif entity_or_email.is_a?(SBF::Client::BaseEntity)
29
+ case entity_or_email
30
+ when String
31
+ entity = target_class.new({email_address: entity_or_email}, clear_changes: false)
32
+ when SBF::Client::BaseEntity
27
33
  entity = entity_or_email
28
34
  else
29
35
  raise SBF::Client::Error, 'Invalid Entity'
@@ -7,7 +7,7 @@ module SBF
7
7
  response = SBF::Client::Api::Request.post_request("#{base_uri}/move_to_different_team", id: participant_id, new_team_id: new_team_id)
8
8
 
9
9
  if ok?(response)
10
- data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!)
10
+ data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!, clear_changes: false)
11
11
  else
12
12
  error = SBF::Client::ErrorEntity.new(JSON.parse(response.body).symbolize!)
13
13
  end
@@ -26,7 +26,7 @@ module SBF
26
26
  )
27
27
 
28
28
  if ok?(response)
29
- data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!)
29
+ data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!, clear_changes: false)
30
30
  else
31
31
  error = SBF::Client::ErrorEntity.new(JSON.parse(response.body).symbolize!)
32
32
  end
@@ -38,7 +38,7 @@ module SBF
38
38
  response = SBF::Client::Api::Request.post_request("#{base_uri}/move_to_different_team", id: participant_id, new_team_id: 0)
39
39
 
40
40
  if ok?(response)
41
- data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!)
41
+ data = SBF::Client::FullParticipant.new(JSON.parse(response.body).symbolize!, clear_changes: false)
42
42
  else
43
43
  error = SBF::Client::ErrorEntity.new(JSON.parse(response.body).symbolize!)
44
44
  end
@@ -4,7 +4,7 @@ module SBF
4
4
  module Client
5
5
  class PhotoEndpoint < SBF::Client::EntityEndpoint
6
6
  def create(entity_or_hash, with = {})
7
- entity = entity_or_hash.is_a?(Hash) ? target_class.new(entity_or_hash) : entity_or_hash
7
+ entity = entity_or_hash.is_a?(Hash) ? target_class.new(entity_or_hash, clear_changes: false) : entity_or_hash
8
8
  raise SBF::Client::Error, 'Invalid Entity' unless entity.is_a?(SBF::Client::BaseEntity)
9
9
 
10
10
  with = normalize_with(with)
@@ -20,12 +20,13 @@ module SBF
20
20
  end
21
21
 
22
22
  def update(id = nil, entity_or_hash = nil, with = {})
23
- if entity_or_hash.is_a?(SBF::Client::BaseEntity)
23
+ case entity_or_hash
24
+ when SBF::Client::BaseEntity
24
25
  # If someone has passed in an entity, just convert it to a hash
25
26
  data = entity_or_hash.dirty_data
26
27
  data[:id] = id unless id.nil?
27
28
  data[:id] = entity_or_hash.id if id.nil? && !entity_or_hash.id.nil?
28
- elsif entity_or_hash.is_a?(Hash)
29
+ when Hash
29
30
  # If someone has passed in a hash, make sure all of it's values match fields in the entity class
30
31
  data = sanitize(entity_or_hash)
31
32
  else
@@ -66,7 +67,7 @@ module SBF
66
67
  data.file = file
67
68
  data
68
69
  else
69
- photo = SBF::Client::Photo.new(data.is_a?(Hash) && data.any? ? data : {})
70
+ photo = SBF::Client::Photo.new((data.is_a?(Hash) && data.any?) ? data : {}, clear_changes: false)
70
71
  photo.file = file
71
72
  photo
72
73
  end
@@ -18,7 +18,7 @@ module SBF
18
18
  # @option [Integer] :offset The query offset.
19
19
  # @return [Client::Api::Response] The data attribute on a successful response will be
20
20
  # an array of search entities matching the model type(s) specified
21
- def find(model_type, search_text = nil, filters = [], geo_location = {}, options = {})
21
+ def find(model_type, search_text: nil, filters: [], geo_location: {}, options: {})
22
22
  if [search_text, filters, geo_location].all?(&:empty?)
23
23
  raise SBF::Client::Error, 'Must provide either a search_text, filter or geo_location for the query'
24
24
  end
@@ -45,7 +45,7 @@ module SBF
45
45
  response_data[:total_count] = parsed_response_body[:total]
46
46
  response_data[:results] = [].tap do |arr|
47
47
  parsed_response_body[:hits].each do |entity_data|
48
- arr << target_class.const_get(entity_data[:type].capitalize).new(entity_data[:source])
48
+ arr << target_class.const_get(entity_data[:type].capitalize).new(entity_data[:source], clear_changes: false)
49
49
  end
50
50
  end
51
51
 
@@ -20,7 +20,7 @@ module SBF
20
20
 
21
21
  if ok?(response)
22
22
  SBF::Client::Configuration.user_token = parsed_response[:token]
23
- data = parsed_response.merge(user: target_class.new(parsed_response[:user]))
23
+ data = parsed_response.merge(user: target_class.new(parsed_response[:user], clear_changes: false))
24
24
  else
25
25
  SBF::Client::Configuration.user_token = nil
26
26
  error = SBF::Client::ErrorEntity.new(parsed_response)
@@ -12,17 +12,15 @@ module SBF
12
12
  PROCESSED = 'processed'.freeze
13
13
  end
14
14
 
15
- attr_accessor :id
16
- attr_accessor :type
15
+ attr_accessor :id, :type, :amount, :filename, :created_at, :modified_at, :processed_at, :submitted_by
16
+
17
17
  multitype_attr_accessor(
18
18
  :payment_details, [
19
19
  [->(v) { v[:type] == SBF::Client::Payment::Type::CREDIT_CARD }, 'SBF::Client::Payment::CreditCardDetails'],
20
20
  [->(v) { v[:type] == SBF::Client::Payment::Type::NONCE }, 'SBF::Client::Payment::NonceDetails']
21
21
  ]
22
22
  )
23
- attr_accessor :amount
24
- attr_accessor :filename
25
- attr_accessor :created_at, :modified_at, :processed_at, :submitted_by
23
+
26
24
  entity_collection_attr_accessor :donations, 'SBF::Client::FullDonation', 'SBF::Client::PartialDonation'
27
25
  end
28
26
  end
@@ -12,13 +12,7 @@ module SBF
12
12
  action :find_by_category
13
13
  action :find_by_tag
14
14
 
15
- attr_reader :id
16
- attr_reader :slug
17
- attr_reader :url
18
- attr_reader :title
19
- attr_reader :content
20
- attr_reader :published_at
21
- attr_reader :modified_at
15
+ attr_reader :id, :slug, :url, :title, :content, :published_at, :modified_at
22
16
  end
23
17
  end
24
18
  end
@@ -12,12 +12,8 @@ module SBF
12
12
  disallow_instantiation
13
13
 
14
14
  class Totals < SBF::Client::BaseEntity
15
- attr_reader :current_year_amount_raised
16
- attr_reader :previous_year_amount_raised
17
- attr_reader :all_years_amount_raised
18
- attr_reader :participants
19
- attr_reader :shavees
20
- attr_reader :number_of_events
15
+ attr_reader :current_year_amount_raised, :previous_year_amount_raised, :all_years_amount_raised, :participants,
16
+ :shavees, :number_of_events
21
17
  end
22
18
  end
23
19
 
@@ -26,15 +22,12 @@ module SBF
26
22
  end
27
23
 
28
24
  class FullCampaign < Campaign
29
- attr_accessor :id
30
- attr_accessor :name
31
- attr_accessor :website_url
32
- attr_accessor :is_enabled
25
+ attr_accessor :id, :name, :website_url, :is_enabled
33
26
 
34
- entity_attr_reader :totals, 'SBF::Client::Campaign::Totals', nil, true
35
- entity_attr_accessor :web_page, 'SBF::Client::WebPage', nil, true
27
+ entity_attr_reader :totals, 'SBF::Client::Campaign::Totals', nil, optional: true
28
+ entity_attr_accessor :web_page, 'SBF::Client::WebPage', nil, optional: true
36
29
 
37
- entity_attr_accessor :photo, 'SBF::Client::Photo', nil, true
30
+ entity_attr_accessor :photo, 'SBF::Client::Photo', nil, optional: true
38
31
  end
39
32
  end
40
33
  end
@@ -16,13 +16,11 @@ module SBF
16
16
  DECLINED = 'declined'.freeze
17
17
  end
18
18
 
19
- attr_accessor :id
20
- attr_accessor :status
21
- attr_accessor :end_date
22
- entity_attr_accessor :challenger, 'SBF::Client::Challenger', nil, true
23
- entity_attr_accessor :challengee, 'SBF::Client::Challenger', nil, true
19
+ attr_accessor :id, :status, :end_date, :modified_by
20
+
21
+ entity_attr_accessor :challenger, 'SBF::Client::Challenger', nil, optional: true
22
+ entity_attr_accessor :challengee, 'SBF::Client::Challenger', nil, optional: true
24
23
  attr_reader :created_at, :modified_at
25
- attr_accessor :modified_by
26
24
  end
27
25
  end
28
26
  end
@@ -97,11 +97,9 @@ module SBF
97
97
  end
98
98
  end
99
99
 
100
- attr_accessor :id
101
- attr_accessor :challenge_id
102
- attr_accessor :type
103
- attr_accessor :is_accepted
104
- entity_attr_reader :totals, 'SBF::Client::Challenger::Totals', nil, true
100
+ attr_accessor :id, :challenge_id, :type, :is_accepted
101
+
102
+ entity_attr_reader :totals, 'SBF::Client::Challenger::Totals', nil, optional: true
105
103
 
106
104
  multitype_attr_accessor(
107
105
  :entity,
@@ -127,7 +125,7 @@ module SBF
127
125
  'SBF::Client::Challenger::PartialEvent'
128
126
  ]
129
127
  ],
130
- true
128
+ optional: true
131
129
  )
132
130
  end
133
131
  end
@@ -59,7 +59,7 @@ module EntityResponseConcern
59
59
  caller_message = method_caller.nil? ? '' : " Called from #{method_caller.first}"
60
60
 
61
61
  "[DEPRECATION] Use of the SBF::Client::Api::Response Interface (including the `#{method_name}` method) is deprecated"\
62
- " for #{self.class}. Please update your code to use the #{self.class} interface accordingly. #{caller_message}"
62
+ " for #{self.class}. Please update your code to use the #{self.class} interface accordingly. #{caller_message}"
63
63
  end
64
64
  end
65
65
  end
@@ -11,14 +11,9 @@ module SBF
11
11
  action :get
12
12
  instance_action :reload
13
13
 
14
- attr_reader :default_year
15
- attr_reader :open_registration_years
16
- attr_reader :website_url
17
- attr_reader :years_for_squire
18
- attr_reader :years_for_knight
19
- attr_reader :years_for_knight_commander
20
- attr_reader :years_for_crusader
21
- attr_reader :years_for_baron
14
+ attr_reader :default_year, :open_registration_years, :website_url, :years_for_squire, :years_for_knight, :years_for_knight_commander,
15
+ :years_for_crusader, :years_for_baron
16
+
22
17
  # NOTE: If you add another attribute, be sure to mock it out in `configure :test` of app.rb
23
18
 
24
19
  # Attempts to call the method on the cached configuration object
@@ -14,22 +14,19 @@ module SBF
14
14
  WEBSITE = 'website'.freeze
15
15
  end
16
16
 
17
- attr_reader :id
17
+ attr_reader :id, :display_name, :email, :created_at, :modified_at
18
+
18
19
  entity_attr_accessor :owner, 'SBF::Client::FullPerson', 'SBF::Client::PartialPerson'
19
20
  entity_attr_accessor :person, 'SBF::Client::FullPerson', 'SBF::Client::PartialPerson'
20
21
  attr_accessor :type
21
- attr_reader :display_name
22
- attr_reader :email
23
- attr_reader :created_at, :modified_at
22
+
24
23
  entity_collection_attr_reader :contact_groups, 'SBF::Client::ContactGroup'
25
24
  end
26
25
 
27
26
  class CustomContact < SBF::Client::Contact
28
27
  endpoint SBF::Client::ContactEndpoint
29
28
 
30
- attr_accessor :id
31
- attr_accessor :display_name
32
- attr_accessor :email
29
+ attr_accessor :id, :display_name, :email
33
30
  end
34
31
  end
35
32
  end
@@ -8,8 +8,8 @@ module SBF
8
8
  class ContactGroup < SBF::Client::TopLevelEntity
9
9
  actions DEFAULT_CRUD_ACTIONS
10
10
 
11
- attr_accessor :id
12
- attr_accessor :display_name
11
+ attr_accessor :id, :display_name
12
+
13
13
  entity_attr_accessor :owner, 'SBF::Client::FullPerson'
14
14
  multitype_collection_attr_accessor(
15
15
  :contacts,
@@ -6,12 +6,7 @@ module SBF
6
6
  action :get
7
7
  action :find
8
8
 
9
- attr_accessor :id
10
- attr_accessor :from_profile_id
11
- attr_accessor :to_profile_id
12
- attr_accessor :checkout_id
13
- attr_accessor :change_history
14
- attr_accessor :date_merged
9
+ attr_accessor :id, :from_profile_id, :to_profile_id, :checkout_id, :change_history, :date_merged
15
10
  end
16
11
  end
17
12
  end
@@ -27,13 +27,10 @@ module SBF
27
27
  ERROR_OUT_OF_SYNC_UPDATE = 'error_out_of_sync_update'.freeze
28
28
  end
29
29
 
30
- attr_accessor :id
31
- attr_accessor :checkout_id
32
- attr_accessor :status
33
- attr_accessor :date_created
34
- attr_accessor :date_modified
35
- entity_collection_attr_accessor :persons, 'SBF::Client::FullPerson', nil, true
36
- entity_collection_attr_accessor :organizations, 'SBF::Client::FullOrganization', nil, true
30
+ attr_accessor :id, :checkout_id, :status, :date_created, :date_modified
31
+
32
+ entity_collection_attr_accessor :persons, 'SBF::Client::FullPerson', nil, optional: true
33
+ entity_collection_attr_accessor :organizations, 'SBF::Client::FullOrganization', nil, optional: true
37
34
  end
38
35
  end
39
36
  end
@@ -13,11 +13,8 @@ module SBF
13
13
 
14
14
  disallow_instantiation
15
15
 
16
- attr_accessor :id
17
- attr_accessor :name
18
- attr_accessor :description
19
- attr_reader :created_at
20
- attr_reader :modified_at
16
+ attr_accessor :id, :name, :description
17
+ attr_reader :created_at, :modified_at
21
18
  end
22
19
  end
23
20
  end
@@ -6,14 +6,9 @@ module SBF
6
6
  class DocumentLibrary < SBF::Client::TopLevelEntity
7
7
  actions DEFAULT_CRUD_ACTIONS
8
8
 
9
- attr_accessor :id
10
- attr_accessor :type
11
- attr_accessor :title
12
- attr_accessor :description
13
- attr_accessor :url
14
- attr_accessor :media_storage_id
15
- attr_accessor :sort_order
16
- entity_attr_reader :category, 'SBF::Client::DocumentLibraryCategory', nil, true
9
+ attr_accessor :id, :type, :title, :description, :url, :media_storage_id, :sort_order
10
+
11
+ entity_attr_reader :category, 'SBF::Client::DocumentLibraryCategory', nil, optional: true
17
12
  end
18
13
  end
19
14
  end
@@ -5,10 +5,7 @@ module SBF
5
5
  class DocumentLibraryCategory < SBF::Client::TopLevelEntity
6
6
  actions DEFAULT_CRUD_ACTIONS
7
7
 
8
- attr_accessor :id
9
- attr_accessor :top_level_category
10
- attr_accessor :name
11
- attr_accessor :sort_order
8
+ attr_accessor :id, :top_level_category, :name, :sort_order
12
9
  end
13
10
  end
14
11
  end