postproxy-sdk 1.4.1 → 1.5.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: 86174e66ca792b05a9f36bff9b881c65c3fdaaeb360e8a4fb49e94014d984839
4
+ data.tar.gz: ebe347a97de89a5af6697087252156b044a26f5c8eae11c3e2129c4594a6cb46
5
5
  SHA512:
6
- metadata.gz: 580704f8585988b149e298ad924865d7a6bf7004709af8babb0761e898d6748ac907dcbe428042049d2951f61dd25de103f28edb57b966fa5b7a70c1394fffb9
7
- data.tar.gz: 9d259eeab2ff02ddb7af93d1c62eb8950469d18ecbb01d42321d8d158f20299bb4447da88a1200b933f993bad119693ac98a522980fdd5cb3335f4c29935e2f8
6
+ metadata.gz: 73dc2f50e0d720cd4048b23db241a17ea81cec2010bb06ae0f6a42a4edbb4d26f2b074be9e3a71ac4e24b9d09fa31651365727aefd88346e416284de4a4a6424
7
+ data.tar.gz: ae13c32ba3db5b1bb1e07bfd3ae63cc7d977215a834e1b4ce42b3298a3e6e790240b5a6dc251c41561489238cdbfdbab816ef22f221dc7ab3886db7e3f837669
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module PostProxy
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PostProxy