authbox 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authbox.rb +21 -23
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88f3bad31b1a1dc5767a54eba3593de501f0a0bb
4
- data.tar.gz: d3f8f8c13f83a669824f9f3488915c1a95cb49ef
3
+ metadata.gz: 043a3f024ab2ffbee3924fbb1db65f0355a37b71
4
+ data.tar.gz: c05d9d06d4a9c94b5629a529225e8c3f22f220cb
5
5
  SHA512:
6
- metadata.gz: c52b50856e96ebcf07272763549b82432613b69aa7abc1fd009c8ad57de51686e07ae1f89f00ac1a8acf513f0d59516905248fb89d5dc0b844580a8930288821
7
- data.tar.gz: 04823d5d38976a4a89debf7f7e5bad4c4ef55657320e90eea2dc82da6b05143c606852f599ef509adde7c4ac7c8d465623bb5780a2bf30cf796c77fcadb52fd1
6
+ metadata.gz: 50a26b11ba2b16dcd23ff55018c47be35e1662fc5cccfbf4b0b9bb997e74076e753dbb84665fd569e9f47abfb0157124aa43a1b86791f83a6752bcb2fe843584
7
+ data.tar.gz: 9004ce71a310cbc65ba6b904451c05db4e712eb127228e6eb3e39819f02348e2f2b80cb539ffd48ca37f395a29ea15818ee623c2348b4adea6589186f54923dd
data/lib/authbox.rb CHANGED
@@ -55,31 +55,25 @@ module Authbox
55
55
  # will be logged. See the documentation for what information
56
56
  # you can pass here in the action hash.
57
57
  def authbox_log(action={})
58
- if not authbox_ensure_one_request()
59
- return @authbox_verdict
58
+ if not authbox_ensure_one_request(:log)
59
+ return
60
60
  end
61
61
 
62
- return authbox_request('/action', action, true)
63
- end
64
-
65
- def authbox_check(action={})
66
- if not authbox_ensure_one_request()
67
- return @authbox_verdict
62
+ if not @authbox_verdict.blank? and @authbox_verdict['type'] != 'ALLOW'
63
+ return
68
64
  end
69
65
 
70
- return authbox_request('/action', action, false)
66
+
67
+ return authbox_request('/action_log', action, true)
71
68
  end
72
69
 
73
- def authbox_begin(action={})
74
- if not authbox_ensure_one_request()
70
+ def authbox_check(action={})
71
+ if not authbox_ensure_one_request(:check)
75
72
  return @authbox_verdict
76
73
  end
77
74
 
78
- return authbox_request('/action_begin', action, false)
79
- end
80
-
81
- def authbox_end(action={})
82
- return authbox_request('/action_end', action, false)
75
+ @authbox_check_action = action
76
+ return authbox_request('/action_check', action, false)
83
77
  end
84
78
 
85
79
  ##
@@ -143,13 +137,13 @@ module Authbox
143
137
  return Rails.configuration.authbox[:endpoint] || 'https://api.authbox.io/api'
144
138
  end
145
139
 
146
- def authbox_ensure_one_request
147
- if @authbox_requested
140
+ def authbox_ensure_one_request(type)
141
+ if @authbox_fired[type]
148
142
  authbox_warn_log { 'authbox_log() already called' }
149
143
  return false
150
144
  end
151
145
 
152
- @authbox_requested = true
146
+ @authbox_fired[type] = true
153
147
  return true
154
148
  end
155
149
 
@@ -217,7 +211,7 @@ module Authbox
217
211
  begin
218
212
  parsed_response = JSON.parse(response.body)
219
213
  if not parsed_response.has_key? 'type'
220
- @authbox_verdict = {'type' => 'ALLOW', 'info' => 'No verdict returend'}
214
+ @authbox_verdict = {'type' => 'ALLOW', 'info' => 'No verdict returned'}
221
215
  return @authbox_verdict
222
216
  end
223
217
  rescue => e
@@ -238,13 +232,17 @@ module Authbox
238
232
  end
239
233
 
240
234
  def authbox_before
241
- @authbox_requested = false
235
+ @authbox_fired = {
236
+ :check => false,
237
+ :log => false
238
+ }
239
+ @authbox_check_action = {}
242
240
  @authbox_insert_pixel = rand() < 0.01
243
241
  end
244
242
 
245
243
  def authbox_after
246
- if not @authbox_requested
247
- authbox_log({})
244
+ if not @authbox_fired[:log]
245
+ authbox_log @authbox_check_action
248
246
 
249
247
  if @authbox_insert_pixel and Rails.configuration.authbox.fetch(:enable_tracking_pixel, true)
250
248
  endpoint = authbox_get_endpoint()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Authbox, Inc.