Class: Unit::ApiToken::Org::CreateApiTokenRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/unit/models/api_token/org/create_api_token_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, description, scope, expiration, source_ip = nil, resources = nil) ⇒ CreateApiTokenRequest

Returns a new instance of CreateApiTokenRequest.

Parameters:

  • user_id (String)
  • description (String)
  • scope (Array<String>)
  • expiration (String)
  • source_ip (String) (defaults to: nil)
    • optional

  • resources (Array<RestrictedResource>) (defaults to: nil)
    • optional



17
18
19
20
21
22
23
24
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 17

def initialize(user_id, description, scope, expiration, source_ip = nil, resources = nil)
  @user_id = user_id
  @description = description
  @scope = scope
  @expiration = expiration
  @source_ip = source_ip
  @resources = resources
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def description
  @description
end

#expirationObject (readonly)

Returns the value of attribute expiration.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def expiration
  @expiration
end

#resourcesObject (readonly)

Returns the value of attribute resources.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def resources
  @resources
end

#scopeObject (readonly)

Returns the value of attribute scope.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def scope
  @scope
end

#source_ipObject (readonly)

Returns the value of attribute source_ip.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def source_ip
  @source_ip
end

#user_idObject (readonly)

Returns the value of attribute user_id.



9
10
11
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 9

def user_id
  @user_id
end

Instance Method Details

#to_json_apiObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/unit/models/api_token/org/create_api_token_request.rb', line 26

def to_json_api
  result = { data: { type: "apiToken",
                     attributes:
                       { description: description,
                         scope: scope.join(" "),
                         expiration: expiration,
                         sourceIp: source_ip,
                         resources: resources } } }
  result[:data][:attributes].compact!
  result.to_json
end