arux_app 1.0.0 → 3.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3619d786915abb5811eca23385011342f49b7c5e7cf7be99c41a50d77972f53e
4
- data.tar.gz: 145c55897cdd5fd3fcc9de07dcb837dd092c99f28c936908b0630e02df007d0c
3
+ metadata.gz: 5bf41c439a9083aa3207a8c937735b80a714a4b9d5173f39599fd43f9030ccaf
4
+ data.tar.gz: 57783b60dc6033a82aca59bd85ebfe0a90b1c9b2a87db090ff4439843b11ebf6
5
5
  SHA512:
6
- metadata.gz: fb3f7d2756410f4b1a94d71124b0179fd93bd5df33b545e4d4cdc2d97bef1dbf2687d9f82cb8ac21e02ad1ac8db0547a589b38870e630d2af4aebdddaa1feda3
7
- data.tar.gz: e66d5f0b8cae74e1397cc657c01d4b19d6ebd65586fc28a7144ad10cac85fbfb6ca378a4a0f93a414904c5394c7306c8a228a0e5c0f4b5a8cffe667b29f93a8c
6
+ metadata.gz: a2b78de0e3f129364fe0efc2231eb52a632e7481fd4f17ecc13d3bd07528df6dcafdaa59a59acc756f0537ef58146b0b98c69be8b9f84ef81af40f48d557b2d9
7
+ data.tar.gz: 32bcb01ccb1dfca6e395021ecfa6f8f1ac050c8d8b21a37c06a634d1ba35bda2fc0a6ab6d43160d32798f208a51bacaeb3f89067632ca87bd519f38ab9be05ef
data/arux_app.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "arux_app"
7
- spec.version = "1.0.0"
7
+ spec.version = "3.0.0"
8
8
  spec.authors = ["Arux Software"]
9
9
  spec.email = ["sheuer@aruxsoftware.com"]
10
10
  spec.summary = "Ruby gem for interacting with the Arux.app Switchboard APIs."
@@ -1,28 +1,34 @@
1
1
  module AruxApp
2
2
  module API
3
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
4
  attr_accessor :auth, :access_token, :api_version
15
5
 
16
6
  def initialize(options = {})
17
7
  self.auth = options[:auth]
18
8
  self.access_token = options[:access_token]
19
- self.api_version = options[:api_version] || 1.2
9
+ self.api_version = options[:api_version] || 1.3
20
10
 
21
11
  raise API::InitializerError.new(:auth_or_access_token, "can't be blank") if self.auth.nil? and self.access_token.nil?
22
12
  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
13
  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
14
  end
25
15
 
16
+ def self.public_uri
17
+ AruxApp::API.uri(subdomain: "account")
18
+ end
19
+
20
+ def public_uri
21
+ self.class.public_uri
22
+ end
23
+
24
+ def self.api_uri
25
+ AruxApp::API.uri(subdomain: "account.api")
26
+ end
27
+
28
+ def api_uri
29
+ self.class.api_uri
30
+ end
31
+
26
32
  def list(params = {})
27
33
  request = HTTPI::Request.new
28
34
  request.url = "#{api_route}/users"
@@ -39,7 +45,7 @@ module AruxApp
39
45
  end
40
46
 
41
47
  def get(uuid, params = {})
42
- uuid = URI.escape(uuid.to_s)
48
+ uuid = AruxApp::API.uri_escape(uuid.to_s)
43
49
 
44
50
  request = HTTPI::Request.new
45
51
  request.url = "#{api_route}/users/#{uuid}"
@@ -73,7 +79,7 @@ module AruxApp
73
79
  end
74
80
 
75
81
  def update(uuid, params)
76
- uuid = URI.escape(uuid.to_s)
82
+ uuid = AruxApp::API.uri_escape(uuid.to_s)
77
83
 
78
84
  request = HTTPI::Request.new
79
85
  request.url = "#{api_route}/users/#{uuid}"
@@ -92,8 +98,8 @@ module AruxApp
92
98
  end
93
99
 
94
100
  def merge(uuid1, uuid2)
95
- uuid1 = URI.escape(uuid1)
96
- uuid2 = URI.escape(uuid2)
101
+ uuid1 = AruxApp::API.uri_escape(uuid1)
102
+ uuid2 = AruxApp::API.uri_escape(uuid2)
97
103
 
98
104
  request = HTTPI::Request.new
99
105
  request.url = "#{api_route}/users/merge/#{uuid1}/#{uuid2}"
@@ -109,7 +115,7 @@ module AruxApp
109
115
  end
110
116
 
111
117
  def delete(uuid)
112
- uuid = URI.escape(uuid.to_s)
118
+ uuid = AruxApp::API.uri_escape(uuid.to_s)
113
119
 
114
120
  request = HTTPI::Request.new
115
121
  request.url = "#{api_route}/users/#{uuid}"
@@ -141,62 +147,6 @@ module AruxApp
141
147
  end
142
148
  end
143
149
 
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
150
  # TODO:: create mapping for relationships api endpoints
201
151
  def list_relationships
202
152
  end
@@ -213,7 +163,7 @@ module AruxApp
213
163
  protected
214
164
 
215
165
  def api_route
216
- "#{self.class.server_uri}/api/v#{api_version}"
166
+ "#{api_uri}/api/v#{api_version}"
217
167
  end
218
168
 
219
169
  def generate_headers
@@ -5,11 +5,12 @@ module AruxApp
5
5
  class InvalidClientError < API::Error; end
6
6
 
7
7
  class AccessToken
8
- attr_accessor :token, :auth
8
+ attr_accessor :token, :auth, :scope
9
9
 
10
10
  def initialize(options = {})
11
11
  self.token = options[:token]
12
12
  self.auth = options[:auth]
13
+ self.scope = options[:scope]
13
14
 
14
15
  raise API::InitializerError.new(:token, "can't be blank") if self.token.to_s.empty?
15
16
  raise API::InitializerError.new(:auth, "can't be blank") if self.auth.nil?
@@ -25,16 +26,6 @@ module AruxApp
25
26
  end
26
27
  end
27
28
 
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
29
  attr_accessor :client_id, :client_secret, :redirect_uri, :js_callback, :district_subdomain, :current_user_uuid, :login_mechanism, :element
39
30
 
40
31
  def initialize(options = {})
@@ -52,12 +43,62 @@ module AruxApp
52
43
  raise API::InitializerError.new(:redirect_uri, "can't be blank") if self.redirect_uri.to_s.empty?
53
44
  end
54
45
 
55
- def authorization_url
56
- %(#{self.class.server_uri}/authorize?client_id=#{self.client_id}&redirect_uri=#{self.redirect_uri}&district=#{self.district_subdomain})
46
+ def self.public_uri
47
+ AruxApp::API.uri(subdomain: "account")
48
+ end
49
+
50
+ def public_uri
51
+ self.class.public_uri
52
+ end
53
+
54
+ def self.api_uri
55
+ AruxApp::API.uri(subdomain: "account.api")
56
+ end
57
+
58
+ def api_uri
59
+ self.class.api_uri
60
+ end
61
+
62
+ def authorization_url(scope: "public")
63
+ base_uri = URI.parse("#{public_uri}/oauth/authorize")
64
+ params = {
65
+ scope: scope,
66
+ response_type: "code",
67
+ client_id: client_id,
68
+ redirect_uri: redirect_uri,
69
+ district: district_subdomain
70
+ }
71
+ base_uri.query = URI.encode_www_form(params)
72
+ base_uri.to_s
73
+ end
74
+
75
+ def basic_authentication(username, password, scope = "public")
76
+ params = {
77
+ scope: scope,
78
+ grant_type: "password",
79
+ client_id: client_id,
80
+ client_secret: client_secret
81
+ }
82
+
83
+ request = HTTPI::Request.new.tap do |req|
84
+ req.url = "#{public_uri}/oauth/token"
85
+ req.body = params
86
+ req.headers = { 'User-Agent' => USER_AGENT }
87
+ req.auth.basic(username, password)
88
+ end
89
+
90
+ response = HTTPI.post(request)
91
+ raise(API::Error.new(response.code, response.body)) if response.error?
92
+
93
+ AccessToken.new(
94
+ token: JSON.parse(response.body)['access_token'],
95
+ scope: JSON.parse(response.body)['scope'],
96
+ auth: self
97
+ )
57
98
  end
58
99
 
59
100
  def registration_url
60
- %(#{self.class.server_uri}/register?client_id=#{self.client_id}&redirect_uri=#{self.redirect_uri}&district=#{self.district_subdomain})
101
+ %(#{public_uri}/users/registrations?client_id=#{self.client_id}&redirect_uri=#{self.redirect_uri}&district=#{self.district_subdomain})
61
102
  end
62
103
 
63
104
  def access_token(code)
@@ -70,14 +111,18 @@ module AruxApp
70
111
  }
71
112
 
72
113
  request = HTTPI::Request.new
73
- request.url = "#{self.class.server_uri}/access_token"
114
+ request.url = "#{api_uri}/oauth/token"
74
115
  request.body = data
75
116
  request.headers = {'User-Agent' => USER_AGENT}
76
117
 
77
118
  response = HTTPI.post(request)
78
119
 
79
120
  if !response.error?
80
- return AccessToken.new(:token => JSON.parse(response.body)['access_token'], :auth => self)
121
+ AccessToken.new(
122
+ token: JSON.parse(response.body)['access_token'],
123
+ scope: JSON.parse(response.body)['scope'],
124
+ auth: self
125
+ )
81
126
  else
82
127
  begin
83
128
  resp_data = JSON.parse(response.body)
@@ -93,6 +138,27 @@ module AruxApp
93
138
  end
94
139
  end
95
140
 
141
+ def client_credentials_token
142
+ data = {
143
+ scope: "public",
144
+ grant_type: "client_credentials",
145
+ client_id: client_id,
146
+ client_secret: client_secret
147
+ }
148
+
149
+ request = HTTPI::Request.new
150
+ request.url = "#{api_uri}/oauth/token"
151
+ request.body = data
152
+ request.headers = {'User-Agent' => USER_AGENT}
153
+
154
+ response = HTTPI.post(request)
155
+ if !response.error?
156
+ AccessToken.new(:token => JSON.parse(response.body)['access_token'], auth: self)
157
+ else
158
+ raise(API::Error.new(response.code, response.body))
159
+ end
160
+ end
161
+
96
162
  def javascript
97
163
  options = {
98
164
  district: self.district_subdomain,
@@ -1,19 +1,31 @@
1
1
  module AruxApp
2
2
  module API
3
3
  class BankInfo
4
- def self.server_uri
5
- "https://banks.api.arux.app"
4
+ def self.public_uri
5
+ AruxApp::API.uri(subdomain: "banks")
6
+ end
7
+
8
+ def public_uri
9
+ self.class.public_uri
10
+ end
11
+
12
+ def self.api_uri
13
+ AruxApp::API.uri(subdomain: "banks.api")
14
+ end
15
+
16
+ def api_uri
17
+ self.class.api_uri
6
18
  end
7
19
 
8
20
  def get(routing_number)
9
- routing_number = URI.escape(routing_number.to_s)
21
+ routing_number = AruxApp::API.uri_escape(routing_number.to_s)
10
22
 
11
23
  request = HTTPI::Request.new
12
- request.url = "#{self.class.server_uri}/#{routing_number}"
24
+ request.url = "#{api_uri}/#{routing_number}"
13
25
  request.headers = {'User-Agent' => USER_AGENT}
14
26
 
15
27
  response = HTTPI.get(request)
16
-
28
+
17
29
  if !response.error?
18
30
  JSON.parse(response.body)
19
31
  else
@@ -1,16 +1,6 @@
1
1
  module AruxApp
2
2
  module API
3
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
4
  attr_accessor :auth, :access_token
15
5
 
16
6
  def initialize(options = {})
@@ -21,15 +11,31 @@ module AruxApp
21
11
  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
12
  end
23
13
 
14
+ def self.public_uri
15
+ AruxApp::API.uri(subdomain: "cart")
16
+ end
17
+
18
+ def public_uri
19
+ self.class.public_uri
20
+ end
21
+
22
+ def self.api_uri
23
+ AruxApp::API.uri(subdomain: "cart.api")
24
+ end
25
+
26
+ def api_uri
27
+ self.class.api_uri
28
+ end
29
+
24
30
  def get(uuid = nil)
25
31
  if uuid
26
- path = %(/api/#{URI.escape(uuid)})
32
+ path = %(/api/#{AruxApp::API.uri_escape(uuid)})
27
33
  else
28
34
  path = %(/api/#{self.generate_cart_path})
29
35
  end
30
36
 
31
37
  request = HTTPI::Request.new
32
- request.url = "#{self.class.server_uri}#{path}"
38
+ request.url = "#{api_uri}#{path}"
33
39
  request.headers = self.generate_headers
34
40
 
35
41
  response = HTTPI.get(request)
@@ -45,7 +51,7 @@ module AruxApp
45
51
  path = %(/api/#{self.generate_cart_path}/status)
46
52
 
47
53
  request = HTTPI::Request.new
48
- request.url = "#{self.class.server_uri}#{path}"
54
+ request.url = "#{api_uri}#{path}"
49
55
  request.headers = self.generate_headers
50
56
 
51
57
  response = HTTPI.get(request)
@@ -61,7 +67,7 @@ module AruxApp
61
67
  path = %(/api/#{self.generate_cart_path}/items)
62
68
 
63
69
  request = HTTPI::Request.new
64
- request.url = "#{self.class.server_uri}#{path}"
70
+ request.url = "#{api_uri}#{path}"
65
71
  request.headers = self.generate_headers
66
72
 
67
73
  response = HTTPI.get(request)
@@ -77,7 +83,7 @@ module AruxApp
77
83
  path = %(/api/#{self.generate_cart_path}/items/#{item_identifier})
78
84
 
79
85
  request = HTTPI::Request.new
80
- request.url = "#{self.class.server_uri}#{path}"
86
+ request.url = "#{api_uri}#{path}"
81
87
  request.headers = self.generate_headers
82
88
 
83
89
  response = HTTPI.get(request)
@@ -93,7 +99,7 @@ module AruxApp
93
99
  path = %(/api/#{self.generate_cart_path}/items)
94
100
 
95
101
  request = HTTPI::Request.new
96
- request.url = "#{self.class.server_uri}#{path}"
102
+ request.url = "#{api_uri}#{path}"
97
103
  if params.keys.first.to_s != 'item'
98
104
  params = {:item => params}
99
105
  end
@@ -110,10 +116,10 @@ module AruxApp
110
116
  end
111
117
 
112
118
  def update_item(item_identifier, params)
113
- path = %(/api/#{self.generate_cart_path}/items/#{URI.escape(item_identifier)})
119
+ path = %(/api/#{self.generate_cart_path}/items/#{AruxApp::API.uri_escape(item_identifier)})
114
120
 
115
121
  request = HTTPI::Request.new
116
- request.url = "#{self.class.server_uri}#{path}"
122
+ request.url = "#{api_uri}#{path}"
117
123
  if params.keys.first.to_s != 'item'
118
124
  params = {:item => params}
119
125
  end
@@ -130,10 +136,10 @@ module AruxApp
130
136
  end
131
137
 
132
138
  def delete_item(item_identifier)
133
- path = %(/api/#{self.generate_cart_path}/items/#{URI.escape(item_identifier)})
139
+ path = %(/api/#{self.generate_cart_path}/items/#{AruxApp::API.uri_escape(item_identifier)})
134
140
 
135
141
  request = HTTPI::Request.new
136
- request.url = "#{self.class.server_uri}#{path}"
142
+ request.url = "#{api_uri}#{path}"
137
143
  request.headers = self.generate_headers
138
144
 
139
145
  response = HTTPI.delete(request)
@@ -148,7 +154,7 @@ module AruxApp
148
154
  def destroy(uuid)
149
155
  path = "/api/#{self.generate_cart_path}/carts/#{uuid}"
150
156
  request = HTTPI::Request.new
151
- request.url = "#{self.class.server_uri}#{path}"
157
+ request.url = "#{api_uri}#{path}"
152
158
  request.headers = self.generate_headers
153
159
 
154
160
  response = HTTPI.delete(request)
@@ -163,7 +169,7 @@ module AruxApp
163
169
  def create(params)
164
170
  path = "/api/#{self.generate_cart_path}/carts"
165
171
  request = HTTPI::Request.new
166
- request.url = "#{self.class.server_uri}#{path}"
172
+ request.url = "#{api_uri}#{path}"
167
173
  request.headers = self.generate_headers
168
174
  request.body = params.to_json
169
175
 
@@ -179,7 +185,7 @@ module AruxApp
179
185
  protected
180
186
 
181
187
  def generate_cart_path
182
- %(#{URI.escape(self.auth.district_subdomain)}/#{URI.escape(self.access_token.token)})
188
+ %(#{AruxApp::API.uri_escape(self.auth.district_subdomain)}/#{AruxApp::API.uri_escape(self.access_token.token)})
183
189
  end
184
190
 
185
191
  def generate_headers
@@ -0,0 +1,38 @@
1
+ module AruxApp
2
+ module API
3
+ class Checkout
4
+ API_VERSION = 1
5
+
6
+ def self.public_uri
7
+ AruxApp::API.uri(subdomain: "pay")
8
+ end
9
+
10
+ def public_uri
11
+ self.class.public_uri
12
+ end
13
+
14
+ def self.api_uri
15
+ AruxApp::API.uri(subdomain: "pay.api")
16
+ end
17
+
18
+ def api_uri
19
+ self.class.api_uri
20
+ end
21
+
22
+ def self.api_route
23
+ "#{api_uri}/api/v#{API_VERSION}/"
24
+ end
25
+
26
+ def self.iframe_url
27
+ case AruxApp::API.mode
28
+ when :production
29
+ "https://htp.tokenex.com/Iframe/Iframe-v3.min.js"
30
+ when :staging, :development, :test
31
+ "https://test-htp.tokenex.com/Iframe/Iframe-v3.min.js"
32
+ else
33
+ raise "AruxApp::API environment not supported"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,16 +1,6 @@
1
1
  module AruxApp
2
2
  module API
3
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
4
  attr_accessor :auth
15
5
 
16
6
  def initialize(options = {})
@@ -20,11 +10,27 @@ module AruxApp
20
10
  raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if !self.auth.is_a?(AruxApp::API::Auth)
21
11
  end
22
12
 
13
+ def self.public_uri
14
+ AruxApp::API.uri(subdomain: "config")
15
+ end
16
+
17
+ def public_uri
18
+ self.class.public_uri
19
+ end
20
+
21
+ def self.api_uri
22
+ AruxApp::API.uri(subdomain: "config.api")
23
+ end
24
+
25
+ def api_uri
26
+ self.class.api_uri
27
+ end
28
+
23
29
  def get(subdomain_or_sn)
24
- subdomain_or_sn = URI.escape(subdomain_or_sn.to_s)
30
+ subdomain_or_sn = AruxApp::API.uri_escape(subdomain_or_sn.to_s)
25
31
 
26
32
  request = HTTPI::Request.new
27
- request.url = "#{self.class.server_uri}/v1/customers/#{subdomain_or_sn}"
33
+ request.url = "#{api_uri}/v1/customers/#{subdomain_or_sn}"
28
34
  request.headers = self.generate_headers
29
35
 
30
36
  response = HTTPI.get(request)
@@ -37,11 +43,11 @@ module AruxApp
37
43
  end
38
44
 
39
45
  def get_by(key, value)
40
- key = URI.escape(key.to_s)
41
- value = URI.escape(value.to_s)
46
+ key = AruxApp::API.uri_escape(key.to_s)
47
+ value = AruxApp::API.uri_escape(value.to_s)
42
48
 
43
49
  request = HTTPI::Request.new
44
- request.url = "#{self.class.server_uri}/v1/customers/by/#{key}/#{value}"
50
+ request.url = "#{api_uri}/v1/customers/by/#{key}/#{value}"
45
51
  request.headers = self.generate_headers
46
52
 
47
53
  response = HTTPI.get(request)
data/lib/arux_app/api.rb CHANGED
@@ -1,22 +1,45 @@
1
1
  module AruxApp
2
2
  module API
3
+ DOMAINS = {
4
+ production: "arux.app",
5
+ staging: "arux.blue",
6
+ development: HOSTNAME,
7
+ test: "arux.test"
8
+ }
9
+
3
10
  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
11
+ def mode
12
+ raise "Environment is not set, i.e. ARUX_APP_GEM_MODE = :development" unless const_defined?(:ARUX_APP_GEM_MODE)
13
+ ARUX_APP_GEM_MODE
14
+ end
15
+
16
+ def uri(subdomain:)
17
+ URI::HTTPS.build(
18
+ host: [subdomain, domain].join('.'),
19
+ )
20
+ end
21
+
22
+ def domain
23
+ raise "#{mode} is not a supported environment" unless DOMAINS.has_key?(mode)
24
+ DOMAINS[mode]
25
+ end
26
+
27
+ def uri_escape(str)
28
+ # URI.escape was deprecated and removed in ruby
29
+ # https://bugs.ruby-lang.org/issues/17309
30
+ # The alternatives suggested were using URI::DEFAULT_PARSER
31
+ # and CGI. This will use URI::DEFAULT_PARSER if it is defined and CGI
32
+ # if not.
33
+ if URI.respond_to?(:escape)
34
+ URI.escape(str)
35
+ elsif defined? URI::DEFAULT_PARSER
36
+ URI::DEFAULT_PARSER.escape(str)
37
+ else
38
+ CGI.escape(str)
16
39
  end
17
40
  end
18
41
  end
19
-
42
+
20
43
  class Error < StandardError
21
44
  attr_accessor :http_status_code
22
45
  def initialize(code, message)
@@ -25,22 +48,22 @@ module AruxApp
25
48
  self.json = JSON.parse(message)
26
49
  rescue
27
50
  end
28
-
51
+
29
52
  super "(#{code}) #{message}"
30
53
  end
31
54
  end
32
-
55
+
33
56
  class InitializerError < StandardError
34
- def initialize(method, message)
57
+ def initialize(method, message)
35
58
  super "#{method} #{message}"
36
59
  end
37
60
  end
38
61
 
39
62
  class RequirementError < StandardError
40
- def initialize(method, message)
63
+ def initialize(method, message)
41
64
  super "#{method} #{message}"
42
65
  end
43
66
  end
44
67
 
45
68
  end
46
- end
69
+ end
data/lib/arux_app.rb CHANGED
@@ -1,34 +1,23 @@
1
+ HOSTNAME = if ENV.has_key?("DEV_HOST")
2
+ ENV.fetch("DEV_HOST")
3
+ elsif RUBY_PLATFORM =~ /darwin/
4
+ "#{`scutil --get LocalHostName`.downcase.strip}.local"
5
+ else
6
+ `hostname`.downcase.strip
7
+ end
8
+
1
9
  require "rubygems"
2
10
  require "httpi"
3
11
  require "json"
4
-
5
12
  require "arux_app/api"
6
-
13
+ require "arux_app/api/checkout"
7
14
  require "arux_app/api/bank_info"
8
15
  require "arux_app/api/config"
9
16
  require "arux_app/api/auth"
10
- require "arux_app/api/nav"
11
17
  require "arux_app/api/account"
12
- require "arux_app/api/student"
13
18
  require "arux_app/api/cart"
14
19
 
15
20
  module AruxApp
16
- VERSION = "1.0.0"
21
+ VERSION = "3.0.0"
17
22
  USER_AGENT = "Arux.app GEM #{VERSION}"
18
23
  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 CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arux_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arux Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-14 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpi
@@ -87,9 +87,8 @@ files:
87
87
  - lib/arux_app/api/auth.rb
88
88
  - lib/arux_app/api/bank_info.rb
89
89
  - lib/arux_app/api/cart.rb
90
+ - lib/arux_app/api/checkout.rb
90
91
  - lib/arux_app/api/config.rb
91
- - lib/arux_app/api/nav.rb
92
- - lib/arux_app/api/student.rb
93
92
  homepage: https://arux.software
94
93
  licenses:
95
94
  - MIT
@@ -1,29 +0,0 @@
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
@@ -1,43 +0,0 @@
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