Class: NeAPI::Auth

Inherits:
Object
  • Object
show all
Includes:
NeAPI
Defined in:
lib/ne_api.rb

Constant Summary collapse

SIGN_IN_PATH =
"/users/sign_in/"
NEAUTH_PATH =
"/api_neauth/"

Constants included from NeAPI

API_SERVER_HOST, NE_SERVER_HOST

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redirect_url: nil) ⇒ Auth

Returns a new instance of Auth.

Raises:


141
142
143
144
145
# File 'lib/ne_api.rb', line 141

def initialize redirect_url: nil
  raise NeAPIException, "no redirect_url" if redirect_url.nil?
  @wait_flag = false
  @redirect_url = redirect_url
end

Instance Attribute Details

#ne_userObject

Returns the value of attribute ne_user


139
140
141
# File 'lib/ne_api.rb', line 139

def ne_user
  @ne_user
end

#redirect_urlObject

Returns the value of attribute redirect_url


139
140
141
# File 'lib/ne_api.rb', line 139

def redirect_url
  @redirect_url
end

#wait_flagObject

Returns the value of attribute wait_flag


139
140
141
# File 'lib/ne_api.rb', line 139

def wait_flag
  @wait_flag
end

Instance Method Details

#ne_auth(uid, state) ⇒ Object

access_token/企業情報取得

Raises:


153
154
155
156
157
# File 'lib/ne_api.rb', line 153

def ne_auth uid, state
  @ne_user = response ( conn.post NEAUTH_PATH, {uid: uid, state: state})
  raise NeAPIException, "003001:Next Engineが大変混み合っているようです" if @ne_user == false
  @ne_user
end

#sign_in(client_id = ENV["CLIENT_ID"], client_secret = ENV["CLIENT_SECRET"]) ⇒ Object

uid/state取得


148
149
150
# File 'lib/ne_api.rb', line 148

def  client_id = ENV["CLIENT_ID"] , client_secret = ENV["CLIENT_SECRET"]
  Launchy.open NE_SERVER_HOST + SIGN_IN_PATH + "?client_id="+client_id+"&client_secret="+client_secret+"&redirect_uri="+@redirect_url
end

#tokensObject


158
159
160
# File 'lib/ne_api.rb', line 158

def tokens
  @ne_user.nil? ?  nil : {access_token: @ne_user["access_token"], refresh_token: @ne_user["refresh_token"]}
end