postproxy-sdk 1.4.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 220a9066d8453acb2430cf48d76d634e8ac69a62a244bedb28a8d1e00a4f5232
4
- data.tar.gz: c5b68356a893d52101198f827d55e31f2931629d170b152b1a038a02f9151350
3
+ metadata.gz: e62e2ba2b3d951aed31a2d60d74a7ee4a46672b03131676f28d81f6dc5cade69
4
+ data.tar.gz: 83bf66f3dae825b04195d1ec9e809849352f4c290dbf2d1458879a1838688e93
5
5
  SHA512:
6
- metadata.gz: 580704f8585988b149e298ad924865d7a6bf7004709af8babb0761e898d6748ac907dcbe428042049d2951f61dd25de103f28edb57b966fa5b7a70c1394fffb9
7
- data.tar.gz: 9d259eeab2ff02ddb7af93d1c62eb8950469d18ecbb01d42321d8d158f20299bb4447da88a1200b933f993bad119693ac98a522980fdd5cb3335f4c29935e2f8
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
@@ -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
@@ -105,6 +105,88 @@ module PostProxy
105
105
  Post.new(**result)
106
106
  end
107
107
 
108
+ def update(id, body: nil, profiles: nil, media: nil, media_files: nil, platforms: nil,
109
+ thread: nil, scheduled_at: nil, draft: nil, queue_id: nil,
110
+ queue_priority: nil, profile_group_id: nil)
111
+ has_files = media_files && !media_files.empty?
112
+ has_thread_files = thread&.any? { |t| t[:media_files]&.any? }
113
+
114
+ if has_files || has_thread_files
115
+ form_data = {}
116
+ form_data["post[body]"] = body if body
117
+ form_data["post[scheduled_at]"] = format_time(scheduled_at) if scheduled_at
118
+ form_data["post[draft]"] = draft.to_s if !draft.nil?
119
+
120
+ files = []
121
+
122
+ profiles&.each do |p|
123
+ files << ["profiles[]", nil, p, "text/plain"]
124
+ end
125
+
126
+ media&.each do |m|
127
+ files << ["media[]", nil, m, "text/plain"]
128
+ end
129
+
130
+ if platforms
131
+ params_hash = platforms.is_a?(PlatformParams) ? platforms.to_h : platforms
132
+ params_hash.each do |platform, platform_params|
133
+ platform_params.each do |key, value|
134
+ files << ["platforms[#{platform}][#{key}]", nil, value.to_s, "text/plain"]
135
+ end
136
+ end
137
+ end
138
+
139
+ media_files&.each do |path|
140
+ path = path.to_s
141
+ filename = File.basename(path)
142
+ content_type = mime_type_for(filename)
143
+ io = File.open(path, "rb")
144
+ files << ["media[]", filename, io, content_type]
145
+ end
146
+
147
+ thread&.each_with_index do |t, i|
148
+ form_data["thread[#{i}][body]"] = t[:body] if t[:body]
149
+
150
+ t[:media]&.each do |m|
151
+ files << ["thread[#{i}][media][]", nil, m, "text/plain"]
152
+ end
153
+
154
+ t[:media_files]&.each do |path|
155
+ path = path.to_s
156
+ filename = File.basename(path)
157
+ content_type = mime_type_for(filename)
158
+ io = File.open(path, "rb")
159
+ files << ["thread[#{i}][media][]", filename, io, content_type]
160
+ end
161
+ end
162
+
163
+ result = @client.request(:patch, "/posts/#{id}",
164
+ data: form_data,
165
+ files: files,
166
+ profile_group_id: profile_group_id
167
+ )
168
+ else
169
+ json_body = {}
170
+
171
+ post_payload = {}
172
+ post_payload[:body] = body if body
173
+ post_payload[:scheduled_at] = format_time(scheduled_at) if scheduled_at
174
+ post_payload[:draft] = draft unless draft.nil?
175
+ json_body[:post] = post_payload unless post_payload.empty?
176
+
177
+ json_body[:profiles] = profiles if profiles
178
+ json_body[:platforms] = platforms.is_a?(PlatformParams) ? platforms.to_h : platforms if platforms
179
+ json_body[:media] = media if media
180
+ json_body[:thread] = thread if thread
181
+ json_body[:queue_id] = queue_id if queue_id
182
+ json_body[:queue_priority] = queue_priority if queue_priority
183
+
184
+ result = @client.request(:patch, "/posts/#{id}", json: json_body, profile_group_id: profile_group_id)
185
+ end
186
+
187
+ Post.new(**result)
188
+ end
189
+
108
190
  def publish_draft(id, profile_group_id: nil)
109
191
  result = @client.request(:post, "/posts/#{id}/publish", profile_group_id: profile_group_id)
110
192
  Post.new(**result)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module PostProxy
2
- VERSION = "1.4.1"
2
+ VERSION = "1.6.0"
3
3
  end
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.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