Class: Files::ApiKey

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/api_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ ApiKey

Returns a new instance of ApiKey.



7
8
9
10
# File 'lib/files.com/models/api_key.rb', line 7

def initialize(attributes = {}, options = {})
  @attributes = attributes || {}
  @options = options || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/api_key.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/api_key.rb', line 5

def options
  @options
end

Class Method Details

.all(params = {}, options = {}) ⇒ Object



144
145
146
# File 'lib/files.com/models/api_key.rb', line 144

def self.all(params = {}, options = {})
  list(params, options)
end

.create(params = {}, options = {}) ⇒ Object

Parameters:

user_id - integer - User ID.  Provide a value of `0` to operate the current session's user.
name - string - Internal name for key.  For your reference only.
permission_set - string - Leave blank, or set to 'desktop_app' to restrict the key to only desktop app functions.
expires_at - string - Have the key expire at this date/time.


169
170
171
172
173
174
175
176
177
# File 'lib/files.com/models/api_key.rb', line 169

def self.create(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: user_id must be an Integer") if params.dig(:user_id) and !params.dig(:user_id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: permission_set must be an String") if params.dig(:permission_set) and !params.dig(:permission_set).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: expires_at must be an String") if params.dig(:expires_at) and !params.dig(:expires_at).is_a?(String)

  response, options = Api.send_request("/api_keys", :post, params, options)
  ApiKey.new(response.data, options)
end

.delete(params = {}, options = {}) ⇒ Object



192
193
194
195
# File 'lib/files.com/models/api_key.rb', line 192

def self.delete(params = {}, options = {})
  response, _options = Api.send_request("/api_key", :delete, params, options)
  response.data
end

.destroy(params = {}, options = {}) ⇒ Object



197
198
199
# File 'lib/files.com/models/api_key.rb', line 197

def self.destroy(params = {}, options = {})
  delete(params, options)
end

.find(id, params = {}, options = {}) ⇒ Object

Parameters:

id (required) - integer - Api Key ID.


150
151
152
153
154
155
156
157
158
# File 'lib/files.com/models/api_key.rb', line 150

def self.find(id, params = {}, options = {})
  params ||= {}
  params[:id] = id
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  response, options = Api.send_request("/api_keys/#{params[:id]}", :get, params, options)
  ApiKey.new(response.data, options)
end

.get(id, params = {}, options = {}) ⇒ Object



160
161
162
# File 'lib/files.com/models/api_key.rb', line 160

def self.get(id, params = {}, options = {})
  find(id, params, options)
end

.list(params = {}, options = {}) ⇒ Object

Parameters:

user_id - integer - User ID.  Provide a value of `0` to operate the current session's user.
page - integer - Current page number.
per_page - integer - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
action - string - Deprecated: If set to `count` returns a count of matching records rather than the records themselves.


134
135
136
137
138
139
140
141
142
# File 'lib/files.com/models/api_key.rb', line 134

def self.list(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: user_id must be an Integer") if params.dig(:user_id) and !params.dig(:user_id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)

  response, options = Api.send_request("/api_keys", :get, params, options)
  response.data.map { |object| ApiKey.new(object, options) }
end

.update(params = {}, options = {}) ⇒ Object

Parameters:

name - string - Internal name for key.  For your reference only.
permission_set - string - Leave blank, or set to `desktop_app` to restrict the key to only desktop app functions.
expires_at - string - Have the key expire at this date/time.


183
184
185
186
187
188
189
190
# File 'lib/files.com/models/api_key.rb', line 183

def self.update(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: permission_set must be an String") if params.dig(:permission_set) and !params.dig(:permission_set).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: expires_at must be an String") if params.dig(:expires_at) and !params.dig(:expires_at).is_a?(String)

  response, options = Api.send_request("/api_key", :patch, params, options)
  ApiKey.new(response.data, options)
end

Instance Method Details

#created_atObject

date-time - Time which API Key was created



22
23
24
# File 'lib/files.com/models/api_key.rb', line 22

def created_at
  @attributes[:created_at]
end

#delete(params = {}) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/files.com/models/api_key.rb', line 106

def delete(params = {})
  params ||= {}
  params[:id] = @attributes[:id]
  raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id]
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  Api.send_request("/api_keys/#{@attributes[:id]}", :delete, params, @options)
end

#destroy(params = {}) ⇒ Object



116
117
118
# File 'lib/files.com/models/api_key.rb', line 116

def destroy(params = {})
  delete(params)
end

#expires_atObject

date-time - API Key expiration date



27
28
29
# File 'lib/files.com/models/api_key.rb', line 27

def expires_at
  @attributes[:expires_at]
end

#expires_at=(value) ⇒ Object



31
32
33
# File 'lib/files.com/models/api_key.rb', line 31

def expires_at=(value)
  @attributes[:expires_at] = value
end

#idObject

int64 - API Key ID



13
14
15
# File 'lib/files.com/models/api_key.rb', line 13

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



17
18
19
# File 'lib/files.com/models/api_key.rb', line 17

def id=(value)
  @attributes[:id] = value
end

#keyObject

string - API Key actual key string



36
37
38
# File 'lib/files.com/models/api_key.rb', line 36

def key
  @attributes[:key]
end

#key=(value) ⇒ Object



40
41
42
# File 'lib/files.com/models/api_key.rb', line 40

def key=(value)
  @attributes[:key] = value
end

#last_use_atObject

date-time - API Key last used - note this value is only updated once per 3 hour period, so the ‘actual’ time of last use may be up to 3 hours later than this timestamp.



45
46
47
# File 'lib/files.com/models/api_key.rb', line 45

def last_use_at
  @attributes[:last_use_at]
end

#last_use_at=(value) ⇒ Object



49
50
51
# File 'lib/files.com/models/api_key.rb', line 49

def last_use_at=(value)
  @attributes[:last_use_at] = value
end

#nameObject

string - Internal name for the API Key. For your use.



54
55
56
# File 'lib/files.com/models/api_key.rb', line 54

def name
  @attributes[:name]
end

#name=(value) ⇒ Object



58
59
60
# File 'lib/files.com/models/api_key.rb', line 58

def name=(value)
  @attributes[:name] = value
end

#permission_setObject

string - Permissions for this API Key. Keys with the ‘desktop_app` permission set only have the ability to do the functions provided in our Desktop App (File and Share Link operations.) We hope to offer additional permission sets in the future, such as for a Site Admin to give a key with no administrator privileges. If you have ideas for permission sets, please let us know.



63
64
65
# File 'lib/files.com/models/api_key.rb', line 63

def permission_set
  @attributes[:permission_set]
end

#permission_set=(value) ⇒ Object



67
68
69
# File 'lib/files.com/models/api_key.rb', line 67

def permission_set=(value)
  @attributes[:permission_set] = value
end

#platformObject

string - If this API key represents a Desktop app, what platform was it created on?



72
73
74
# File 'lib/files.com/models/api_key.rb', line 72

def platform
  @attributes[:platform]
end

#platform=(value) ⇒ Object



76
77
78
# File 'lib/files.com/models/api_key.rb', line 76

def platform=(value)
  @attributes[:platform] = value
end

#saveObject



120
121
122
123
124
125
126
127
# File 'lib/files.com/models/api_key.rb', line 120

def save
  if @attributes[:id]
    update(@attributes)
  else
    new_obj = ApiKey.create(@attributes, @options)
    @attributes = new_obj.attributes
  end
end

#update(params = {}) ⇒ Object

Parameters:

name - string - Internal name for key.  For your reference only.
permission_set - string - Leave blank, or set to 'desktop_app' to restrict the key to only desktop app functions.
expires_at - string - Have the key expire at this date/time.


93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/files.com/models/api_key.rb', line 93

def update(params = {})
  params ||= {}
  params[:id] = @attributes[:id]
  raise MissingParameterError.new("Current object doesn't have a id") unless @attributes[:id]
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: name must be an String") if params.dig(:name) and !params.dig(:name).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: permission_set must be an String") if params.dig(:permission_set) and !params.dig(:permission_set).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: expires_at must be an String") if params.dig(:expires_at) and !params.dig(:expires_at).is_a?(String)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  Api.send_request("/api_keys/#{@attributes[:id]}", :patch, params, @options)
end

#user_idObject

int64 - User ID for the owner of this API Key. May be blank for Site-wide API Keys.



81
82
83
# File 'lib/files.com/models/api_key.rb', line 81

def user_id
  @attributes[:user_id]
end

#user_id=(value) ⇒ Object



85
86
87
# File 'lib/files.com/models/api_key.rb', line 85

def user_id=(value)
  @attributes[:user_id] = value
end