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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 642a24871da7edc12eaaa1f788987515f0d20555ab3ea5063d5fc7bc18246d3a
4
- data.tar.gz: 2975767ca1c23bf2180198b20149846338d91f3a88e4d7a9a787858dfc9e8f49
3
+ metadata.gz: d1b0ec47242c7f1e3f0d551233d27f9e11be3874cc3b78a78181eaa40a21b84f
4
+ data.tar.gz: 5a8827a29aa9b0ae06a890bc979d9e52e8a9f94ba2b717d38ebb305b7459fcad
5
5
  SHA512:
6
- metadata.gz: 4b6b91b051d9fcf2b2ed6dd098b8f29a67a4d080c9504c30da4b9e7e0f93bc2115630d678298747b7cd353392c181ed7cdd58157771553d9429ebe251fadea8a
7
- data.tar.gz: 105430857e70bdb5a7fed51b248e756e23b8e488e07db604802c68ddf1bc6f795adbd5f78d06001634fa9d5e63fc24f6391a226eb8e505792cfcaa820262dbcd
6
+ metadata.gz: '08f33db279a55d7b432d7cc29c0b7b1ebec5b8d5938bab8c00e13484871f4fcdfe7bba2989146f0253e4c3cfe1dc86dc8110ba732cfd05ac6a0e2b08184c9108'
7
+ data.tar.gz: 92519f692c9d01b014c933f3a333a5494ebc86f0cc3ad0c98247b6799cb2d457220304cd11f71c7f8df3c5f277ee1ea66aaf75f05a025a27e080640ada04378e
data/README.md CHANGED
@@ -7,7 +7,7 @@ A zero-dependency Ruby client for the [Scrape Creators API](https://docs.scrapec
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'scrape_creators', '0.1.0'
10
+ gem 'scrape_creators', '0.2.0'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -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 posts(username_or_handle, options = {})
19
- params = { handle: username_or_handle }.merge(options)
20
- res = get("/v2/instagram/user/posts", params)
21
- res.is_a?(Hash) ? (res["items"] || []) : []
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("/v1/instagram/post", params)
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
- res = get("/v2/instagram/post/comments", params)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScrapeCreators
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrape_creators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - swlkr