userbin 1.4.7 → 1.5.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
  SHA1:
3
- metadata.gz: fe3459497c3122f6b5e380b429a1d9dbb5b485ea
4
- data.tar.gz: 9df0a146b6cc26ff2b404354a58728a27ceda9ae
3
+ metadata.gz: bb87601eef49b0f5d845aadecd86b36c2aa2a5a2
4
+ data.tar.gz: d35d0620253e7702afbdddd95b1a94c586018b34
5
5
  SHA512:
6
- metadata.gz: 1a2274aa29cfa87f220ababb741014d90946da71b0d31d2a20b208e2efd8b1b544befb43ba79820febfcaa82823ff78a4a0a0abc8b36cfa3c8ed8ed324f9c78e
7
- data.tar.gz: 817146fe462f1147baccf117ea78f783d42173d2a2877142e9939c774eab0837cd73c96140329ec5da86dbf0a62f501fe4f57cc61bf656f6b2f5b0035cd57994
6
+ metadata.gz: 7a7d1ad419f59374579ecff1a8d3038671da449fc9b7dd4a637ba8db300c711fe07394d6fc9d842e50a935c0055acc2c375d5a5f53f8610588b37371d581feb3
7
+ data.tar.gz: 2cda728dfc00d9c03288037a5b6039ff04b40d0d5a150994d4a329a7e34a40f7feaf844b8ec41f4540346548a10b04d69d58674262cc486a3ee7c7169104863f
data/README.md CHANGED
@@ -43,17 +43,6 @@ require 'userbin'
43
43
  Userbin.api_secret = "YOUR_API_SECRET"
44
44
  ```
45
45
 
46
- Add a reference to the Userbin client in your main controller so that it's globally accessible throughout a request. The initializer takes a Rack **request** as argument from which it extracts details such as IP address and user agent and sends it along all API requests. The second argument is a reference to the **cookies** hash, used for storing the trusted device token.
47
-
48
- ```ruby
49
- class ApplicationController < ActionController::Base
50
- def userbin
51
- @userbin ||= Userbin::Client.new(request, cookies)
52
- end
53
- # ...
54
- end
55
- ```
56
-
57
46
  ## Setup User Monitoring
58
47
 
59
48
  You should call `login` as soon as the user has logged in to your application. Pass a unique user identifier, and an *optional* hash of user properties which are used when searching for users in your dashboard. This will create a [Session](https://api.userbin.com/#POST--version-users--user_id-sessions---format-) resource and return a corresponding [session token](https://api.userbin.com/#session-tokens) which is stored in the Userbin client.
@@ -19,6 +19,15 @@ require 'userbin/utils'
19
19
  require 'userbin/request'
20
20
  require 'userbin/session_token'
21
21
 
22
+ require 'userbin/support/rails' if defined?(Rails::Railtie)
23
+ if defined?(Sinatra::Base)
24
+ if defined?(Padrino)
25
+ require 'userbin/support/padrino'
26
+ else
27
+ require 'userbin/support/sinatra'
28
+ end
29
+ end
30
+
22
31
  module Userbin
23
32
  API = Userbin.setup_api
24
33
  end
@@ -115,6 +115,8 @@ module Userbin
115
115
 
116
116
  # Set the session token for use in all subsequent requests
117
117
  self.session_token = session.token
118
+
119
+ session
118
120
  end
119
121
 
120
122
  def trust_device(attrs = {})
@@ -0,0 +1,16 @@
1
+ module Userbin
2
+ class CookieStore
3
+ def initialize(request, response)
4
+ @request = request
5
+ @response = response
6
+ end
7
+
8
+ def [](key)
9
+ @request.cookies[key]
10
+ end
11
+
12
+ def []=(key, value)
13
+ @response.set_cookie key, value
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'cookie_store'
2
+
3
+ module Padrino
4
+ class Application
5
+ module Userbin
6
+ module Helpers
7
+ def userbin
8
+ store = ::Userbin::CookieStore.new(request, response)
9
+ @userbin ||= ::Userbin::Client.new(request, store)
10
+ end
11
+ end
12
+
13
+ def self.registered(app)
14
+ app.helpers Helpers
15
+ end
16
+ end
17
+
18
+ register Userbin
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ module Userbin
2
+ module UserbinClient
3
+ def userbin
4
+ @userbin ||= Userbin::Client.new(request, cookies)
5
+ end
6
+ end
7
+
8
+ ActiveSupport.on_load(:action_controller) do
9
+ include UserbinClient
10
+ end
11
+ end
@@ -1,11 +1,11 @@
1
- require 'sinatra/base'
1
+ require_relative 'cookie_store'
2
2
 
3
3
  module Sinatra
4
4
  module Userbin
5
5
  module Helpers
6
6
  def userbin
7
- binding.pry
8
- 'hey'
7
+ store = ::Userbin::CookieStore.new(request, response)
8
+ @userbin ||= ::Userbin::Client.new(request, store)
9
9
  end
10
10
  end
11
11
 
@@ -1,3 +1,3 @@
1
1
  module Userbin
2
- VERSION = "1.4.7"
2
+ VERSION = "1.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userbin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.7
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-03 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: her
@@ -172,7 +172,6 @@ extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
174
  - README.md
175
- - lib/sinatra/userbin.rb
176
175
  - lib/userbin.rb
177
176
  - lib/userbin/client.rb
178
177
  - lib/userbin/configuration.rb
@@ -192,6 +191,10 @@ files:
192
191
  - lib/userbin/request.rb
193
192
  - lib/userbin/session_store.rb
194
193
  - lib/userbin/session_token.rb
194
+ - lib/userbin/support/cookie_store.rb
195
+ - lib/userbin/support/padrino.rb
196
+ - lib/userbin/support/rails.rb
197
+ - lib/userbin/support/sinatra.rb
195
198
  - lib/userbin/trusted_token_store.rb
196
199
  - lib/userbin/utils.rb
197
200
  - lib/userbin/version.rb