scrape_creators 0.2.0 → 0.4.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: 41069945ebf877cbd439c8bfbb318ba0114d4e9df6275aabacef16867417a7b4
4
+ data.tar.gz: 24d8743a67a698cfc97f974015a8ff30ab33254b8dd155e96f1d4b0283e9d9c0
5
5
  SHA512:
6
- metadata.gz: 4b6b91b051d9fcf2b2ed6dd098b8f29a67a4d080c9504c30da4b9e7e0f93bc2115630d678298747b7cd353392c181ed7cdd58157771553d9429ebe251fadea8a
7
- data.tar.gz: 105430857e70bdb5a7fed51b248e756e23b8e488e07db604802c68ddf1bc6f795adbd5f78d06001634fa9d5e63fc24f6391a226eb8e505792cfcaa820262dbcd
6
+ metadata.gz: fdab6ab8877d97093743a3e52d3daa17bf33ac1c4b3a461b6ea85957e83bff213b9e27adbaa878b36e9af15858f014334aceda898beae6cb9d498d15e56e2d1f
7
+ data.tar.gz: ddeaf8dc9f781648485b348a3ccaeb660a2dfe47a611e37a6c0cd9283fae66179a91521c11be731faf698b8cf22683cf5a8b8b3862b198d1c148f20641011bda
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,10 @@ require 'stringio'
8
8
 
9
9
  module ScrapeCreators
10
10
  class Client
11
+ TIKTOK = 'tiktok'
12
+ INSTAGRAM = 'instagram'
13
+ YOUTUBE = 'youtube'
14
+
11
15
  attr_reader :config, :api_key
12
16
 
13
17
  def initialize(config = nil, api_key: nil)
@@ -15,22 +19,65 @@ module ScrapeCreators
15
19
  @api_key = api_key || @config.api_key
16
20
  end
17
21
 
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"] || []) : []
22
+ def posts_url_for(source:)
23
+ case source.to_s
24
+ when TIKTOK then '/v3/tiktok/profile/videos'
25
+ when INSTAGRAM then '/v2/instagram/user/posts'
26
+ when YOUTUBE then '/v1/youtube/channel/shorts'
27
+ else '/404'
28
+ end
29
+ end
30
+
31
+ def post_url_for(source:)
32
+ case source.to_s
33
+ when TIKTOK then '/v2/tiktok/video'
34
+ when INSTAGRAM then '/v1/instagram/post'
35
+ when YOUTUBE then '/v1/youtube/video'
36
+ else '/404'
37
+ end
38
+ end
39
+
40
+ def comments_url_for(source:)
41
+ case source.to_s
42
+ when TIKTOK then '/v1/tiktok/video/comments'
43
+ when INSTAGRAM then '/v2/instagram/post/comments'
44
+ when YOUTUBE then '/v1/youtube/video/comments'
45
+ else '/404'
46
+ end
47
+ end
48
+
49
+ def posts_key_for(source:)
50
+ case source.to_s
51
+ when TIKTOK then 'aweme_list'
52
+ when INSTAGRAM then 'items'
53
+ when YOUTUBE then 'shorts'
54
+ else 'items'
55
+ end
56
+ end
57
+
58
+ def posts(handle, options = {})
59
+ source = (options[:source] || 'instagram').to_s
60
+ params = { handle: handle }.merge(options.reject { |k, _| k.to_s == 'source' })
61
+ posts_url = posts_url_for(source: source)
62
+ res = get(posts_url, params)
63
+ key = posts_key_for(source: source)
64
+ res.is_a?(Hash) ? (res[key] || []) : []
22
65
  end
23
66
 
24
67
  def post(url_or_code, options = {})
68
+ source = (options[:source] || 'instagram').to_s
25
69
  url = normalize_url(url_or_code)
26
- params = { url: url }.merge(options)
27
- get("/v1/instagram/post", params)
70
+ post_url = post_url_for(source: source)
71
+ params = { url: url }.merge(options.reject { |k, _| k.to_s == 'source' })
72
+ get(post_url, params)
28
73
  end
29
74
 
30
75
  def comments(url_or_code, options = {})
76
+ source = (options[:source] || 'instagram').to_s
31
77
  url = normalize_url(url_or_code)
32
- params = { url: url }.merge(options)
33
- res = get("/v2/instagram/post/comments", params)
78
+ params = { url: url }.merge(options.reject { |k, _| k.to_s == 'source' })
79
+ comments_url = comments_url_for(source: source)
80
+ res = get(comments_url, params)
34
81
  res.is_a?(Hash) ? (res["comments"] || []) : []
35
82
  end
36
83
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScrapeCreators
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.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.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - swlkr