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
26 def create_api_client_auth
27 api_client_auth = ApiClientAuthorization.
28 new(user: anonymous_user,
30 expires_at: Time.now + 100.years,
33 api_client_auth.reload
37 api_client_auth = ApiClientAuthorization.
38 where('user_id=?', anonymous_user.id.to_i).
39 where('expires_at>?', Time.now).
40 select { |auth| auth.scopes == ['GET /'] }.
44 # either not a get or no api_client_auth was found
46 api_client_auth = create_api_client_auth
49 # print it to the console
50 puts api_client_auth.api_token