Class: Files::Behavior

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Behavior.



7
8
9
10
# File 'lib/files.com/models/behavior.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/behavior.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

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



135
136
137
# File 'lib/files.com/models/behavior.rb', line 135

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

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

Parameters:

value - string - The value of the folder behavior.  Can be a integer, array, or hash depending on the type of folder behavior. See The Behavior Types section for example values for each type of behavior.
attachment_file - file - Certain behaviors may require a file, for instance, the "watermark" behavior requires a watermark image
path (required) - string - Folder behaviors path.
behavior (required) - string - Behavior type.


195
196
197
198
199
200
201
202
203
204
# File 'lib/files.com/models/behavior.rb', line 195

def self.create(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: value must be an String") if params.dig(:value) and !params.dig(:value).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)
  raise MissingParameterError.new("Parameter missing: behavior") unless params.dig(:behavior)

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

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



244
245
246
247
248
249
250
251
252
# File 'lib/files.com/models/behavior.rb', line 244

def self.delete(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("/behaviors/#{params[:id]}", :delete, params, options)
  response.data
end

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



254
255
256
# File 'lib/files.com/models/behavior.rb', line 254

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

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

Parameters:

id (required) - int64 - Behavior ID.


141
142
143
144
145
146
147
148
149
# File 'lib/files.com/models/behavior.rb', line 141

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("/behaviors/#{params[:id]}", :get, params, options)
  Behavior.new(response.data, options)
end

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



151
152
153
# File 'lib/files.com/models/behavior.rb', line 151

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

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

Parameters:

cursor - string - Used for pagination.  Send a cursor value to resume an existing list from the point at which you left off.  Get a cursor from an existing list via the X-Files-Cursor-Next header.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
sort_by - object - If set, sort records by the specified field in either 'asc' or 'desc' direction (e.g. sort_by[last_login_at]=desc). Valid fields are `behavior`.
filter - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `behavior`.
filter_gt - object - If set, return records where the specifiied field is greater than the supplied value. Valid fields are `behavior`.
filter_gteq - object - If set, return records where the specifiied field is greater than or equal to the supplied value. Valid fields are `behavior`.
filter_like - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `behavior`.
filter_lt - object - If set, return records where the specifiied field is less than the supplied value. Valid fields are `behavior`.
filter_lteq - object - If set, return records where the specifiied field is less than or equal to the supplied value. Valid fields are `behavior`.
behavior - string - If set, only shows folder behaviors matching this behavior type.


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/files.com/models/behavior.rb', line 118

def self.list(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: cursor must be an String") if params.dig(:cursor) and !params.dig(:cursor).is_a?(String)
  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: sort_by must be an Hash") if params.dig(:sort_by) and !params.dig(:sort_by).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter must be an Hash") if params.dig(:filter) and !params.dig(:filter).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gt must be an Hash") if params.dig(:filter_gt) and !params.dig(:filter_gt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gteq must be an Hash") if params.dig(:filter_gteq) and !params.dig(:filter_gteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_like must be an Hash") if params.dig(:filter_like) and !params.dig(:filter_like).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lt must be an Hash") if params.dig(:filter_lt) and !params.dig(:filter_lt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lteq must be an Hash") if params.dig(:filter_lteq) and !params.dig(:filter_lteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)

  List.new(Behavior, params) do
    Api.send_request("/behaviors", :get, params, options)
  end
end

.list_for(path, params = {}, options = {}) ⇒ Object

Parameters:

cursor - string - Used for pagination.  Send a cursor value to resume an existing list from the point at which you left off.  Get a cursor from an existing list via the X-Files-Cursor-Next header.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
sort_by - object - If set, sort records by the specified field in either 'asc' or 'desc' direction (e.g. sort_by[last_login_at]=desc). Valid fields are `behavior`.
filter - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `behavior`.
filter_gt - object - If set, return records where the specifiied field is greater than the supplied value. Valid fields are `behavior`.
filter_gteq - object - If set, return records where the specifiied field is greater than or equal to the supplied value. Valid fields are `behavior`.
filter_like - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `behavior`.
filter_lt - object - If set, return records where the specifiied field is less than the supplied value. Valid fields are `behavior`.
filter_lteq - object - If set, return records where the specifiied field is less than or equal to the supplied value. Valid fields are `behavior`.
path (required) - string - Path to operate on.
recursive - string - Show behaviors above this path?
behavior - string - DEPRECATED: If set only shows folder behaviors matching this behavior type. Use `filter[behavior]` instead.


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/files.com/models/behavior.rb', line 168

def self.list_for(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: cursor must be an String") if params.dig(:cursor) and !params.dig(:cursor).is_a?(String)
  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: sort_by must be an Hash") if params.dig(:sort_by) and !params.dig(:sort_by).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter must be an Hash") if params.dig(:filter) and !params.dig(:filter).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gt must be an Hash") if params.dig(:filter_gt) and !params.dig(:filter_gt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gteq must be an Hash") if params.dig(:filter_gteq) and !params.dig(:filter_gteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_like must be an Hash") if params.dig(:filter_like) and !params.dig(:filter_like).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lt must be an Hash") if params.dig(:filter_lt) and !params.dig(:filter_lt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lteq must be an Hash") if params.dig(:filter_lteq) and !params.dig(:filter_lteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: recursive must be an String") if params.dig(:recursive) and !params.dig(:recursive).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

  List.new(Behavior, params) do
    Api.send_request("/behaviors/folders/#{params[:path]}", :get, params, options)
  end
end

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

Parameters:

value - string - The value of the folder behavior.  Can be a integer, array, or hash depending on the type of folder behavior. See The Behavior Types section for example values for each type of behavior.
attachment_file - file - Certain behaviors may require a file, for instance, the "watermark" behavior requires a watermark image
behavior - string - Behavior type.
path - string - Folder behaviors path.


231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/files.com/models/behavior.rb', line 231

def self.update(id, params = {}, options = {})
  params ||= {}
  params[:id] = id
  raise InvalidParameterError.new("Bad parameter: id must be one of String, Integer, Hash") if params.dig(:id) and [ String, Integer, Hash ].none? { |klass| params.dig(:id).is_a?(klass) }
  raise InvalidParameterError.new("Bad parameter: value must be an String") if params.dig(:value) and !params.dig(:value).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: path must be one of String, Integer, Hash") if params.dig(:path) and [ String, Integer, Hash ].none? { |klass| params.dig(:path).is_a?(klass) }
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  response, options = Api.send_request("/behaviors/#{params[:id]}", :patch, params, options)
  Behavior.new(response.data, options)
end

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

Parameters:

url (required) - string - URL for testing the webhook.
method - string - HTTP method(GET or POST).
encoding - string - HTTP encoding method.  Can be JSON, XML, or RAW (form data).
headers - object - Additional request headers.
body - object - Additional body parameters.
action - string - action for test body


213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/files.com/models/behavior.rb', line 213

def self.webhook_test(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: url must be an String") if params.dig(:url) and !params.dig(:url).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: method must be an String") if params.dig(:method) and !params.dig(:method).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: encoding must be an String") if params.dig(:encoding) and !params.dig(:encoding).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: headers must be an Hash") if params.dig(:headers) and !params.dig(:headers).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: body must be an Hash") if params.dig(:body) and !params.dig(:body).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
  raise MissingParameterError.new("Parameter missing: url") unless params.dig(:url)

  response, _options = Api.send_request("/behaviors/webhook/test", :post, params, options)
  response.data
end

Instance Method Details

#attachment_fileObject

file - Certain behaviors may require a file, for instance, the “watermark” behavior requires a watermark image



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

def attachment_file
  @attributes[:attachment_file]
end

#attachment_file=(value) ⇒ Object



62
63
64
# File 'lib/files.com/models/behavior.rb', line 62

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

#attachment_urlObject

string - URL for attached file



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

def attachment_url
  @attributes[:attachment_url]
end

#attachment_url=(value) ⇒ Object



35
36
37
# File 'lib/files.com/models/behavior.rb', line 35

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

#behaviorObject

string - Behavior type.



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

def behavior
  @attributes[:behavior]
end

#behavior=(value) ⇒ Object



44
45
46
# File 'lib/files.com/models/behavior.rb', line 44

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

#delete(params = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/files.com/models/behavior.rb', line 84

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("/behaviors/#{@attributes[:id]}", :delete, params, @options)
end

#destroy(params = {}) ⇒ Object



94
95
96
# File 'lib/files.com/models/behavior.rb', line 94

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

#idObject

int64 - Folder behavior ID



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

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



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

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

#pathObject

string - Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.



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

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



26
27
28
# File 'lib/files.com/models/behavior.rb', line 26

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

#saveObject



98
99
100
101
102
103
104
105
# File 'lib/files.com/models/behavior.rb', line 98

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

#update(params = {}) ⇒ Object

Parameters:

value - string - The value of the folder behavior.  Can be a integer, array, or hash depending on the type of folder behavior. See The Behavior Types section for example values for each type of behavior.
attachment_file - file - Certain behaviors may require a file, for instance, the "watermark" behavior requires a watermark image
behavior - string - Behavior type.
path - string - Folder behaviors path.


71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/files.com/models/behavior.rb', line 71

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: value must be an String") if params.dig(:value) and !params.dig(:value).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: behavior must be an String") if params.dig(:behavior) and !params.dig(:behavior).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

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

#valueObject

object - Settings for this behavior. See the section above for an example value to provide here. Formatting is different for each Behavior type. May be sent as nested JSON or a single JSON-encoded string. If using XML encoding for the API call, this data must be sent as a JSON-encoded string.



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

def value
  @attributes[:value]
end

#value=(value) ⇒ Object



53
54
55
# File 'lib/files.com/models/behavior.rb', line 53

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