mx-platform-ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +20 -0
  3. data/.gitignore +13 -0
  4. data/.rubocop.yml +44 -0
  5. data/Gemfile +5 -0
  6. data/LICENSE +21 -0
  7. data/README.md +60 -0
  8. data/Rakefile +11 -0
  9. data/lib/mx-platform-ruby.rb +44 -0
  10. data/lib/mx-platform-ruby/account.rb +107 -0
  11. data/lib/mx-platform-ruby/account_number.rb +57 -0
  12. data/lib/mx-platform-ruby/account_owner.rb +42 -0
  13. data/lib/mx-platform-ruby/category.rb +127 -0
  14. data/lib/mx-platform-ruby/challenge.rb +37 -0
  15. data/lib/mx-platform-ruby/client.rb +59 -0
  16. data/lib/mx-platform-ruby/connect_widget.rb +43 -0
  17. data/lib/mx-platform-ruby/credential.rb +54 -0
  18. data/lib/mx-platform-ruby/enhanced_transaction.rb +44 -0
  19. data/lib/mx-platform-ruby/error.rb +6 -0
  20. data/lib/mx-platform-ruby/holding.rb +87 -0
  21. data/lib/mx-platform-ruby/institution.rb +78 -0
  22. data/lib/mx-platform-ruby/member.rb +242 -0
  23. data/lib/mx-platform-ruby/member_status.rb +35 -0
  24. data/lib/mx-platform-ruby/merchant.rb +52 -0
  25. data/lib/mx-platform-ruby/oauth_window.rb +32 -0
  26. data/lib/mx-platform-ruby/pageable.rb +29 -0
  27. data/lib/mx-platform-ruby/statement.rb +70 -0
  28. data/lib/mx-platform-ruby/tag.rb +104 -0
  29. data/lib/mx-platform-ruby/tagging.rb +107 -0
  30. data/lib/mx-platform-ruby/transaction.rb +162 -0
  31. data/lib/mx-platform-ruby/transaction_rule.rb +112 -0
  32. data/lib/mx-platform-ruby/user.rb +112 -0
  33. data/lib/mx-platform-ruby/version.rb +5 -0
  34. data/lib/mx-platform-ruby/widget.rb +49 -0
  35. data/mx-platform-ruby.gemspec +31 -0
  36. data/spec/lib/mx-platform-ruby/account_number_spec.rb +100 -0
  37. data/spec/lib/mx-platform-ruby/account_owner_spec.rb +71 -0
  38. data/spec/lib/mx-platform-ruby/account_spec.rb +267 -0
  39. data/spec/lib/mx-platform-ruby/category_spec.rb +244 -0
  40. data/spec/lib/mx-platform-ruby/challenge_spec.rb +72 -0
  41. data/spec/lib/mx-platform-ruby/client_spec.rb +101 -0
  42. data/spec/lib/mx-platform-ruby/connect_widget_spec.rb +66 -0
  43. data/spec/lib/mx-platform-ruby/credential_spec.rb +90 -0
  44. data/spec/lib/mx-platform-ruby/enhanced_transaction_spec.rb +89 -0
  45. data/spec/lib/mx-platform-ruby/holding_spec.rb +178 -0
  46. data/spec/lib/mx-platform-ruby/institution_spec.rb +141 -0
  47. data/spec/lib/mx-platform-ruby/member_spec.rb +557 -0
  48. data/spec/lib/mx-platform-ruby/member_status_spec.rb +76 -0
  49. data/spec/lib/mx-platform-ruby/merchant_spec.rb +89 -0
  50. data/spec/lib/mx-platform-ruby/oauth_window_spec.rb +47 -0
  51. data/spec/lib/mx-platform-ruby/pageable_spec.rb +75 -0
  52. data/spec/lib/mx-platform-ruby/statement_spec.rb +130 -0
  53. data/spec/lib/mx-platform-ruby/tag_spec.rb +179 -0
  54. data/spec/lib/mx-platform-ruby/tagging_spec.rb +191 -0
  55. data/spec/lib/mx-platform-ruby/transaction_rule_spec.rb +207 -0
  56. data/spec/lib/mx-platform-ruby/transaction_spec.rb +449 -0
  57. data/spec/lib/mx-platform-ruby/user_spec.rb +196 -0
  58. data/spec/lib/mx-platform-ruby/widget_spec.rb +76 -0
  59. data/spec/lib/mx-platform-ruby_spec.rb +15 -0
  60. data/spec/sample.pdf +0 -0
  61. data/spec/spec_helper.rb +24 -0
  62. metadata +63 -3
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class Institution
5
+ extend ::MXPlatformRuby::Pageable
6
+ include ::ActiveAttr::Model
7
+
8
+ attribute :code
9
+ attribute :medium_logo_url
10
+ attribute :name
11
+ attribute :small_logo_url
12
+ attribute :supports_account_identification
13
+ attribute :supports_account_statement
14
+ attribute :supports_account_verification
15
+ attribute :supports_oauth
16
+ attribute :supports_transaction_history
17
+ attribute :url
18
+
19
+ def self.list_favorites(options = {})
20
+ options = list_favorites_options(options)
21
+
22
+ paginate(options)
23
+ end
24
+
25
+ def self.list_institutions(options = {})
26
+ options = list_institutions_options(options)
27
+
28
+ paginate(options)
29
+ end
30
+
31
+ def self.read_institution(options = {})
32
+ read_institution_options = read_institution_options(options)
33
+ response = ::MXPlatformRuby.client.make_request(read_institution_options)
34
+
35
+ institution_params = response['institution']
36
+ ::MXPlatformRuby::Institution.new(institution_params)
37
+ end
38
+
39
+ # Private class methods
40
+
41
+ def self.list_favorites_options(options)
42
+ {
43
+ endpoint: '/institutions/favorites',
44
+ http_method: :get,
45
+ query_params: {
46
+ page: options[:page],
47
+ records_per_page: options[:records_per_page]
48
+ }.compact,
49
+ resource: 'institutions'
50
+ }
51
+ end
52
+ private_class_method :list_favorites_options
53
+
54
+ def self.list_institutions_options(options)
55
+ {
56
+ endpoint: '/institutions',
57
+ http_method: :get,
58
+ query_params: {
59
+ name: options[:name],
60
+ supports_account_identification: options[:supports_account_identification],
61
+ supports_account_statement: options[:supports_account_statement],
62
+ supports_account_verification: options[:supports_account_verification],
63
+ supports_transaction_history: options[:supports_transaction_history]
64
+ }.compact,
65
+ resource: 'institutions'
66
+ }
67
+ end
68
+ private_class_method :list_institutions_options
69
+
70
+ def self.read_institution_options(options)
71
+ {
72
+ endpoint: "/institutions/#{options[:institution_code]}",
73
+ http_method: :get
74
+ }
75
+ end
76
+ private_class_method :read_institution_options
77
+ end
78
+ end
@@ -0,0 +1,242 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class Member
5
+ extend ::MXPlatformRuby::Pageable
6
+ include ::ActiveAttr::Model
7
+
8
+ attribute :aggregated_at
9
+ attribute :connection_status
10
+ attribute :guid
11
+ attribute :id
12
+ attribute :institution_code
13
+ attribute :is_being_aggregated
14
+ attribute :is_oauth
15
+ attribute :metadata
16
+ attribute :name
17
+ attribute :oauth_window_uri
18
+ attribute :successfully_aggregated_at
19
+ attribute :user_guid
20
+
21
+ def self.aggregate_member(options = {})
22
+ aggregate_member_options = aggregate_member_options(options)
23
+ response = ::MXPlatformRuby.client.make_request(aggregate_member_options)
24
+
25
+ member_params = response['member']
26
+ ::MXPlatformRuby::Member.new(member_params)
27
+ end
28
+
29
+ def self.check_balances(options = {})
30
+ check_balances_options = check_balances_options(options)
31
+ response = ::MXPlatformRuby.client.make_request(check_balances_options)
32
+
33
+ member_params = response['member']
34
+ ::MXPlatformRuby::Member.new(member_params)
35
+ end
36
+
37
+ def self.create_member(options = {})
38
+ create_member_options = create_member_options(options)
39
+ response = ::MXPlatformRuby.client.make_request(create_member_options)
40
+
41
+ member_params = response['member']
42
+ ::MXPlatformRuby::Member.new(member_params)
43
+ end
44
+
45
+ def self.delete_member(options = {})
46
+ delete_member_options = delete_member_options(options)
47
+ ::MXPlatformRuby.client.make_request(delete_member_options)
48
+ end
49
+
50
+ def self.extend_history(options = {})
51
+ extend_history_options = extend_history_options(options)
52
+ response = ::MXPlatformRuby.client.make_request(extend_history_options)
53
+
54
+ member_params = response['member']
55
+ ::MXPlatformRuby::Member.new(member_params)
56
+ end
57
+
58
+ def self.fetch_statements_by_member(options = {})
59
+ fetch_statements_by_member_options = fetch_statements_by_member_options(options)
60
+ response = ::MXPlatformRuby.client.make_request(fetch_statements_by_member_options)
61
+
62
+ member_params = response['member']
63
+ ::MXPlatformRuby::Member.new(member_params)
64
+ end
65
+
66
+ def self.identify_member(options = {})
67
+ identify_member_options = identify_member_options(options)
68
+ response = ::MXPlatformRuby.client.make_request(identify_member_options)
69
+
70
+ member_params = response['member']
71
+ ::MXPlatformRuby::Member.new(member_params)
72
+ end
73
+
74
+ def self.list_members(options = {})
75
+ options = list_members_options(options)
76
+
77
+ paginate(options)
78
+ end
79
+
80
+ def self.read_member(options = {})
81
+ read_member_options = read_member_options(options)
82
+ response = ::MXPlatformRuby.client.make_request(read_member_options)
83
+
84
+ member_params = response['member']
85
+ ::MXPlatformRuby::Member.new(member_params)
86
+ end
87
+
88
+ def self.resume_aggregation(options = {})
89
+ resume_aggregation_options = resume_aggregation_options(options)
90
+ response = ::MXPlatformRuby.client.make_request(resume_aggregation_options)
91
+
92
+ member_params = response['member']
93
+ ::MXPlatformRuby::Member.new(member_params)
94
+ end
95
+
96
+ def self.update_member(options = {})
97
+ update_member_options = update_member_options(options)
98
+ response = ::MXPlatformRuby.client.make_request(update_member_options)
99
+
100
+ member_params = response['member']
101
+ ::MXPlatformRuby::Member.new(member_params)
102
+ end
103
+
104
+ def self.verify_member(options = {})
105
+ verify_member_options = verify_member_options(options)
106
+ response = ::MXPlatformRuby.client.make_request(verify_member_options)
107
+
108
+ member_params = response['member']
109
+ ::MXPlatformRuby::Member.new(member_params)
110
+ end
111
+
112
+ # Private class methods
113
+
114
+ def self.aggregate_member_options(options)
115
+ {
116
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/aggregate",
117
+ http_method: :post
118
+ }
119
+ end
120
+ private_class_method :aggregate_member_options
121
+
122
+ def self.check_balances_options(options)
123
+ {
124
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/check_balance",
125
+ http_method: :post
126
+ }
127
+ end
128
+ private_class_method :check_balances_options
129
+
130
+ def self.create_member_options(options)
131
+ {
132
+ endpoint: "/users/#{options[:user_guid]}/members",
133
+ http_method: :post,
134
+ request_body: {
135
+ member: {
136
+ background_aggregation_is_disabled: options[:background_aggregation_is_disabled],
137
+ credentials: options[:credentials],
138
+ id: options[:id],
139
+ institution_code: options[:institution_code],
140
+ is_oauth: options[:is_oauth],
141
+ metadata: options[:metadata],
142
+ skip_aggregation: options[:skip_aggregation]
143
+ }.compact,
144
+ referral_source: options[:referral_source],
145
+ ui_message_webview_url_scheme: options[:ui_message_webview_url_scheme]
146
+ }.compact
147
+ }
148
+ end
149
+ private_class_method :create_member_options
150
+
151
+ def self.delete_member_options(options)
152
+ {
153
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}",
154
+ http_method: :delete
155
+ }
156
+ end
157
+ private_class_method :delete_member_options
158
+
159
+ def self.extend_history_options(options)
160
+ {
161
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/extend_history",
162
+ http_method: :post
163
+ }
164
+ end
165
+ private_class_method :extend_history_options
166
+
167
+ def self.fetch_statements_by_member_options(options)
168
+ {
169
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/fetch_statements",
170
+ http_method: :post
171
+ }
172
+ end
173
+ private_class_method :fetch_statements_by_member_options
174
+
175
+ def self.identify_member_options(options)
176
+ {
177
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/identify",
178
+ http_method: :post
179
+ }
180
+ end
181
+ private_class_method :identify_member_options
182
+
183
+ def self.list_members_options(options)
184
+ {
185
+ endpoint: "/users/#{options[:user_guid]}/members",
186
+ http_method: :get,
187
+ query_params: {
188
+ page: options[:page],
189
+ records_per_page: options[:records_per_page]
190
+ }.compact,
191
+ resource: 'members'
192
+ }
193
+ end
194
+ private_class_method :list_members_options
195
+
196
+ def self.read_member_options(options)
197
+ {
198
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}",
199
+ http_method: :get
200
+ }
201
+ end
202
+ private_class_method :read_member_options
203
+
204
+ def self.resume_aggregation_options(options)
205
+ {
206
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/resume",
207
+ http_method: :put,
208
+ request_body: {
209
+ member: {
210
+ challenges: options[:challenges]
211
+ }.compact
212
+ }
213
+ }
214
+ end
215
+ private_class_method :resume_aggregation_options
216
+
217
+ def self.update_member_options(options)
218
+ {
219
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}",
220
+ http_method: :put,
221
+ request_body: {
222
+ member: {
223
+ background_aggregation_is_disabled: options[:background_aggregation_is_disabled],
224
+ credentials: options[:credentials],
225
+ id: options[:id],
226
+ metadata: options[:metadata],
227
+ skip_aggregation: options[:skip_aggregation]
228
+ }.compact
229
+ }
230
+ }
231
+ end
232
+ private_class_method :update_member_options
233
+
234
+ def self.verify_member_options(options)
235
+ {
236
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/verify",
237
+ http_method: :post
238
+ }
239
+ end
240
+ private_class_method :verify_member_options
241
+ end
242
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class MemberStatus
5
+ include ::ActiveAttr::Model
6
+
7
+ attribute :aggregated_at
8
+ attribute :challenges
9
+ attribute :connection_status
10
+ attribute :guid
11
+ attribute :has_processed_accounts
12
+ attribute :has_processed_transactions
13
+ attribute :is_authenticated
14
+ attribute :is_being_aggregated
15
+ attribute :successfully_aggregated_at
16
+
17
+ def self.read_member_status(options = {})
18
+ read_member_status_options = read_member_status_options(options)
19
+ response = ::MXPlatformRuby.client.make_request(read_member_status_options)
20
+
21
+ member_params = response['member']
22
+ ::MXPlatformRuby::MemberStatus.new(member_params)
23
+ end
24
+
25
+ # Private class methods
26
+
27
+ def self.read_member_status_options(options)
28
+ {
29
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/status",
30
+ http_method: :get
31
+ }
32
+ end
33
+ private_class_method :read_member_status_options
34
+ end
35
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class Merchant
5
+ extend ::MXPlatformRuby::Pageable
6
+ include ::ActiveAttr::Model
7
+
8
+ attribute :created_at
9
+ attribute :guid
10
+ attribute :logo_url
11
+ attribute :name
12
+ attribute :updated_at
13
+ attribute :website_url
14
+
15
+ def self.list_merchants(options = {})
16
+ options = list_merchants_options(options)
17
+
18
+ paginate(options)
19
+ end
20
+
21
+ def self.read_merchant(options = {})
22
+ read_merchant_options = read_merchant_options(options)
23
+ response = ::MXPlatformRuby.client.make_request(read_merchant_options)
24
+
25
+ merchant_params = response['merchant']
26
+ ::MXPlatformRuby::Merchant.new(merchant_params)
27
+ end
28
+
29
+ # Private class methods
30
+
31
+ def self.list_merchants_options(options)
32
+ {
33
+ endpoint: '/merchants',
34
+ http_method: :get,
35
+ query_params: {
36
+ page: options[:page],
37
+ records_per_page: options[:records_per_page]
38
+ }.compact,
39
+ resource: 'merchants'
40
+ }
41
+ end
42
+ private_class_method :list_merchants_options
43
+
44
+ def self.read_merchant_options(options)
45
+ {
46
+ endpoint: "/merchants/#{options[:merchant_guid]}",
47
+ http_method: :get
48
+ }
49
+ end
50
+ private_class_method :read_merchant_options
51
+ end
52
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class OAuthWindow
5
+ include ::ActiveAttr::Model
6
+
7
+ attribute :guid
8
+ attribute :oauth_window_uri
9
+
10
+ def self.request_oauth_window(options = {})
11
+ request_oauth_window_options = request_oauth_window_options(options)
12
+ response = ::MXPlatformRuby.client.make_request(request_oauth_window_options)
13
+
14
+ member_params = response['member']
15
+ ::MXPlatformRuby::OAuthWindow.new(member_params)
16
+ end
17
+
18
+ # Private class methods
19
+
20
+ def self.request_oauth_window_options(options)
21
+ {
22
+ endpoint: "/users/#{options[:user_guid]}/members/#{options[:member_guid]}/oauth_window_uri",
23
+ http_method: :get,
24
+ query_params: {
25
+ referral_source: options[:referral_source],
26
+ ui_message_webview_url_scheme: options[:ui_message_webview_url_scheme]
27
+ }.compact
28
+ }
29
+ end
30
+ private_class_method :request_oauth_window_options
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MXPlatformRuby
4
+ class Page < ::Array
5
+ attr_accessor :current_page, :per_page, :total_entries, :total_pages
6
+ end
7
+
8
+ module Pageable
9
+ def paginate(options = {})
10
+ klass = options.fetch(:klass, self)
11
+ resource = options.fetch(:resource)
12
+
13
+ response = ::MXPlatformRuby.client.make_request(options)
14
+ return nil if response.nil?
15
+
16
+ pagination = response['pagination']
17
+
18
+ records = response[resource].map { |attributes| klass.new(attributes) }
19
+
20
+ page = ::MXPlatformRuby::Page.new(records)
21
+ page.current_page = pagination['current_page']
22
+ page.per_page = pagination['per_page']
23
+ page.total_entries = pagination['total_entries']
24
+ page.total_pages = pagination['total_pages']
25
+
26
+ page
27
+ end
28
+ end
29
+ end