Class: Motion::Authentication::DeviseTokenAuthGem
- Inherits:
-
Object
- Object
- Motion::Authentication::DeviseTokenAuthGem
- Defined in:
- lib/project/strategies/devise_token_auth_gem.rb
Class Method Summary collapse
- .authorization_header ⇒ Object
- .deserialize(mystring, arr_sep = ',', key_sep = '·') ⇒ Object
- .set_current_user ⇒ Object
- .sign_in(sign_in_url, params, &block) ⇒ Object
- .sign_out(&block) ⇒ Object
- .sign_up(sign_up_url, params, &block) ⇒ Object
- .signed_in? ⇒ Boolean
- .store_auth_tokens(response, headers) ⇒ Object
Class Method Details
.authorization_header ⇒ Object
48 49 50 51 52 53 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 48 def token = MotionKeychain.get :auth_token uid = MotionKeychain.get :auth_uid client = MotionKeychain.get :auth_client {"access-token" => token, "uid" => uid, "client" => client } end |
.deserialize(mystring, arr_sep = ',', key_sep = '·') ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 67 def deserialize(mystring,arr_sep=',', key_sep='·') array = mystring.split(arr_sep) hash = {} array.each do |e| key_value = e.split(key_sep) hash[key_value[0]] = key_value[1] end return hash end |
.set_current_user ⇒ Object
44 45 46 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 44 def set_current_user deserialize(MotionKeychain.get :current_user) end |
.sign_in(sign_in_url, params, &block) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 6 def sign_in(sign_in_url, params, &block) AFMotion::JSON.post(sign_in_url, params) do |response| if response.success? store_auth_tokens(response.object,response.operation.response.allHeaderFields) end block.call(response) end end |
.sign_out(&block) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 59 def sign_out(&block) MotionKeychain.remove :auth_uid MotionKeychain.remove :auth_token MotionKeychain.remove :auth_client MotionKeychain.remove :current_user block.call end |
.sign_up(sign_up_url, params, &block) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 15 def sign_up(sign_up_url, params, &block) AFMotion::JSON.post(sign_up_url, params) do |response| if response.success? store_auth_tokens(response.object,response.operation.response.allHeaderFields) end block.call(response) end end |
.signed_in? ⇒ Boolean
55 56 57 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 55 def signed_in? !! MotionKeychain.get(:auth_token) end |
.store_auth_tokens(response, headers) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/project/strategies/devise_token_auth_gem.rb', line 24 def store_auth_tokens(response,headers) MotionKeychain.set :auth_uid, headers["uid"] MotionKeychain.set :auth_token, headers["access-token"] MotionKeychain.set :auth_client, headers["client"] serialized_response = "" response["data"].each do |key,value| case key when "assets" value.each do |eachasset| serialized_response << eachasset["name"] + "·" + eachasset["qty"].to_s + "," end when "friends" #do nothing else serialized_response << key + "·" + value.to_s + "," end end MotionKeychain.set :current_user, serialized_response end |