atrium-ruby 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/atrium-ruby.gemspec +29 -0
- data/bin/console +14 -0
- data/bin/demo +50 -0
- data/bin/setup +8 -0
- data/lib/atrium.rb +34 -0
- data/lib/atrium/account.rb +61 -0
- data/lib/atrium/client.rb +42 -0
- data/lib/atrium/credential.rb +11 -0
- data/lib/atrium/error.rb +4 -0
- data/lib/atrium/institution.rb +27 -0
- data/lib/atrium/member.rb +176 -0
- data/lib/atrium/paginate.rb +85 -0
- data/lib/atrium/transaction.rb +50 -0
- data/lib/atrium/user.rb +105 -0
- data/lib/atrium/version.rb +3 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a0f84af859ed13efd9e0dc27521fb6badc1d550
|
4
|
+
data.tar.gz: 4f796b1636d69486d4bee97e905527b96629cae9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b0adeb06d2ae1f6b540afa5f6a74f9742c76b8079f41f0c55ccf2723abb53bc0c0d2a6782a5510fc79c0b029d54cc0e932ccab9cd4ea2633aca0b3c296d2199
|
7
|
+
data.tar.gz: 5815ce54d975ed4a693941084a7703643e699ef5a6b84a176c78f66c3e2e2c1a7bc1de7e20dad1f3a84e3c76d8343cb6691a7dfc8d468cb9001151a2070cb4fc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Atrium-Ruby
|
2
|
+
|
3
|
+
A Ruby wrapper for use with the [MX Atrium API](https://atrium.mx.com). In order to make requests, you will need to [sign up for MX Atrium API](https://atrium.mx.com/developers/sign_up) and get a `MX-API-KEY` and `MX-CLIENT-ID`. Then, configure your instance with:
|
4
|
+
```ruby
|
5
|
+
Atrium.configure do |config|
|
6
|
+
config.mx_api_key = YOUR_API_KEY
|
7
|
+
config.mx_client_id = YOUR_CLIENT_ID
|
8
|
+
end
|
9
|
+
```
|
10
|
+
|
11
|
+
From there, you can start using some basic class methods to make calls for data. See our [full documentation](https://atrium.mx.com/documentation) for more details.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'atrium-ruby'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install atrium-ruby
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
Suggested implementation flow can be found in `bin/demo` comments. You can also use that as an executable for managing the settings and creating your own test flow to handle the requests and data with `./bin/demo`
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mxenabled/atrium-ruby.
|
data/Rakefile
ADDED
data/atrium-ruby.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'atrium/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "atrium-ruby"
|
8
|
+
spec.version = ::Atrium::VERSION
|
9
|
+
spec.authors = ["Jon Carstens, Dan Jones, Zach Toolson"]
|
10
|
+
spec.email = ["jon.carstens@mx.com, dan.jones@mx.com, zach.toolson@mx.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby wrapper for the Atrium API by MX"
|
13
|
+
spec.description = "Ruby wrapper for the Atrium API by MX"
|
14
|
+
spec.homepage = "http://github.com/mxenabled/atrium-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "active_attr"
|
23
|
+
spec.add_runtime_dependency "httpclient"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "atrium"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/demo
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "atrium"
|
4
|
+
require "pry"
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
def load_settings
|
8
|
+
if ::File.exists?("tmp/settings.yml")
|
9
|
+
puts "=> Using key and ID in tmp/settings.yml ¬"
|
10
|
+
::YAML.load(::File.read("tmp/settings.yml"))
|
11
|
+
else
|
12
|
+
settings = {}
|
13
|
+
puts "What is your MX-API-KEY?"
|
14
|
+
settings[:mx_api_key] = gets.chomp
|
15
|
+
|
16
|
+
puts "What is your Client ID?"
|
17
|
+
settings[:mx_client_id] = gets.chomp
|
18
|
+
|
19
|
+
puts "Would you like to save API key and client ID for future use?"
|
20
|
+
case gets.chomp
|
21
|
+
when /y/i
|
22
|
+
::File.open("tmp/settings.yml", "w") { |f| f.write(settings.to_yaml) }
|
23
|
+
puts "Settings written to tmp/settings.yml ¬"
|
24
|
+
settings
|
25
|
+
when /n/i
|
26
|
+
puts "One-time use settings ¬"
|
27
|
+
settings
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
settings = load_settings
|
34
|
+
settings.each { |k,v| puts "\t#{k}: #{v}" }
|
35
|
+
|
36
|
+
::Atrium.configure do |config|
|
37
|
+
config.mx_client_id = settings[:mx_client_id]
|
38
|
+
config.mx_api_key = settings[:mx_api_key]
|
39
|
+
end
|
40
|
+
|
41
|
+
## Example flow
|
42
|
+
#
|
43
|
+
# 1. Create a User
|
44
|
+
# 2. Read that user data via GUID
|
45
|
+
# 3. List Institutions
|
46
|
+
# 4. Get credentials for institution
|
47
|
+
# 5. Create member on user
|
48
|
+
# 6. Check member aggregation status
|
49
|
+
# 7. Read other user data (accounts, members, transactions)
|
50
|
+
#
|
data/bin/setup
ADDED
data/lib/atrium.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "active_attr"
|
2
|
+
require "httpclient"
|
3
|
+
require "json"
|
4
|
+
require "atrium/paginate"
|
5
|
+
|
6
|
+
require "atrium/account"
|
7
|
+
require "atrium/client"
|
8
|
+
require "atrium/credential"
|
9
|
+
require "atrium/error"
|
10
|
+
require "atrium/institution"
|
11
|
+
require "atrium/member"
|
12
|
+
require "atrium/transaction"
|
13
|
+
require "atrium/user"
|
14
|
+
require "atrium/version"
|
15
|
+
|
16
|
+
module Atrium
|
17
|
+
BASE_URL = "https://vestibule.mx.com".freeze
|
18
|
+
##
|
19
|
+
# mx-api-key and mx-client-id are required for Atrium
|
20
|
+
#
|
21
|
+
# Atrium.configure do |config|
|
22
|
+
# config.mx_api_key = generated_api_key
|
23
|
+
# config.mx_client_id = generated_client_id
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
class << self
|
27
|
+
attr_reader :client
|
28
|
+
|
29
|
+
def configure
|
30
|
+
@client = ::Atrium::Client.new
|
31
|
+
yield @client
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Atrium
|
2
|
+
class Account
|
3
|
+
include ::ActiveAttr::Model
|
4
|
+
|
5
|
+
# ATTRIBUTES
|
6
|
+
attribute :apr
|
7
|
+
attribute :apy
|
8
|
+
attribute :available_balance
|
9
|
+
attribute :available_credit
|
10
|
+
attribute :balance
|
11
|
+
attribute :created_at
|
12
|
+
attribute :credit_limit
|
13
|
+
attribute :day_payment_is_due
|
14
|
+
attribute :guid
|
15
|
+
attribute :institution_code
|
16
|
+
attribute :interest_rate
|
17
|
+
attribute :is_closed
|
18
|
+
attribute :last_payment
|
19
|
+
attribute :last_payment_at
|
20
|
+
attribute :matures_on
|
21
|
+
attribute :member_guid
|
22
|
+
attribute :minimum_balance
|
23
|
+
attribute :minimum_payment
|
24
|
+
attribute :name
|
25
|
+
attribute :original_balance
|
26
|
+
attribute :payment_due_at
|
27
|
+
attribute :payoff_balance
|
28
|
+
attribute :started_on
|
29
|
+
attribute :subtype
|
30
|
+
attribute :total_account_value
|
31
|
+
attribute :type
|
32
|
+
attribute :updated_at
|
33
|
+
attribute :user_guid
|
34
|
+
|
35
|
+
def self.list(user_guid:)
|
36
|
+
endpoint = "/users/#{user_guid}/accounts"
|
37
|
+
accounts_response = ::Atrium.client.make_request(:get, endpoint)
|
38
|
+
|
39
|
+
accounts = accounts_response["accounts"].map do |account|
|
40
|
+
::Atrium::Account.new(account)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.read(user_guid:, account_guid:)
|
45
|
+
endpoint = "/users/#{user_guid}/accounts/#{account_guid}"
|
46
|
+
account_response = ::Atrium.client.make_request(:get, endpoint)
|
47
|
+
|
48
|
+
account_params = account_response["account"]
|
49
|
+
::Atrium::Account.new(account_params)
|
50
|
+
end
|
51
|
+
|
52
|
+
def transactions
|
53
|
+
endpoint = "/users/#{self.user_guid}/accounts/#{self.guid}/transactions"
|
54
|
+
account_transactions_response = ::Atrium.client.make_request(:get, endpoint)
|
55
|
+
|
56
|
+
transactions = account_transactions_response["transactions"].map do |transaction|
|
57
|
+
::Atrium::Transaction.new(transaction)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Atrium
|
2
|
+
class Client
|
3
|
+
attr_accessor :mx_api_key, :mx_client_id
|
4
|
+
|
5
|
+
def initialize(api_key = nil, client_id = nil)
|
6
|
+
@mx_api_key = api_key
|
7
|
+
@mx_client_id = client_id
|
8
|
+
end
|
9
|
+
|
10
|
+
def make_request(method, endpoint, body = {}, headers = {})
|
11
|
+
headers = default_headers.merge(headers)
|
12
|
+
url = "#{::Atrium::BASE_URL}#{endpoint}"
|
13
|
+
response = http_client.public_send(method, url, ::JSON.dump(body), headers)
|
14
|
+
|
15
|
+
handle_response(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def http_client
|
19
|
+
@http_client ||= ::HTTPClient.new
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def default_headers
|
25
|
+
{
|
26
|
+
"Accept" => "application/vnd.mx.atrium.v1+json",
|
27
|
+
"Content-Type" => "application/json",
|
28
|
+
"MX-API-KEY" => mx_api_key,
|
29
|
+
"MX-CLIENT-ID" => mx_client_id
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle_response(response)
|
34
|
+
# Handle 200-206 responses as acceptable
|
35
|
+
unless response.status.between?(200, 206)
|
36
|
+
fail ::Atrium::Error, "#{response.status}: #{response.body}"
|
37
|
+
end
|
38
|
+
|
39
|
+
::JSON.parse(response.body) unless response.body.empty?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/atrium/error.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Atrium
|
2
|
+
class Institution
|
3
|
+
extend ::Atrium::Paginate
|
4
|
+
include ::ActiveAttr::Model
|
5
|
+
|
6
|
+
attribute :code
|
7
|
+
attribute :name
|
8
|
+
attribute :url
|
9
|
+
|
10
|
+
def self.credentials(institution_code)
|
11
|
+
endpoint = "/institutions/#{institution_code}/credentials"
|
12
|
+
response = ::Atrium.client.make_request(:get, endpoint)
|
13
|
+
|
14
|
+
response["credentials"].map do |credential|
|
15
|
+
::Atrium::Credential.new(credential)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.list(query_params: nil, limit: nil)
|
20
|
+
paginate_endpoint(query_params: query_params, limit: limit)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.list_in_batches(query_params: nil, limit: nil, &block)
|
24
|
+
paginate_endpoint_in_batches(query_params: query_params, limit: limit, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
module Atrium
|
2
|
+
class Member
|
3
|
+
include ::ActiveAttr::Model
|
4
|
+
include ::ActiveAttr::Attributes
|
5
|
+
|
6
|
+
attribute :aggregated_at
|
7
|
+
attribute :guid
|
8
|
+
attribute :identifier
|
9
|
+
attribute :institution_code
|
10
|
+
attribute :metadata
|
11
|
+
attribute :name
|
12
|
+
attribute :status
|
13
|
+
attribute :successfully_aggregated_at
|
14
|
+
attribute :user_guid
|
15
|
+
|
16
|
+
##
|
17
|
+
# CLASS METHODS
|
18
|
+
#
|
19
|
+
def self.create(user_guid:, institution_code:, credentials:)
|
20
|
+
endpoint = "/users/#{user_guid}/members"
|
21
|
+
body = create_params(institution_code, credentials)
|
22
|
+
member_response = ::Atrium.client.make_request(:post, endpoint, body)
|
23
|
+
|
24
|
+
member_params = member_response["member"]
|
25
|
+
::Atrium::Member.new(member_params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.list(user_guid:)
|
29
|
+
endpoint = "/users/#{user_guid}/members"
|
30
|
+
members_response = ::Atrium.client.make_request(:get, endpoint)
|
31
|
+
|
32
|
+
members_response["members"].map do |member|
|
33
|
+
::Atrium::Member.new(member)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.read(user_guid:, member_guid:)
|
38
|
+
endpoint = "/users/#{user_guid}/members/#{member_guid}"
|
39
|
+
member_response = ::Atrium.client.make_request(:get, endpoint)
|
40
|
+
|
41
|
+
member_params = member_response["member"]
|
42
|
+
::Atrium::Member.new(member_params)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# INSTANCE METHODS
|
47
|
+
#
|
48
|
+
def accounts
|
49
|
+
endpoint = "users/#{self.user_guid}/members/#{self.guid}/account"
|
50
|
+
accounts_response = ::Atrium.client.make_request(:get, endpoint)
|
51
|
+
|
52
|
+
accounts_response["accounts"].map do |account|
|
53
|
+
::Atrium::Account.new(account)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def aggregate
|
58
|
+
endpoint = "users/#{self.user_guid}/members/#{self.guid}/aggregate"
|
59
|
+
member_response = ::Atrium.client.make_request(:post, endpoint)
|
60
|
+
|
61
|
+
member_params = member_response["member"]
|
62
|
+
self.assign_attributes(member_params)
|
63
|
+
self
|
64
|
+
end
|
65
|
+
|
66
|
+
def aggregation_status
|
67
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}/status"
|
68
|
+
member_response = ::Atrium.client.make_request(:get, endpoint)
|
69
|
+
|
70
|
+
member_params = member_response["member"]
|
71
|
+
self.assign_attributes(member_params)
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
def challenges
|
76
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}/challenges"
|
77
|
+
member_response = ::Atrium.client.make_request(:get, endpoint)
|
78
|
+
|
79
|
+
member_params = member_response["member"]
|
80
|
+
self.assign_attributes(member_params)
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete
|
85
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}"
|
86
|
+
::Atrium.client.make_request(:delete, endpoint)
|
87
|
+
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def read_account(account_guid:)
|
92
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}/accounts/#{account_guid}"
|
93
|
+
account_response = ::Atrium.client.make_request(:get, endpoint)
|
94
|
+
|
95
|
+
account_params = account_response["account"]
|
96
|
+
::Atrium::Account.new(account_params)
|
97
|
+
end
|
98
|
+
|
99
|
+
def resume(challenge_credentials)
|
100
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}/resume"
|
101
|
+
body = resume_params(challenge_credentials)
|
102
|
+
member_response = ::Atrium.client.make_request(:get, endpoint, body)
|
103
|
+
|
104
|
+
member_params = member_response["member"]
|
105
|
+
self.assign_attributes(member_params)
|
106
|
+
self
|
107
|
+
end
|
108
|
+
|
109
|
+
def update(params)
|
110
|
+
endpoint = "/users/#{self.user_guid}/members/#{self.guid}"
|
111
|
+
body = member_body(params)
|
112
|
+
member_response = ::Atrium.client.make_request(:put, endpoint, body)
|
113
|
+
|
114
|
+
member_params = member_response["member"]
|
115
|
+
self.assign_attributes(member_params)
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
def transactions
|
120
|
+
endpoint = "users/#{self.user_guid}/members/#{self.guid}/transactions"
|
121
|
+
transactions_response = ::Atrium.client.make_request(:post, endpoint)
|
122
|
+
|
123
|
+
transactions_response["transactions"].map do |transaction|
|
124
|
+
::Atrium::Transaction.new(transaction)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
##
|
129
|
+
# PRIVATE CLASS METHODS
|
130
|
+
#
|
131
|
+
def self.create_params(institution_code, credentials_array)
|
132
|
+
{
|
133
|
+
:member => {
|
134
|
+
:institution_code => institution_code,
|
135
|
+
:credentials => credentials_array
|
136
|
+
}
|
137
|
+
}
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.member_body(params)
|
141
|
+
{
|
142
|
+
:member => {
|
143
|
+
:credentials => params[:credentials],
|
144
|
+
:identifier => params[:identifier],
|
145
|
+
:institution_code => params[:institution_code],
|
146
|
+
:metadata => params[:metadata]
|
147
|
+
}
|
148
|
+
}
|
149
|
+
end
|
150
|
+
private_class_method :create_params, :member_body
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
##
|
155
|
+
# PRIVATE INSTANCE METHODS
|
156
|
+
#
|
157
|
+
def member_body(params)
|
158
|
+
{
|
159
|
+
:member => {
|
160
|
+
:credentials => params[:credentials],
|
161
|
+
:identifier => params[:identifier],
|
162
|
+
:institution_code => params[:institution_code],
|
163
|
+
:metadata => params[:metadata]
|
164
|
+
}
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
168
|
+
def resume_params(challenge_credentials)
|
169
|
+
{
|
170
|
+
:member => {
|
171
|
+
:credentials => challenge_credentials
|
172
|
+
}
|
173
|
+
}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "URI"
|
2
|
+
|
3
|
+
module Atrium
|
4
|
+
module Paginate
|
5
|
+
DEFAULT_RECORDS_PER_PAGE = 25
|
6
|
+
INITIAL_PAGE = 1
|
7
|
+
|
8
|
+
attr_accessor :current_page, :endpoint, :total_pages
|
9
|
+
|
10
|
+
def endpoint_name(query_params: nil)
|
11
|
+
@endpoint = if query_params.present?
|
12
|
+
klass_name + "?" + URI.encode_www_form(query_params) + "&"
|
13
|
+
else
|
14
|
+
klass_name + "?"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_total_pages
|
19
|
+
@current_page = INITIAL_PAGE
|
20
|
+
|
21
|
+
paginated_endpoint = endpoint + "page=#{current_page}&records_per_page=#{records_per_page}"
|
22
|
+
response = ::Atrium.client.make_request(:get, paginated_endpoint)
|
23
|
+
|
24
|
+
pagination = response["pagination"]
|
25
|
+
@total_pages = pagination["total_pages"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def klass_name
|
29
|
+
@klass_name ||= self.name.gsub("Atrium::", "").downcase.pluralize
|
30
|
+
end
|
31
|
+
|
32
|
+
def paginate_endpoint(query_params: nil, limit: nil)
|
33
|
+
endpoint_name(query_params: query_params)
|
34
|
+
get_total_pages
|
35
|
+
response_list(limit: limit)
|
36
|
+
end
|
37
|
+
|
38
|
+
def paginate_endpoint_in_batches(query_params: nil, limit: nil, &block)
|
39
|
+
return "method requires block to be passed" unless block_given?
|
40
|
+
|
41
|
+
endpoint_name(query_params: query_params)
|
42
|
+
get_total_pages
|
43
|
+
response_list_in_batches(limit: limit, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def records_per_page
|
47
|
+
@records_per_page ||= DEFAULT_RECORDS_PER_PAGE
|
48
|
+
end
|
49
|
+
|
50
|
+
def response_list(limit: nil)
|
51
|
+
# "total_pages > 1" check exists since some query_params only return 1 page
|
52
|
+
@total_pages = limit / records_per_page if limit.present? && total_pages > 1
|
53
|
+
list = []
|
54
|
+
|
55
|
+
until current_page > total_pages
|
56
|
+
paginated_endpoint = endpoint + "page=#{current_page}&records_per_page=#{records_per_page}"
|
57
|
+
response = ::Atrium.client.make_request(:get, paginated_endpoint)
|
58
|
+
|
59
|
+
# Add new objects to the list
|
60
|
+
response["#{klass_name}"].each do |params|
|
61
|
+
list << self.new(params)
|
62
|
+
end
|
63
|
+
@current_page += 1
|
64
|
+
end
|
65
|
+
list
|
66
|
+
end
|
67
|
+
|
68
|
+
def response_list_in_batches(limit: nil, &block)
|
69
|
+
# "total_pages > 1" check exists since some query_params only return 1 page
|
70
|
+
@total_pages = limit / records_per_page if limit.present? && total_pages > 1
|
71
|
+
|
72
|
+
until current_page > total_pages
|
73
|
+
paginated_endpoint = endpoint + "page=#{current_page}&records_per_page=#{records_per_page}"
|
74
|
+
response = ::Atrium.client.make_request(:get, paginated_endpoint)
|
75
|
+
list = []
|
76
|
+
|
77
|
+
response["#{klass_name}"].each do |params|
|
78
|
+
list << self.new(params)
|
79
|
+
end
|
80
|
+
@current_page += 1
|
81
|
+
yield list
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Atrium
|
2
|
+
class Transaction
|
3
|
+
include ::ActiveAttr::Model
|
4
|
+
|
5
|
+
attribute :account_guid
|
6
|
+
attribute :amount
|
7
|
+
attribute :category
|
8
|
+
attribute :check_number
|
9
|
+
attribute :created_at
|
10
|
+
attribute :date
|
11
|
+
attribute :description
|
12
|
+
attribute :guid
|
13
|
+
attribute :is_bill_pay
|
14
|
+
attribute :is_direct_deposit
|
15
|
+
attribute :is_expense
|
16
|
+
attribute :is_fee
|
17
|
+
attribute :is_income
|
18
|
+
attribute :is_overdraft_fee
|
19
|
+
attribute :is_payroll_advance
|
20
|
+
attribute :latitude
|
21
|
+
attribute :longitude
|
22
|
+
attribute :member_guid
|
23
|
+
attribute :memo
|
24
|
+
attribute :merchant_category_code
|
25
|
+
attribute :original_description
|
26
|
+
attribute :posted_at
|
27
|
+
attribute :status
|
28
|
+
attribute :top_level_category
|
29
|
+
attribute :transacted_at
|
30
|
+
attribute :type
|
31
|
+
attribute :updated_at
|
32
|
+
attribute :user_guid
|
33
|
+
|
34
|
+
def self.list(user_guid:)
|
35
|
+
endpoint = "/users/#{user_guid}/transactions"
|
36
|
+
raw_transactions = ::Atrium.client.make_request(:get, endpoint)
|
37
|
+
|
38
|
+
raw_transactions["transactions"].map do |raw_transaction|
|
39
|
+
::Atrium::Transaction.new(raw_transaction)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.read(user_guid:, transaction_guid:)
|
44
|
+
endpoint = "/users/#{user_guid}/transactions/#{transaction_guid}"
|
45
|
+
raw_transaction = ::Atrium.client.make_request(:get, endpoint)
|
46
|
+
|
47
|
+
::Atrium::Transaction.new(raw_transaction["transaction"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/atrium/user.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
module Atrium
|
2
|
+
class User
|
3
|
+
include ::ActiveAttr::Model
|
4
|
+
|
5
|
+
# ATTRIBUTES
|
6
|
+
attribute :guid
|
7
|
+
attribute :identifier
|
8
|
+
attribute :is_disabled
|
9
|
+
attribute :metadata
|
10
|
+
|
11
|
+
##
|
12
|
+
# CLASS METHODS
|
13
|
+
#
|
14
|
+
def self.create(identifier:, is_disabled:, metadata:)
|
15
|
+
endpoint = "/users"
|
16
|
+
body = user_body(identifier, is_disabled, metadata)
|
17
|
+
response = ::Atrium.client.make_request(:post, endpoint, body)
|
18
|
+
|
19
|
+
user_params = response["user"]
|
20
|
+
::Atrium::User.new(user_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.list
|
24
|
+
endpoint = "/users"
|
25
|
+
users_response = ::Atrium.client.make_request(:get, endpoint)
|
26
|
+
|
27
|
+
users_response["users"].map do |user|
|
28
|
+
::Atrium::User.new(user)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.read(guid:)
|
33
|
+
endpoint = "/users/#{guid}"
|
34
|
+
response = ::Atrium.client.make_request(:get, endpoint)
|
35
|
+
|
36
|
+
user_params = response["user"]
|
37
|
+
::Atrium::User.new(user_params)
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# INSTANCE METHODS
|
42
|
+
#
|
43
|
+
def accounts
|
44
|
+
endpoint = "/users/#{self.guid}/accounts"
|
45
|
+
response = ::Atrium.client.make_request(:get, endpoint)
|
46
|
+
|
47
|
+
response["accounts"].map do |account|
|
48
|
+
::Atrium::Account.new(account)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete
|
53
|
+
endpoint = "/users/#{self.guid}"
|
54
|
+
::Atrium.client.make_request(:delete, endpoint)
|
55
|
+
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def members
|
60
|
+
endpoint = "/users/#{self.guid}/members"
|
61
|
+
response = ::Atrium.client.make_request(:get, endpoint)
|
62
|
+
|
63
|
+
response["members"].map do |member|
|
64
|
+
::Atrium::Member.new(member)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def transactions
|
69
|
+
endpoint = "/users/#{self.guid}/transactions"
|
70
|
+
response = ::Atrium.client.make_request(:get, endpoint)
|
71
|
+
|
72
|
+
response["transactions"].map do |transaction|
|
73
|
+
::Atrium::Transaction.new(transaction)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def update(params)
|
78
|
+
endpoint = "/users/#{self.guid}"
|
79
|
+
body = update_params(params)
|
80
|
+
response = ::Atrium.client.make_request(:put, endpoint, body)
|
81
|
+
|
82
|
+
user_params = response["user"]
|
83
|
+
self.assign_attributes(user_params)
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def update_params(params)
|
90
|
+
{
|
91
|
+
:user => params
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.user_body(identifier, is_disabled, metadata)
|
96
|
+
{
|
97
|
+
:user => {
|
98
|
+
:identifier => identifier,
|
99
|
+
:is_disabled => is_disabled,
|
100
|
+
:metadata => metadata
|
101
|
+
}
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: atrium-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Carstens, Dan Jones, Zach Toolson
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_attr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Ruby wrapper for the Atrium API by MX
|
98
|
+
email:
|
99
|
+
- jon.carstens@mx.com, dan.jones@mx.com, zach.toolson@mx.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- README.md
|
107
|
+
- Rakefile
|
108
|
+
- atrium-ruby.gemspec
|
109
|
+
- bin/console
|
110
|
+
- bin/demo
|
111
|
+
- bin/setup
|
112
|
+
- lib/atrium.rb
|
113
|
+
- lib/atrium/account.rb
|
114
|
+
- lib/atrium/client.rb
|
115
|
+
- lib/atrium/credential.rb
|
116
|
+
- lib/atrium/error.rb
|
117
|
+
- lib/atrium/institution.rb
|
118
|
+
- lib/atrium/member.rb
|
119
|
+
- lib/atrium/paginate.rb
|
120
|
+
- lib/atrium/transaction.rb
|
121
|
+
- lib/atrium/user.rb
|
122
|
+
- lib/atrium/version.rb
|
123
|
+
homepage: http://github.com/mxenabled/atrium-ruby
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Ruby wrapper for the Atrium API by MX
|
147
|
+
test_files: []
|