Class: Files::FileComment

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FileComment.



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

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

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

Parameters:

body (required) - string - Comment body.
path (required) - string - File path.


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

def self.create(params = {}, options = {})
  raise InvalidParameterError.new("Bad parameter: body must be an String") if params.dig(:body) and !params.dig(:body).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: body") unless params.dig(:body)
  raise MissingParameterError.new("Parameter missing: path") unless params.dig(:path)

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

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



129
130
131
132
133
134
135
136
137
# File 'lib/files.com/models/file_comment.rb', line 129

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

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



139
140
141
# File 'lib/files.com/models/file_comment.rb', line 139

def self.destroy(id, params = {}, options = {})
  delete(id, params, options)
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 either the X-Files-Cursor-Next header or the X-Files-Cursor-Prev header.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
path (required) - string - Path to operate on.


89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/files.com/models/file_comment.rb', line 89

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

  List.new(FileComment, params) do
    Api.send_request("/file_comments/files/#{params[:path]}", :get, params, options)
  end
end

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

Parameters:

body (required) - string - Comment body.


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

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

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

Instance Method Details

#bodyObject

string - Comment body.



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

def body
  @attributes[:body]
end

#body=(value) ⇒ Object



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

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

#delete(params = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/files.com/models/file_comment.rb', line 62

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

#destroy(params = {}) ⇒ Object



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

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

#idObject

int64 - File Comment ID



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

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



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

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

#pathObject

string - File path.



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

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



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

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

#reactionsObject

FileCommentReaction - Reactions to this comment.



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

def reactions
  @attributes[:reactions]
end

#reactions=(value) ⇒ Object



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

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

#saveObject



76
77
78
79
80
81
82
83
# File 'lib/files.com/models/file_comment.rb', line 76

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

#update(params = {}) ⇒ Object

Parameters:

body (required) - string - Comment body.


50
51
52
53
54
55
56
57
58
59
60
# File 'lib/files.com/models/file_comment.rb', line 50

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

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