Class: PostProxy::Resources::Comments
- Inherits:
-
Object
- Object
- PostProxy::Resources::Comments
- Defined in:
- lib/postproxy/resources/comments.rb
Instance Method Summary collapse
- #create(post_id, text, profile_id:, parent_id: nil) ⇒ Object
- #delete(post_id, comment_id, profile_id:) ⇒ Object
- #get(post_id, comment_id, profile_id:) ⇒ Object
- #hide(post_id, comment_id, profile_id:) ⇒ Object
-
#initialize(client) ⇒ Comments
constructor
A new instance of Comments.
- #like(post_id, comment_id, profile_id:) ⇒ Object
- #list(post_id, profile_id:, page: nil, per_page: nil) ⇒ Object
- #unhide(post_id, comment_id, profile_id:) ⇒ Object
- #unlike(post_id, comment_id, profile_id:) ⇒ Object
Constructor Details
#initialize(client) ⇒ Comments
Returns a new instance of Comments.
4 5 6 |
# File 'lib/postproxy/resources/comments.rb', line 4 def initialize(client) @client = client end |
Instance Method Details
#create(post_id, text, profile_id:, parent_id: nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/postproxy/resources/comments.rb', line 28 def create(post_id, text, profile_id:, parent_id: nil) json_body = { text: text } json_body[:parent_id] = parent_id if parent_id result = @client.request(:post, "/posts/#{post_id}/comments", params: { profile_id: profile_id }, json: json_body) Comment.new(**result) end |
#delete(post_id, comment_id, profile_id:) ⇒ Object
36 37 38 39 |
# File 'lib/postproxy/resources/comments.rb', line 36 def delete(post_id, comment_id, profile_id:) result = @client.request(:delete, "/posts/#{post_id}/comments/#{comment_id}", params: { profile_id: profile_id }) AcceptedResponse.new(**result) end |
#get(post_id, comment_id, profile_id:) ⇒ Object
23 24 25 26 |
# File 'lib/postproxy/resources/comments.rb', line 23 def get(post_id, comment_id, profile_id:) result = @client.request(:get, "/posts/#{post_id}/comments/#{comment_id}", params: { profile_id: profile_id }) Comment.new(**result) end |
#hide(post_id, comment_id, profile_id:) ⇒ Object
41 42 43 44 |
# File 'lib/postproxy/resources/comments.rb', line 41 def hide(post_id, comment_id, profile_id:) result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/hide", params: { profile_id: profile_id }) AcceptedResponse.new(**result) end |
#like(post_id, comment_id, profile_id:) ⇒ Object
51 52 53 54 |
# File 'lib/postproxy/resources/comments.rb', line 51 def like(post_id, comment_id, profile_id:) result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/like", params: { profile_id: profile_id }) AcceptedResponse.new(**result) end |
#list(post_id, profile_id:, page: nil, per_page: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/postproxy/resources/comments.rb', line 8 def list(post_id, profile_id:, page: nil, per_page: nil) params = { profile_id: profile_id } params[:page] = page if page params[:per_page] = per_page if per_page result = @client.request(:get, "/posts/#{post_id}/comments", params: params) comments = (result[:data] || []).map { |c| Comment.new(**c) } PaginatedResponse.new( data: comments, total: result[:total], page: result[:page], per_page: result[:per_page] ) end |
#unhide(post_id, comment_id, profile_id:) ⇒ Object
46 47 48 49 |
# File 'lib/postproxy/resources/comments.rb', line 46 def unhide(post_id, comment_id, profile_id:) result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/unhide", params: { profile_id: profile_id }) AcceptedResponse.new(**result) end |
#unlike(post_id, comment_id, profile_id:) ⇒ Object
56 57 58 59 |
# File 'lib/postproxy/resources/comments.rb', line 56 def unlike(post_id, comment_id, profile_id:) result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/unlike", params: { profile_id: profile_id }) AcceptedResponse.new(**result) end |