snapchat_api 0.1.7 → 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11163e5d9e5cfc8a292c23a4488c3fdde63f8e18731811798f56fbe510dddb37
|
|
4
|
+
data.tar.gz: '08f18ffb5bdf15fcf5eca32592b3433109668c1840a7ce4fe6dd51080c75f935'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5bd570f4f88237923574b48d482b04c02ad6de20b9fe0b4e27b3d948670acde41bc67be35818352bf77c3808bb3a05d4ae91fe2bdb33d6e3b155afde15c7fb3
|
|
7
|
+
data.tar.gz: 1086b6865f4200b90214faab067145ea182504622862478779fad366926908ddb689474527de7132002a41f212699e5da92979582f588f5f19ecd42d5adfd536
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
|
|
10
|
+
## [0.1.8](https://github.com/k0va1/snapchat_api/compare/v0.1.7...v0.1.8) (2026-01-13)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add funding sources api ([#15](https://github.com/k0va1/snapchat_api/issues/15)) ([1974240](https://github.com/k0va1/snapchat_api/commit/19742401dd77f4209cccf1be3a0c1cb5e8397ba0))
|
|
16
|
+
* add organizations ([#13](https://github.com/k0va1/snapchat_api/issues/13)) ([920bcc0](https://github.com/k0va1/snapchat_api/commit/920bcc08baee865da03cd174d4937a3dab35a6f0))
|
|
17
|
+
|
|
3
18
|
## [0.1.7](https://github.com/k0va1/snapchat_api/compare/v0.1.6...v0.1.7) (2026-01-13)
|
|
4
19
|
|
|
5
20
|
|
data/lib/snapchat_api/client.rb
CHANGED
|
@@ -132,6 +132,14 @@ module SnapchatApi
|
|
|
132
132
|
@ads ||= SnapchatApi::Resources::Ad.new(self)
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
+
def organizations
|
|
136
|
+
@organizations ||= SnapchatApi::Resources::Organization.new(self)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def funding_sources
|
|
140
|
+
@funding_sources ||= SnapchatApi::Resources::FundingSource.new(self)
|
|
141
|
+
end
|
|
142
|
+
|
|
135
143
|
private
|
|
136
144
|
|
|
137
145
|
def handle_response(response)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module SnapchatApi
|
|
2
|
+
module Resources
|
|
3
|
+
class FundingSource < Base
|
|
4
|
+
def list_all(organization_id:, params: {})
|
|
5
|
+
params[:limit] ||= 50
|
|
6
|
+
|
|
7
|
+
funding_sources = []
|
|
8
|
+
query = URI.encode_www_form(params.compact)
|
|
9
|
+
next_link = "organizations/#{organization_id}/fundingsources?#{query}"
|
|
10
|
+
|
|
11
|
+
loop do
|
|
12
|
+
response = client.request(:get, next_link)
|
|
13
|
+
next_link = response.body.dig("paging", "next_link")
|
|
14
|
+
funding_sources.concat(response.body["fundingsources"].map { |el| el["fundingsource"] })
|
|
15
|
+
break if next_link.nil?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
funding_sources
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get(funding_source_id:)
|
|
22
|
+
response = client.request(:get, "fundingsources/#{funding_source_id}")
|
|
23
|
+
response.body["fundingsources"].first["fundingsource"]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -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
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module SnapchatApi
|
|
2
|
+
module Resources
|
|
3
|
+
class Organization < Base
|
|
4
|
+
def list_all(params: {})
|
|
5
|
+
params[:limit] ||= 50
|
|
6
|
+
|
|
7
|
+
organizations = []
|
|
8
|
+
query = URI.encode_www_form(params.compact)
|
|
9
|
+
next_link = "me/organizations?#{query}"
|
|
10
|
+
|
|
11
|
+
loop do
|
|
12
|
+
response = client.request(:get, next_link)
|
|
13
|
+
next_link = response.body.dig("paging", "next_link")
|
|
14
|
+
organizations.concat(response.body["organizations"].map { |el| el["organization"] })
|
|
15
|
+
break if next_link.nil?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
organizations
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get(organization_id:)
|
|
22
|
+
response = client.request(:get, "organizations/#{organization_id}")
|
|
23
|
+
response.body["organizations"].first["organization"]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/snapchat_api/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.1.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex Koval
|
|
@@ -212,7 +212,9 @@ files:
|
|
|
212
212
|
- lib/snapchat_api/resources/base.rb
|
|
213
213
|
- lib/snapchat_api/resources/campaign.rb
|
|
214
214
|
- lib/snapchat_api/resources/creative.rb
|
|
215
|
+
- lib/snapchat_api/resources/funding_source.rb
|
|
215
216
|
- lib/snapchat_api/resources/media.rb
|
|
217
|
+
- lib/snapchat_api/resources/organization.rb
|
|
216
218
|
- lib/snapchat_api/version.rb
|
|
217
219
|
homepage: https://github.com/k0va1/snapchat_api
|
|
218
220
|
licenses: []
|