postproxy-sdk 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/lib/postproxy/client.rb +6 -0
- data/lib/postproxy/resources/comments.rb +62 -0
- data/lib/postproxy/types.rb +36 -0
- data/lib/postproxy/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e62e2ba2b3d951aed31a2d60d74a7ee4a46672b03131676f28d81f6dc5cade69
|
|
4
|
+
data.tar.gz: 83bf66f3dae825b04195d1ec9e809849352f4c290dbf2d1458879a1838688e93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b38044c1990d12a5d937b261df5b01e80d3cec44caaebd0eeb4eb9038859bb2428c35c6f557421ba8a5cc494347e4e08de7963d98d8ff1ad552960cbcd02dae
|
|
7
|
+
data.tar.gz: 5f3393e61377f4de158148d7c4de2982df376410cc377bdd356d478729bf129a86b5659ea0abc412a4809a55a343dde7b59e4e8ee11ff6957630f7475957286d
|
data/README.md
CHANGED
|
@@ -248,6 +248,43 @@ PostProxy::WebhookSignature.verify(
|
|
|
248
248
|
)
|
|
249
249
|
```
|
|
250
250
|
|
|
251
|
+
## Comments
|
|
252
|
+
|
|
253
|
+
```ruby
|
|
254
|
+
# List comments on a post (paginated)
|
|
255
|
+
comments = client.comments.list("post-id", profile_id: "profile-id")
|
|
256
|
+
comments.data.each do |comment|
|
|
257
|
+
puts "#{comment.author_username}: #{comment.body}"
|
|
258
|
+
comment.replies.each do |reply|
|
|
259
|
+
puts " #{reply.author_username}: #{reply.body}"
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# List with pagination
|
|
264
|
+
comments = client.comments.list("post-id", profile_id: "profile-id", page: 2, per_page: 10)
|
|
265
|
+
|
|
266
|
+
# Get a single comment
|
|
267
|
+
comment = client.comments.get("post-id", "comment-id", profile_id: "profile-id")
|
|
268
|
+
|
|
269
|
+
# Create a comment
|
|
270
|
+
comment = client.comments.create("post-id", profile_id: "profile-id", text: "Great post!")
|
|
271
|
+
|
|
272
|
+
# Reply to a comment
|
|
273
|
+
reply = client.comments.create("post-id", profile_id: "profile-id", text: "Thanks!", parent_id: "comment-id")
|
|
274
|
+
|
|
275
|
+
# Delete a comment
|
|
276
|
+
result = client.comments.delete("post-id", "comment-id", profile_id: "profile-id")
|
|
277
|
+
puts result.accepted # true
|
|
278
|
+
|
|
279
|
+
# Hide / unhide a comment
|
|
280
|
+
client.comments.hide("post-id", "comment-id", profile_id: "profile-id")
|
|
281
|
+
client.comments.unhide("post-id", "comment-id", profile_id: "profile-id")
|
|
282
|
+
|
|
283
|
+
# Like / unlike a comment
|
|
284
|
+
client.comments.like("post-id", "comment-id", profile_id: "profile-id")
|
|
285
|
+
client.comments.unlike("post-id", "comment-id", profile_id: "profile-id")
|
|
286
|
+
```
|
|
287
|
+
|
|
251
288
|
## Profiles
|
|
252
289
|
|
|
253
290
|
```ruby
|
data/lib/postproxy/client.rb
CHANGED
|
@@ -6,6 +6,7 @@ require_relative "resources/profiles"
|
|
|
6
6
|
require_relative "resources/profile_groups"
|
|
7
7
|
require_relative "resources/webhooks"
|
|
8
8
|
require_relative "resources/queues"
|
|
9
|
+
require_relative "resources/comments"
|
|
9
10
|
|
|
10
11
|
module PostProxy
|
|
11
12
|
class Client
|
|
@@ -21,6 +22,7 @@ module PostProxy
|
|
|
21
22
|
@profile_groups = nil
|
|
22
23
|
@webhooks = nil
|
|
23
24
|
@queues = nil
|
|
25
|
+
@comments = nil
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def posts
|
|
@@ -43,6 +45,10 @@ module PostProxy
|
|
|
43
45
|
@queues ||= Resources::Queues.new(self)
|
|
44
46
|
end
|
|
45
47
|
|
|
48
|
+
def comments
|
|
49
|
+
@comments ||= Resources::Comments.new(self)
|
|
50
|
+
end
|
|
51
|
+
|
|
46
52
|
def request(method, path, params: nil, json: nil, data: nil, files: nil, profile_group_id: nil)
|
|
47
53
|
url = "/api#{path}"
|
|
48
54
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module PostProxy
|
|
2
|
+
module Resources
|
|
3
|
+
class Comments
|
|
4
|
+
def initialize(client)
|
|
5
|
+
@client = client
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def list(post_id, profile_id:, page: nil, per_page: nil)
|
|
9
|
+
params = { profile_id: profile_id }
|
|
10
|
+
params[:page] = page if page
|
|
11
|
+
params[:per_page] = per_page if per_page
|
|
12
|
+
|
|
13
|
+
result = @client.request(:get, "/posts/#{post_id}/comments", params: params)
|
|
14
|
+
comments = (result[:data] || []).map { |c| Comment.new(**c) }
|
|
15
|
+
PaginatedResponse.new(
|
|
16
|
+
data: comments,
|
|
17
|
+
total: result[:total],
|
|
18
|
+
page: result[:page],
|
|
19
|
+
per_page: result[:per_page]
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get(post_id, comment_id, profile_id:)
|
|
24
|
+
result = @client.request(:get, "/posts/#{post_id}/comments/#{comment_id}", params: { profile_id: profile_id })
|
|
25
|
+
Comment.new(**result)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def create(post_id, text, profile_id:, parent_id: nil)
|
|
29
|
+
json_body = { text: text }
|
|
30
|
+
json_body[:parent_id] = parent_id if parent_id
|
|
31
|
+
|
|
32
|
+
result = @client.request(:post, "/posts/#{post_id}/comments", params: { profile_id: profile_id }, json: json_body)
|
|
33
|
+
Comment.new(**result)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def delete(post_id, comment_id, profile_id:)
|
|
37
|
+
result = @client.request(:delete, "/posts/#{post_id}/comments/#{comment_id}", params: { profile_id: profile_id })
|
|
38
|
+
AcceptedResponse.new(**result)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def hide(post_id, comment_id, profile_id:)
|
|
42
|
+
result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/hide", params: { profile_id: profile_id })
|
|
43
|
+
AcceptedResponse.new(**result)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def unhide(post_id, comment_id, profile_id:)
|
|
47
|
+
result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/unhide", params: { profile_id: profile_id })
|
|
48
|
+
AcceptedResponse.new(**result)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def like(post_id, comment_id, profile_id:)
|
|
52
|
+
result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/like", params: { profile_id: profile_id })
|
|
53
|
+
AcceptedResponse.new(**result)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def unlike(post_id, comment_id, profile_id:)
|
|
57
|
+
result = @client.request(:post, "/posts/#{post_id}/comments/#{comment_id}/unlike", params: { profile_id: profile_id })
|
|
58
|
+
AcceptedResponse.new(**result)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/postproxy/types.rb
CHANGED
|
@@ -276,6 +276,42 @@ module PostProxy
|
|
|
276
276
|
end
|
|
277
277
|
end
|
|
278
278
|
|
|
279
|
+
class Comment < Model
|
|
280
|
+
attr_accessor :id, :external_id, :body, :status, :author_username,
|
|
281
|
+
:author_avatar_url, :author_external_id, :parent_external_id,
|
|
282
|
+
:like_count, :is_hidden, :permalink, :platform_data,
|
|
283
|
+
:posted_at, :created_at, :replies
|
|
284
|
+
|
|
285
|
+
def initialize(**attrs)
|
|
286
|
+
@external_id = nil
|
|
287
|
+
@author_avatar_url = nil
|
|
288
|
+
@author_external_id = nil
|
|
289
|
+
@parent_external_id = nil
|
|
290
|
+
@like_count = 0
|
|
291
|
+
@is_hidden = false
|
|
292
|
+
@permalink = nil
|
|
293
|
+
@platform_data = nil
|
|
294
|
+
@replies = []
|
|
295
|
+
super
|
|
296
|
+
@posted_at = parse_time(@posted_at)
|
|
297
|
+
@created_at = parse_time(@created_at)
|
|
298
|
+
@replies = (@replies || []).map do |r|
|
|
299
|
+
r.is_a?(Comment) ? r : Comment.new(**r.transform_keys(&:to_sym))
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
private
|
|
304
|
+
|
|
305
|
+
def parse_time(value)
|
|
306
|
+
return nil if value.nil?
|
|
307
|
+
value.is_a?(Time) ? value : Time.parse(value.to_s)
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
class AcceptedResponse < Model
|
|
312
|
+
attr_accessor :accepted
|
|
313
|
+
end
|
|
314
|
+
|
|
279
315
|
class DeleteResponse < Model
|
|
280
316
|
attr_accessor :deleted
|
|
281
317
|
end
|
data/lib/postproxy/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: postproxy-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- PostProxy
|
|
@@ -78,6 +78,7 @@ files:
|
|
|
78
78
|
- lib/postproxy/client.rb
|
|
79
79
|
- lib/postproxy/constants.rb
|
|
80
80
|
- lib/postproxy/errors.rb
|
|
81
|
+
- lib/postproxy/resources/comments.rb
|
|
81
82
|
- lib/postproxy/resources/posts.rb
|
|
82
83
|
- lib/postproxy/resources/profile_groups.rb
|
|
83
84
|
- lib/postproxy/resources/profiles.rb
|