scrape_creators 0.2.0 → 0.3.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 +1 -1
- data/lib/scrape_creators/client.rb +48 -6
- data/lib/scrape_creators/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d1b0ec47242c7f1e3f0d551233d27f9e11be3874cc3b78a78181eaa40a21b84f
|
|
4
|
+
data.tar.gz: 5a8827a29aa9b0ae06a890bc979d9e52e8a9f94ba2b717d38ebb305b7459fcad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '08f33db279a55d7b432d7cc29c0b7b1ebec5b8d5938bab8c00e13484871f4fcdfe7bba2989146f0253e4c3cfe1dc86dc8110ba732cfd05ac6a0e2b08184c9108'
|
|
7
|
+
data.tar.gz: 92519f692c9d01b014c933f3a333a5494ebc86f0cc3ad0c98247b6799cb2d457220304cd11f71c7f8df3c5f277ee1ea66aaf75f05a025a27e080640ada04378e
|
data/README.md
CHANGED
|
@@ -8,6 +8,9 @@ require 'stringio'
|
|
|
8
8
|
|
|
9
9
|
module ScrapeCreators
|
|
10
10
|
class Client
|
|
11
|
+
TIKTOK = 'tiktok'
|
|
12
|
+
INSTAGRAM = 'instagram'
|
|
13
|
+
|
|
11
14
|
attr_reader :config, :api_key
|
|
12
15
|
|
|
13
16
|
def initialize(config = nil, api_key: nil)
|
|
@@ -15,22 +18,61 @@ module ScrapeCreators
|
|
|
15
18
|
@api_key = api_key || @config.api_key
|
|
16
19
|
end
|
|
17
20
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
def posts_url_for(source:)
|
|
22
|
+
case source
|
|
23
|
+
when TIKTOK then '/v3/tiktok/profile/videos'
|
|
24
|
+
when INSTAGRAM then '/v2/instagram/user/posts'
|
|
25
|
+
else '/404'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def post_url_for(source:)
|
|
30
|
+
case source
|
|
31
|
+
when TIKTOK then '/v2/tiktok/video'
|
|
32
|
+
when INSTAGRAM then '/v1/instagram/post'
|
|
33
|
+
else '/404'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def comments_url_for(source:)
|
|
38
|
+
case source
|
|
39
|
+
when TIKTOK then '/v1/tiktok/video/comments'
|
|
40
|
+
when INSTAGRAM then '/v2/instagram/post/comments'
|
|
41
|
+
else '/404'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def posts_key_for(source:)
|
|
46
|
+
case source
|
|
47
|
+
when TIKTOK then 'aweme_list'
|
|
48
|
+
when INSTAGRAM then 'items'
|
|
49
|
+
else 'items'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def posts(handle, options = {})
|
|
54
|
+
params = { handle: }.merge(options)
|
|
55
|
+
source = options.dig(:source) || 'instagram'
|
|
56
|
+
posts_url = posts_url_for(source:)
|
|
57
|
+
res = get(posts_url, params)
|
|
58
|
+
key = posts_key_for(source:)
|
|
59
|
+
res.is_a?(Hash) ? (res[key] || []) : []
|
|
22
60
|
end
|
|
23
61
|
|
|
24
62
|
def post(url_or_code, options = {})
|
|
25
63
|
url = normalize_url(url_or_code)
|
|
64
|
+
source = options.dig(:source) || 'instagram'
|
|
65
|
+
post_url = post_url_for(source:)
|
|
26
66
|
params = { url: url }.merge(options)
|
|
27
|
-
get(
|
|
67
|
+
get(post_url, params)
|
|
28
68
|
end
|
|
29
69
|
|
|
30
70
|
def comments(url_or_code, options = {})
|
|
31
71
|
url = normalize_url(url_or_code)
|
|
32
72
|
params = { url: url }.merge(options)
|
|
33
|
-
|
|
73
|
+
source = options.dig(:source) || 'instagram'
|
|
74
|
+
comments_url = comments_url_for(source:)
|
|
75
|
+
res = get(comments_url, params)
|
|
34
76
|
res.is_a?(Hash) ? (res["comments"] || []) : []
|
|
35
77
|
end
|
|
36
78
|
|