arux_app 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/arux_app.gemspec +24 -0
- data/lib/arux_app/api/account.rb +229 -0
- data/lib/arux_app/api/auth.rb +113 -0
- data/lib/arux_app/api/bank_info.rb +26 -0
- data/lib/arux_app/api/cart.rb +190 -0
- data/lib/arux_app/api/config.rb +64 -0
- data/lib/arux_app/api/nav.rb +29 -0
- data/lib/arux_app/api/student.rb +43 -0
- data/lib/arux_app/api.rb +46 -0
- data/lib/arux_app.rb +34 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3619d786915abb5811eca23385011342f49b7c5e7cf7be99c41a50d77972f53e
|
4
|
+
data.tar.gz: 145c55897cdd5fd3fcc9de07dcb837dd092c99f28c936908b0630e02df007d0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb3f7d2756410f4b1a94d71124b0179fd93bd5df33b545e4d4cdc2d97bef1dbf2687d9f82cb8ac21e02ad1ac8db0547a589b38870e630d2af4aebdddaa1feda3
|
7
|
+
data.tar.gz: e66d5f0b8cae74e1397cc657c01d4b19d6ebd65586fc28a7144ad10cac85fbfb6ca378a4a0f93a414904c5394c7306c8a228a0e5c0f4b5a8cffe667b29f93a8c
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
arux_app_gem
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2022 Arux Software, Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# AruxApp Gem
|
2
|
+
|
3
|
+
Gem for connecting to APIs for Arux.app common services.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'arux_app'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install arux_app
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Here is an example of how to get bank information for ACH purposes:
|
24
|
+
```ruby
|
25
|
+
bi = AruxApp::API::BankInfo.new
|
26
|
+
bi.get("091000019")
|
27
|
+
=> {"city"=>"MINNEAPOLIS", "addr1"=>"255 2ND AVE SOUTH", "name"=>"WELLS FARGO BANK NA (MINNESOTA)", "zip"=>"55479", "routing_number"=>"091000019", "id"=>"1cb7cd2e-c1c6-11e2-8fb0-12313d062143", "zip_ext"=>"0000", "office_type"=>"Main", "last_updated"=>"2004-02-20T00:00:00+00:00", "phone"=>"(800) 745-2426", "state"=>"MN"}
|
28
|
+
```
|
29
|
+
|
30
|
+
Here is an example of setting up an oauth2 flow:
|
31
|
+
```ruby
|
32
|
+
class LoginController < ActionController::Base
|
33
|
+
API_CONFIG = {client_id: "EXAMPLE-CLIENT-ID", client_secret: "EXAMPLE-CLIENT-SECRET", district_subdomain: "test", redirect_uri: "https://example.org/login"}
|
34
|
+
|
35
|
+
def login
|
36
|
+
code = params[:code]
|
37
|
+
|
38
|
+
if code.blank?
|
39
|
+
redirect_to AruxApp::API::Auth.new(API_CONFIG).authorization_url and return
|
40
|
+
else
|
41
|
+
auth = AruxApp::API::Auth.new(API_CONFIG)
|
42
|
+
access_token = auth.access_token(code)
|
43
|
+
|
44
|
+
user_data = access_token.user_data
|
45
|
+
# log the user in based on the user_data json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/[my-github-username]/arux_app_gem/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/arux_app.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "arux_app"
|
7
|
+
spec.version = "1.0.0"
|
8
|
+
spec.authors = ["Arux Software"]
|
9
|
+
spec.email = ["sheuer@aruxsoftware.com"]
|
10
|
+
spec.summary = "Ruby gem for interacting with the Arux.app Switchboard APIs."
|
11
|
+
spec.homepage = "https://arux.software"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "httpi", "~> 2.4"
|
20
|
+
spec.add_runtime_dependency "json", ">= 0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", ">= 1.14"
|
23
|
+
spec.add_development_dependency "rake", ">= 12.0"
|
24
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Account
|
4
|
+
def self.server_uri
|
5
|
+
if AruxApp::API.standardmode?
|
6
|
+
"https://acc.arux.app"
|
7
|
+
elsif AruxApp::API.testmode?
|
8
|
+
"https://acc.arux.blue"
|
9
|
+
elsif AruxApp::API.devmode?
|
10
|
+
"https://acc.#{HOSTNAME}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :auth, :access_token, :api_version
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
self.auth = options[:auth]
|
18
|
+
self.access_token = options[:access_token]
|
19
|
+
self.api_version = options[:api_version] || 1.2
|
20
|
+
|
21
|
+
raise API::InitializerError.new(:auth_or_access_token, "can't be blank") if self.auth.nil? and self.access_token.nil?
|
22
|
+
raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if self.auth and !self.auth.is_a?(AruxApp::API::Auth)
|
23
|
+
raise API::InitializerError.new(:access_token, "must be of class type AruxApp::API::Auth::AccessToken") if self.access_token and !self.access_token.is_a?(AruxApp::API::Auth::AccessToken)
|
24
|
+
end
|
25
|
+
|
26
|
+
def list(params = {})
|
27
|
+
request = HTTPI::Request.new
|
28
|
+
request.url = "#{api_route}/users"
|
29
|
+
request.query = URI.encode_www_form(params)
|
30
|
+
request.headers = self.generate_headers
|
31
|
+
|
32
|
+
response = HTTPI.get(request)
|
33
|
+
|
34
|
+
if !response.error?
|
35
|
+
JSON.parse(response.body)
|
36
|
+
else
|
37
|
+
raise(API::Error.new(response.code, response.body))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(uuid, params = {})
|
42
|
+
uuid = URI.escape(uuid.to_s)
|
43
|
+
|
44
|
+
request = HTTPI::Request.new
|
45
|
+
request.url = "#{api_route}/users/#{uuid}"
|
46
|
+
request.query = URI.encode_www_form(params)
|
47
|
+
request.headers = self.generate_headers
|
48
|
+
|
49
|
+
response = HTTPI.get(request)
|
50
|
+
|
51
|
+
if !response.error?
|
52
|
+
JSON.parse(response.body)
|
53
|
+
else
|
54
|
+
raise(API::Error.new(response.code, response.body))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create(params)
|
59
|
+
request = HTTPI::Request.new
|
60
|
+
request.url = "#{api_route}/users/"
|
61
|
+
request.body = params.to_json
|
62
|
+
request.headers = self.generate_headers
|
63
|
+
|
64
|
+
response = HTTPI.post(request)
|
65
|
+
|
66
|
+
if response.code == 201
|
67
|
+
true
|
68
|
+
elsif !response.error?
|
69
|
+
JSON.parse(response.body)
|
70
|
+
else
|
71
|
+
raise(API::Error.new(response.code, response.body))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update(uuid, params)
|
76
|
+
uuid = URI.escape(uuid.to_s)
|
77
|
+
|
78
|
+
request = HTTPI::Request.new
|
79
|
+
request.url = "#{api_route}/users/#{uuid}"
|
80
|
+
request.body = params.to_json
|
81
|
+
request.headers = self.generate_headers
|
82
|
+
|
83
|
+
response = HTTPI.put(request)
|
84
|
+
|
85
|
+
if response.code == 204
|
86
|
+
true
|
87
|
+
elsif !response.error?
|
88
|
+
JSON.parse(response.body)
|
89
|
+
else
|
90
|
+
raise(API::Error.new(response.code, response.body))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def merge(uuid1, uuid2)
|
95
|
+
uuid1 = URI.escape(uuid1)
|
96
|
+
uuid2 = URI.escape(uuid2)
|
97
|
+
|
98
|
+
request = HTTPI::Request.new
|
99
|
+
request.url = "#{api_route}/users/merge/#{uuid1}/#{uuid2}"
|
100
|
+
request.headers = self.generate_headers
|
101
|
+
|
102
|
+
response = HTTPI.put(request)
|
103
|
+
|
104
|
+
if !response.error?
|
105
|
+
JSON.parse(response.body)
|
106
|
+
else
|
107
|
+
raise(API::Error.new(response.code, response.body))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete(uuid)
|
112
|
+
uuid = URI.escape(uuid.to_s)
|
113
|
+
|
114
|
+
request = HTTPI::Request.new
|
115
|
+
request.url = "#{api_route}/users/#{uuid}"
|
116
|
+
request.headers = self.generate_headers
|
117
|
+
|
118
|
+
response = HTTPI.delete(request)
|
119
|
+
|
120
|
+
if !response.error?
|
121
|
+
JSON.parse(response.body)
|
122
|
+
else
|
123
|
+
raise(API::Error.new(response.code, response.body))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def owner(params = {})
|
128
|
+
raise API::RequirementError.new(:access_token, "can't be blank") if self.access_token.nil?
|
129
|
+
|
130
|
+
request = HTTPI::Request.new
|
131
|
+
request.url = "#{api_route}/users/owner"
|
132
|
+
request.query = URI.encode_www_form(params)
|
133
|
+
request.headers = self.generate_headers
|
134
|
+
|
135
|
+
response = HTTPI.get(request)
|
136
|
+
|
137
|
+
if !response.error?
|
138
|
+
JSON.parse(response.body)
|
139
|
+
else
|
140
|
+
raise(API::Error.new(response.code, response.body))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def list_user_locks(user_uuid)
|
145
|
+
uuid = URI.escape(user_uuid.to_s)
|
146
|
+
|
147
|
+
request = HTTPI::Request.new
|
148
|
+
request.url = "#{api_route}/users/#{user_uuid}/locks"
|
149
|
+
request.headers = self.generate_headers
|
150
|
+
|
151
|
+
response = HTTPI.get(request)
|
152
|
+
|
153
|
+
if !response.error?
|
154
|
+
JSON.parse(response.body)
|
155
|
+
else
|
156
|
+
raise(API::Error.new(response.code, response.body))
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def add_user_lock(user_uuid, scope, reason = "")
|
161
|
+
uuid = URI.escape(user_uuid.to_s)
|
162
|
+
|
163
|
+
request = HTTPI::Request.new
|
164
|
+
request.url = "#{api_route}/users/#{uuid}/locks"
|
165
|
+
request.body = {
|
166
|
+
user_lock: {
|
167
|
+
scope: scope,
|
168
|
+
reason: reason
|
169
|
+
}
|
170
|
+
}.to_json
|
171
|
+
request.headers = self.generate_headers
|
172
|
+
|
173
|
+
response = HTTPI.post(request)
|
174
|
+
|
175
|
+
if response.code == 201
|
176
|
+
true
|
177
|
+
elsif !response.error?
|
178
|
+
JSON.parse(response.body)
|
179
|
+
else
|
180
|
+
raise(API::Error.new(response.code, response.body))
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def delete_user_lock(user_uuid, lock_id)
|
185
|
+
uuid = URI.escape(user_uuid.to_s)
|
186
|
+
|
187
|
+
request = HTTPI::Request.new
|
188
|
+
request.url = "#{api_route}/users/#{uuid}/locks/#{lock_id}"
|
189
|
+
request.headers = self.generate_headers
|
190
|
+
|
191
|
+
response = HTTPI.delete(request)
|
192
|
+
|
193
|
+
if !response.error?
|
194
|
+
JSON.parse(response.body)
|
195
|
+
else
|
196
|
+
raise(API::Error.new(response.code, response.body))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# TODO:: create mapping for relationships api endpoints
|
201
|
+
def list_relationships
|
202
|
+
end
|
203
|
+
|
204
|
+
def add_relationship
|
205
|
+
end
|
206
|
+
|
207
|
+
def update_relationship
|
208
|
+
end
|
209
|
+
|
210
|
+
def delete_relationship
|
211
|
+
end
|
212
|
+
|
213
|
+
protected
|
214
|
+
|
215
|
+
def api_route
|
216
|
+
"#{self.class.server_uri}/api/v#{api_version}"
|
217
|
+
end
|
218
|
+
|
219
|
+
def generate_headers
|
220
|
+
if self.access_token
|
221
|
+
{'User-Agent' => USER_AGENT, 'Authorization' => self.access_token.token, 'Content-Type' => "application/json"}
|
222
|
+
else
|
223
|
+
{'User-Agent' => USER_AGENT, 'Client-Secret' => self.auth.client_secret, 'Client-Id' => self.auth.client_id, 'Content-Type' => "application/json"}
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Auth
|
4
|
+
class InvalidGrantError < API::Error; end
|
5
|
+
class InvalidClientError < API::Error; end
|
6
|
+
|
7
|
+
class AccessToken
|
8
|
+
attr_accessor :token, :auth
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
self.token = options[:token]
|
12
|
+
self.auth = options[:auth]
|
13
|
+
|
14
|
+
raise API::InitializerError.new(:token, "can't be blank") if self.token.to_s.empty?
|
15
|
+
raise API::InitializerError.new(:auth, "can't be blank") if self.auth.nil?
|
16
|
+
raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if !self.auth.is_a?(AruxApp::API::Auth)
|
17
|
+
end
|
18
|
+
|
19
|
+
def user_data(params = {})
|
20
|
+
if @user_data.nil? and !@token.nil?
|
21
|
+
acc = AruxApp::API::Account.new(:access_token => self)
|
22
|
+
@user_data = acc.owner(params)["user"]
|
23
|
+
end
|
24
|
+
@user_data
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.server_uri
|
29
|
+
if AruxApp::API.standardmode?
|
30
|
+
"https://sso.arux.app"
|
31
|
+
elsif AruxApp::API.testmode?
|
32
|
+
"https://sso.arux.blue"
|
33
|
+
elsif AruxApp::API.devmode?
|
34
|
+
"https://sso.#{HOSTNAME}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_accessor :client_id, :client_secret, :redirect_uri, :js_callback, :district_subdomain, :current_user_uuid, :login_mechanism, :element
|
39
|
+
|
40
|
+
def initialize(options = {})
|
41
|
+
self.client_id = options[:client_id]
|
42
|
+
self.client_secret = options[:client_secret]
|
43
|
+
self.redirect_uri = options[:redirect_uri]
|
44
|
+
self.js_callback = options[:js_callback]
|
45
|
+
self.login_mechanism = options[:login_mechanism] || 'redirect'
|
46
|
+
self.element = options[:element]
|
47
|
+
self.district_subdomain = options[:district_subdomain]
|
48
|
+
self.current_user_uuid = options[:current_user_uuid]
|
49
|
+
|
50
|
+
raise API::InitializerError.new(:client_id, "can't be blank") if self.client_id.to_s.empty?
|
51
|
+
raise API::InitializerError.new(:client_secret, "can't be blank") if self.client_secret.to_s.empty?
|
52
|
+
raise API::InitializerError.new(:redirect_uri, "can't be blank") if self.redirect_uri.to_s.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorization_url
|
56
|
+
%(#{self.class.server_uri}/authorize?client_id=#{self.client_id}&redirect_uri=#{self.redirect_uri}&district=#{self.district_subdomain})
|
57
|
+
end
|
58
|
+
|
59
|
+
def registration_url
|
60
|
+
%(#{self.class.server_uri}/register?client_id=#{self.client_id}&redirect_uri=#{self.redirect_uri}&district=#{self.district_subdomain})
|
61
|
+
end
|
62
|
+
|
63
|
+
def access_token(code)
|
64
|
+
data = {
|
65
|
+
:code => code,
|
66
|
+
:grant_type => "authorization_code",
|
67
|
+
:redirect_uri => self.redirect_uri,
|
68
|
+
:client_secret => self.client_secret,
|
69
|
+
:client_id => self.client_id
|
70
|
+
}
|
71
|
+
|
72
|
+
request = HTTPI::Request.new
|
73
|
+
request.url = "#{self.class.server_uri}/access_token"
|
74
|
+
request.body = data
|
75
|
+
request.headers = {'User-Agent' => USER_AGENT}
|
76
|
+
|
77
|
+
response = HTTPI.post(request)
|
78
|
+
|
79
|
+
if !response.error?
|
80
|
+
return AccessToken.new(:token => JSON.parse(response.body)['access_token'], :auth => self)
|
81
|
+
else
|
82
|
+
begin
|
83
|
+
resp_data = JSON.parse(response.body)
|
84
|
+
rescue
|
85
|
+
end
|
86
|
+
if resp_data and resp_data["error"] == "invalid_grant"
|
87
|
+
raise(API::Auth::InvalidGrantError.new(response.code, response.body))
|
88
|
+
elsif resp_data and resp_data["error"] == "invalid_client"
|
89
|
+
raise(API::Auth::InvalidClientError.new(response.code, response.body))
|
90
|
+
else
|
91
|
+
raise(API::Error.new(response.code, response.body))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def javascript
|
97
|
+
options = {
|
98
|
+
district: self.district_subdomain,
|
99
|
+
element: self.element,
|
100
|
+
login: {
|
101
|
+
current_uuid: self.current_user_uuid,
|
102
|
+
client_id: self.client_id,
|
103
|
+
redirect_uri: self.redirect_uri,
|
104
|
+
login_mechanism: self.login_mechanism,
|
105
|
+
callback: self.js_callback
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return %(new SwitchBoardIOLogin(#{options.to_json});)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class BankInfo
|
4
|
+
def self.server_uri
|
5
|
+
"https://banks.api.arux.app"
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(routing_number)
|
9
|
+
routing_number = URI.escape(routing_number.to_s)
|
10
|
+
|
11
|
+
request = HTTPI::Request.new
|
12
|
+
request.url = "#{self.class.server_uri}/#{routing_number}"
|
13
|
+
request.headers = {'User-Agent' => USER_AGENT}
|
14
|
+
|
15
|
+
response = HTTPI.get(request)
|
16
|
+
|
17
|
+
if !response.error?
|
18
|
+
JSON.parse(response.body)
|
19
|
+
else
|
20
|
+
raise(API::Error.new(response.code, response.body))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Cart
|
4
|
+
def self.server_uri
|
5
|
+
if AruxApp::API.standardmode?
|
6
|
+
"https://cart.arux.app"
|
7
|
+
elsif AruxApp::API.testmode?
|
8
|
+
"https://cart.arux.blue"
|
9
|
+
elsif AruxApp::API.devmode?
|
10
|
+
"https://cart.#{HOSTNAME}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :auth, :access_token
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
self.access_token = options[:access_token]
|
18
|
+
self.auth = self.access_token.auth
|
19
|
+
|
20
|
+
raise API::InitializerError.new(:access_token, "can't be blank") if self.access_token.nil?
|
21
|
+
raise API::InitializerError.new(:access_token, "must be of class type AruxApp::API::Auth::AccessToken") if !self.access_token.is_a?(AruxApp::API::Auth::AccessToken)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(uuid = nil)
|
25
|
+
if uuid
|
26
|
+
path = %(/api/#{URI.escape(uuid)})
|
27
|
+
else
|
28
|
+
path = %(/api/#{self.generate_cart_path})
|
29
|
+
end
|
30
|
+
|
31
|
+
request = HTTPI::Request.new
|
32
|
+
request.url = "#{self.class.server_uri}#{path}"
|
33
|
+
request.headers = self.generate_headers
|
34
|
+
|
35
|
+
response = HTTPI.get(request)
|
36
|
+
|
37
|
+
if !response.error?
|
38
|
+
JSON.parse(response.body)
|
39
|
+
else
|
40
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_status
|
45
|
+
path = %(/api/#{self.generate_cart_path}/status)
|
46
|
+
|
47
|
+
request = HTTPI::Request.new
|
48
|
+
request.url = "#{self.class.server_uri}#{path}"
|
49
|
+
request.headers = self.generate_headers
|
50
|
+
|
51
|
+
response = HTTPI.get(request)
|
52
|
+
|
53
|
+
if !response.error?
|
54
|
+
JSON.parse(response.body)
|
55
|
+
else
|
56
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_items
|
61
|
+
path = %(/api/#{self.generate_cart_path}/items)
|
62
|
+
|
63
|
+
request = HTTPI::Request.new
|
64
|
+
request.url = "#{self.class.server_uri}#{path}"
|
65
|
+
request.headers = self.generate_headers
|
66
|
+
|
67
|
+
response = HTTPI.get(request)
|
68
|
+
|
69
|
+
if !response.error?
|
70
|
+
JSON.parse(response.body)
|
71
|
+
else
|
72
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_item(item_identifier)
|
77
|
+
path = %(/api/#{self.generate_cart_path}/items/#{item_identifier})
|
78
|
+
|
79
|
+
request = HTTPI::Request.new
|
80
|
+
request.url = "#{self.class.server_uri}#{path}"
|
81
|
+
request.headers = self.generate_headers
|
82
|
+
|
83
|
+
response = HTTPI.get(request)
|
84
|
+
|
85
|
+
if !response.error?
|
86
|
+
JSON.parse(response.body)
|
87
|
+
else
|
88
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_item(params)
|
93
|
+
path = %(/api/#{self.generate_cart_path}/items)
|
94
|
+
|
95
|
+
request = HTTPI::Request.new
|
96
|
+
request.url = "#{self.class.server_uri}#{path}"
|
97
|
+
if params.keys.first.to_s != 'item'
|
98
|
+
params = {:item => params}
|
99
|
+
end
|
100
|
+
request.body = params.to_json
|
101
|
+
request.headers = self.generate_headers
|
102
|
+
|
103
|
+
response = HTTPI.post(request)
|
104
|
+
|
105
|
+
if !response.error?
|
106
|
+
JSON.parse(response.body)
|
107
|
+
else
|
108
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def update_item(item_identifier, params)
|
113
|
+
path = %(/api/#{self.generate_cart_path}/items/#{URI.escape(item_identifier)})
|
114
|
+
|
115
|
+
request = HTTPI::Request.new
|
116
|
+
request.url = "#{self.class.server_uri}#{path}"
|
117
|
+
if params.keys.first.to_s != 'item'
|
118
|
+
params = {:item => params}
|
119
|
+
end
|
120
|
+
request.body = params.to_json
|
121
|
+
request.headers = self.generate_headers
|
122
|
+
|
123
|
+
response = HTTPI.put(request)
|
124
|
+
|
125
|
+
if !response.error?
|
126
|
+
JSON.parse(response.body)
|
127
|
+
else
|
128
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def delete_item(item_identifier)
|
133
|
+
path = %(/api/#{self.generate_cart_path}/items/#{URI.escape(item_identifier)})
|
134
|
+
|
135
|
+
request = HTTPI::Request.new
|
136
|
+
request.url = "#{self.class.server_uri}#{path}"
|
137
|
+
request.headers = self.generate_headers
|
138
|
+
|
139
|
+
response = HTTPI.delete(request)
|
140
|
+
|
141
|
+
if !response.error?
|
142
|
+
JSON.parse(response.body)
|
143
|
+
else
|
144
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def destroy(uuid)
|
149
|
+
path = "/api/#{self.generate_cart_path}/carts/#{uuid}"
|
150
|
+
request = HTTPI::Request.new
|
151
|
+
request.url = "#{self.class.server_uri}#{path}"
|
152
|
+
request.headers = self.generate_headers
|
153
|
+
|
154
|
+
response = HTTPI.delete(request)
|
155
|
+
|
156
|
+
if !response.error?
|
157
|
+
JSON.parse(response.body)
|
158
|
+
else
|
159
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def create(params)
|
164
|
+
path = "/api/#{self.generate_cart_path}/carts"
|
165
|
+
request = HTTPI::Request.new
|
166
|
+
request.url = "#{self.class.server_uri}#{path}"
|
167
|
+
request.headers = self.generate_headers
|
168
|
+
request.body = params.to_json
|
169
|
+
|
170
|
+
response = HTTPI.post(request)
|
171
|
+
|
172
|
+
if !response.error?
|
173
|
+
JSON.parse(response.body)
|
174
|
+
else
|
175
|
+
raise(API::Error.new(response.code, JSON.parse(response.body)["message"]))
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
protected
|
180
|
+
|
181
|
+
def generate_cart_path
|
182
|
+
%(#{URI.escape(self.auth.district_subdomain)}/#{URI.escape(self.access_token.token)})
|
183
|
+
end
|
184
|
+
|
185
|
+
def generate_headers
|
186
|
+
{'User-Agent' => USER_AGENT, 'Client-Id' => self.auth.client_id, 'Content-Type' => 'application/json'}
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Config
|
4
|
+
def self.server_uri
|
5
|
+
if AruxApp::API.standardmode?
|
6
|
+
"https://config.arux.app"
|
7
|
+
elsif AruxApp::API.testmode?
|
8
|
+
"https://config.arux.blue"
|
9
|
+
elsif AruxApp::API.devmode?
|
10
|
+
"http://config.#{HOSTNAME}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :auth
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
self.auth = options[:auth]
|
18
|
+
|
19
|
+
raise API::InitializerError.new(:auth, "can't be blank") if self.auth.nil?
|
20
|
+
raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if !self.auth.is_a?(AruxApp::API::Auth)
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(subdomain_or_sn)
|
24
|
+
subdomain_or_sn = URI.escape(subdomain_or_sn.to_s)
|
25
|
+
|
26
|
+
request = HTTPI::Request.new
|
27
|
+
request.url = "#{self.class.server_uri}/v1/customers/#{subdomain_or_sn}"
|
28
|
+
request.headers = self.generate_headers
|
29
|
+
|
30
|
+
response = HTTPI.get(request)
|
31
|
+
|
32
|
+
if !response.error?
|
33
|
+
JSON.parse(response.body)
|
34
|
+
else
|
35
|
+
raise(API::Error.new(response.code, response.body))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_by(key, value)
|
40
|
+
key = URI.escape(key.to_s)
|
41
|
+
value = URI.escape(value.to_s)
|
42
|
+
|
43
|
+
request = HTTPI::Request.new
|
44
|
+
request.url = "#{self.class.server_uri}/v1/customers/by/#{key}/#{value}"
|
45
|
+
request.headers = self.generate_headers
|
46
|
+
|
47
|
+
response = HTTPI.get(request)
|
48
|
+
|
49
|
+
if !response.error?
|
50
|
+
JSON.parse(response.body)
|
51
|
+
else
|
52
|
+
raise(API::Error.new(response.code, response.body))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def generate_headers
|
59
|
+
{'User-Agent' => USER_AGENT, 'Client-Secret' => self.auth.client_secret, 'Client-Id' => self.auth.client_id}
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Nav
|
4
|
+
|
5
|
+
attr_accessor :auth
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
self.auth = options[:auth]
|
9
|
+
|
10
|
+
raise API::InitializerError.new(:auth, "can't be blank") if self.auth.nil?
|
11
|
+
raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if !self.auth.is_a?(AruxApp::API::Auth)
|
12
|
+
end
|
13
|
+
|
14
|
+
def javascript
|
15
|
+
options = {
|
16
|
+
district: self.auth.district_subdomain,
|
17
|
+
login: {
|
18
|
+
current_uuid: self.auth.current_user_uuid,
|
19
|
+
client_id: self.auth.client_id,
|
20
|
+
redirect_uri: self.auth.redirect_uri,
|
21
|
+
callback: self.auth.js_callback
|
22
|
+
}
|
23
|
+
}
|
24
|
+
return %(new SwitchBoardIONav(#{options.to_json});)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class Student < Account
|
4
|
+
|
5
|
+
def lookup_district_student_id(params)
|
6
|
+
# accepted lookup attributes
|
7
|
+
# firstname & lastname & birthdate
|
8
|
+
# state_student_id
|
9
|
+
request = HTTPI::Request.new
|
10
|
+
request.url = "#{self.class.server_uri}/api/v1/students/lookup/district_student_id/#{URI.escape(self.auth.district_subdomain)}"
|
11
|
+
request.query = params
|
12
|
+
request.headers = self.generate_headers
|
13
|
+
|
14
|
+
response = HTTPI.get(request)
|
15
|
+
|
16
|
+
if !response.error?
|
17
|
+
JSON.parse(response.body)
|
18
|
+
else
|
19
|
+
raise(API::Error.new(response.code, response.body))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def lookup_state_student_id(params)
|
24
|
+
# accepted lookup attributes
|
25
|
+
# firstname & lastname & birthdate
|
26
|
+
# district_student_id
|
27
|
+
request = HTTPI::Request.new
|
28
|
+
request.url = "#{self.class.server_uri}/api/v1/students/lookup/state_student_id/#{URI.escape(self.auth.district_subdomain)}"
|
29
|
+
request.query = params
|
30
|
+
request.headers = self.generate_headers
|
31
|
+
|
32
|
+
response = HTTPI.get(request)
|
33
|
+
|
34
|
+
if !response.error?
|
35
|
+
JSON.parse(response.body)
|
36
|
+
else
|
37
|
+
raise(API::Error.new(response.code, response.body))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/arux_app/api.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module AruxApp
|
2
|
+
module API
|
3
|
+
class << self
|
4
|
+
@@mode = :standard
|
5
|
+
[:test, :dev, :standard].each do |m|
|
6
|
+
define_method("#{m}mode?") do
|
7
|
+
@@mode == m
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method("#{m}mode") do
|
11
|
+
@@mode == m
|
12
|
+
end
|
13
|
+
|
14
|
+
define_method("#{m}mode=") do |b|
|
15
|
+
@@mode = b ? m : :standard
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Error < StandardError
|
21
|
+
attr_accessor :http_status_code
|
22
|
+
def initialize(code, message)
|
23
|
+
self.http_status_code = code.to_i
|
24
|
+
begin
|
25
|
+
self.json = JSON.parse(message)
|
26
|
+
rescue
|
27
|
+
end
|
28
|
+
|
29
|
+
super "(#{code}) #{message}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class InitializerError < StandardError
|
34
|
+
def initialize(method, message)
|
35
|
+
super "#{method} #{message}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class RequirementError < StandardError
|
40
|
+
def initialize(method, message)
|
41
|
+
super "#{method} #{message}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/arux_app.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "httpi"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
require "arux_app/api"
|
6
|
+
|
7
|
+
require "arux_app/api/bank_info"
|
8
|
+
require "arux_app/api/config"
|
9
|
+
require "arux_app/api/auth"
|
10
|
+
require "arux_app/api/nav"
|
11
|
+
require "arux_app/api/account"
|
12
|
+
require "arux_app/api/student"
|
13
|
+
require "arux_app/api/cart"
|
14
|
+
|
15
|
+
module AruxApp
|
16
|
+
VERSION = "1.0.0"
|
17
|
+
USER_AGENT = "Arux.app GEM #{VERSION}"
|
18
|
+
end
|
19
|
+
|
20
|
+
if ENV['ARUX_APP_GEM_TEST_MODE'].to_s == "true"
|
21
|
+
AruxApp::API.testmode = true
|
22
|
+
end
|
23
|
+
|
24
|
+
if ENV['ARUX_APP_GEM_DEV_MODE'].to_s == "true"
|
25
|
+
AruxApp::API.devmode = true
|
26
|
+
end
|
27
|
+
|
28
|
+
if ENV.has_key?("DEV_HOST")
|
29
|
+
HOSTNAME = ENV.fetch("DEV_HOST")
|
30
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
31
|
+
HOSTNAME = "#{`scutil --get LocalHostName`.downcase.strip}.local"
|
32
|
+
else
|
33
|
+
HOSTNAME = `hostname`.downcase.strip
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arux_app
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arux Software
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
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.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- sheuer@aruxsoftware.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- arux_app.gemspec
|
84
|
+
- lib/arux_app.rb
|
85
|
+
- lib/arux_app/api.rb
|
86
|
+
- lib/arux_app/api/account.rb
|
87
|
+
- lib/arux_app/api/auth.rb
|
88
|
+
- lib/arux_app/api/bank_info.rb
|
89
|
+
- lib/arux_app/api/cart.rb
|
90
|
+
- lib/arux_app/api/config.rb
|
91
|
+
- lib/arux_app/api/nav.rb
|
92
|
+
- lib/arux_app/api/student.rb
|
93
|
+
homepage: https://arux.software
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.0.9
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Ruby gem for interacting with the Arux.app Switchboard APIs.
|
116
|
+
test_files: []
|