snapchat_api 0.1.8 → 0.1.9

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: 68c01081685c51092fac5d51d23bfdd92783647f615454dba7b1ea42f2ce4796
4
- data.tar.gz: 36708edcfd4d108effdd48e17a99d7d7c010913b40f0651eb104bc54ea9a7f01
3
+ metadata.gz: 11163e5d9e5cfc8a292c23a4488c3fdde63f8e18731811798f56fbe510dddb37
4
+ data.tar.gz: '08f18ffb5bdf15fcf5eca32592b3433109668c1840a7ce4fe6dd51080c75f935'
5
5
  SHA512:
6
- metadata.gz: 4acabf2f1ddf87f1477bfdf509756cc5ae30623b4a9437ce157f8fee964a06916bb5d9f8e9bc9c6b8e9863f158052979dca9dcdd00b6b4d95ddcc23ac6aaae8a
7
- data.tar.gz: 0f8bdb643cb3a189890eac966912788f0cb7d4da19973f86a26d37798bc87f1382b66f3c127eea45c241d239e96c9fa773f0a16547a1c60477cabc10878c8a8e
6
+ metadata.gz: c5bd570f4f88237923574b48d482b04c02ad6de20b9fe0b4e27b3d948670acde41bc67be35818352bf77c3808bb3a05d4ae91fe2bdb33d6e3b155afde15c7fb3
7
+ data.tar.gz: 1086b6865f4200b90214faab067145ea182504622862478779fad366926908ddb689474527de7132002a41f212699e5da92979582f588f5f19ecd42d5adfd536
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.9](https://github.com/k0va1/snapchat_api/compare/v0.1.8...v0.1.9) (2026-07-27)
4
+
5
+
6
+ ### Features
7
+
8
+ * add chunked media upload for files larger than 32MB ([#16](https://github.com/k0va1/snapchat_api/issues/16)) ([854dcdb](https://github.com/k0va1/snapchat_api/commit/854dcdbc1e9f9ef8abc70166f20a264cdb5e586f))
9
+
3
10
  ## [0.1.8](https://github.com/k0va1/snapchat_api/compare/v0.1.7...v0.1.8) (2026-01-13)
4
11
 
5
12
 
@@ -4,6 +4,9 @@ require "mime/types"
4
4
  module SnapchatApi
5
5
  module Resources
6
6
  class Media < Base
7
+ CHUNKED_UPLOAD_THRESHOLD = 32_000_000
8
+ CHUNK_SIZE = 25 * 1024 * 1024
9
+
7
10
  def list_all(ad_account_id:, params: {})
8
11
  params[:limit] ||= 50
9
12
 
@@ -35,6 +38,8 @@ module SnapchatApi
35
38
  end
36
39
 
37
40
  def upload(media_id:, file_path:, params: {})
41
+ return upload_chunked(media_id: media_id, file_path: file_path, params: params) if File.size(file_path) > CHUNKED_UPLOAD_THRESHOLD
42
+
38
43
  mime_type = MIME::Types.type_for(file_path).first.content_type
39
44
 
40
45
  upload_params = {
@@ -45,6 +50,52 @@ module SnapchatApi
45
50
  response.body["result"]
46
51
  end
47
52
 
53
+ def upload_chunked(media_id:, file_path:, params: {})
54
+ mime_type = MIME::Types.type_for(file_path).first.content_type
55
+ file_name = File.basename(file_path)
56
+ file_size = File.size(file_path)
57
+ number_of_parts = (file_size.to_f / CHUNK_SIZE).ceil
58
+
59
+ init_response = client.request(
60
+ :post,
61
+ "media/#{media_id}/multipart-upload-v2?action=INIT",
62
+ {
63
+ file_name: file_name,
64
+ file_size: file_size.to_s,
65
+ number_of_parts: number_of_parts.to_s
66
+ },
67
+ {"Content-Type" => "multipart/form-data"}
68
+ )
69
+ upload_id = init_response.body["upload_id"]
70
+ add_path = init_response.body["add_path"]
71
+ finalize_path = init_response.body["finalize_path"]
72
+
73
+ File.open(file_path, "rb") do |file|
74
+ part_number = 1
75
+ while (chunk = file.read(CHUNK_SIZE))
76
+ client.request(
77
+ :post,
78
+ add_path,
79
+ {
80
+ file: Faraday::UploadIO.new(StringIO.new(chunk), mime_type, file_name),
81
+ part_number: part_number.to_s,
82
+ upload_id: upload_id
83
+ },
84
+ {"Content-Type" => "multipart/form-data"}
85
+ )
86
+ part_number += 1
87
+ end
88
+ end
89
+
90
+ response = client.request(
91
+ :post,
92
+ finalize_path,
93
+ {upload_id: upload_id, file_name: file_name},
94
+ {"Content-Type" => "multipart/form-data"}
95
+ )
96
+ response.body["result"]
97
+ end
98
+
48
99
  def preview(media_id:)
49
100
  response = client.request(:get, "media/#{media_id}/preview")
50
101
  response.body
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnapchatApi
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapchat_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Koval