3 # Get or Create an anonymous user token.
4 # If get option is used, an existing anonymous user token is returned. If none exist, one is created.
5 # If the get option is omitted, a new token is created and returned.
9 opts = Trollop::options do
11 banner "Usage: get_anonymous_user_token "
14 Get an existing anonymous user token. If no such token exists \
15 or if this option is omitted, a new token is created and returned.
19 get_existing = opts[:get]
21 require File.dirname(__FILE__) + '/../config/environment'
23 include ApplicationHelper
28 def create_api_client_auth
29 api_client_auth = ApiClientAuthorization.
30 new(user: anonymous_user,
32 expires_at: db_current_time + 100.years,
35 api_client_auth.reload
39 api_client_auth = ApiClientAuthorization.
40 where('user_id=?', anonymous_user.id.to_i).
41 where('expires_at>?', db_current_time).
42 select { |auth| auth.scopes == ['GET /'] }.
46 # either not a get or no api_client_auth was found
48 api_client_auth = create_api_client_auth
51 # print it to the console
52 puts api_client_auth.api_token