social_miner 0.1.0 → 0.1.1
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: 439119f6aead2784171285a078b203445960b155c0fa0e08af5dcc686d3d6f4f
|
4
|
+
data.tar.gz: 71e386b92baaa07f8142d362952ac530e1485f60eb542031e2db79884d50d64f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67bb6e4133c7c417a705cddf6805973d42aa17370059e75d721175e889fe75223341ab7561ac3ab96e9bb603dd77c67cd2e2dcd708016ac9a215133ceae7999f
|
7
|
+
data.tar.gz: 91744da0e64fd23b0ee9777eaf14db35d1e62baad4f3e3a141841b3e212a323085bcb5cc1d0269555b0bb45bace3b88cba845f8def17d1f1f34796a235d018ec
|
data/README.md
CHANGED
@@ -20,11 +20,7 @@ bundle install
|
|
20
20
|
Fetch user profile info:
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
|
24
|
-
|
25
|
-
result = SocialMiner::Instagram.profile_info(username: "instagram") do |profile_attrs|
|
26
|
-
mapper.map(profile_attrs)
|
27
|
-
end
|
23
|
+
result = SocialMiner::Instagram.profile_info(username: "instagram")
|
28
24
|
# Result contains:
|
29
25
|
# {
|
30
26
|
# social_id: "123456789",
|
@@ -41,14 +37,8 @@ end
|
|
41
37
|
To fetch a user's posts:
|
42
38
|
|
43
39
|
```ruby
|
44
|
-
mapper = SocialMiner::Instagram::PostMapper
|
45
40
|
# User ID can be obtained from the profile info (social_id field)
|
46
|
-
result
|
47
|
-
[
|
48
|
-
posts_attrs.map { |post_attrs| mapper.map(post_attrs) },
|
49
|
-
cursor
|
50
|
-
]
|
51
|
-
end
|
41
|
+
result = SocialMiner::Instagram.profile_posts(user_id: "user_id")
|
52
42
|
|
53
43
|
# Result contains:
|
54
44
|
# {
|
@@ -66,22 +56,13 @@ end
|
|
66
56
|
# }
|
67
57
|
|
68
58
|
# To fetch next page:
|
69
|
-
next_page = SocialMiner::Instagram.profile_posts(user_id: "user_id", cursor: result[:cursor])
|
70
|
-
...
|
71
|
-
end
|
59
|
+
next_page = SocialMiner::Instagram.profile_posts(user_id: "user_id", cursor: result[:cursor])
|
72
60
|
```
|
73
61
|
|
74
62
|
To fetch comments on a specific post:
|
75
63
|
|
76
64
|
```ruby
|
77
|
-
|
78
|
-
|
79
|
-
result, cursor = SocialMiner::Instagram.post_comments(post_shortcode: "ABC123") do |comments_attrs, cursor|
|
80
|
-
[
|
81
|
-
comments_attrs.map { |comment_attrs| mapper.map(comment_attrs) },
|
82
|
-
cursor
|
83
|
-
]
|
84
|
-
end
|
65
|
+
result = SocialMiner::Instagram.post_comments(post_shortcode: "ABC123")
|
85
66
|
|
86
67
|
# Result contains:
|
87
68
|
# {
|
@@ -96,9 +77,7 @@ end
|
|
96
77
|
# }
|
97
78
|
|
98
79
|
# To fetch next page of comments:
|
99
|
-
next_page = SocialMiner::Instagram.post_comments(post_shortcode: "ABC123", cursor: result[:cursor])
|
100
|
-
...
|
101
|
-
end
|
80
|
+
next_page = SocialMiner::Instagram.post_comments(post_shortcode: "ABC123", cursor: result[:cursor])
|
102
81
|
```
|
103
82
|
|
104
83
|
# Custom Headers
|
@@ -135,20 +114,13 @@ end
|
|
135
114
|
|
136
115
|
```ruby
|
137
116
|
class BackgroundJob
|
138
|
-
@@mapper = SocialMiner::Instagram::PostMapper
|
139
|
-
|
140
117
|
def perform(user_id, cursor: nil)
|
141
|
-
|
142
|
-
[
|
143
|
-
posts_attrs.map { |post_attrs| @@mapper.map(post_attrs) },
|
144
|
-
cursor
|
145
|
-
]
|
146
|
-
end
|
118
|
+
result = SocialMiner::Instagram.profile_posts(user_id: user_id, cursor: cursor)
|
147
119
|
|
148
120
|
# Bulk import to DB
|
149
|
-
Post.import(
|
121
|
+
Post.import(result[:records])
|
150
122
|
|
151
|
-
perform_async(user_id, cursor) unless cursor.nil?
|
123
|
+
perform_async(user_id, result[:cursor]) unless result[:cursor].nil?
|
152
124
|
end
|
153
125
|
end
|
154
126
|
```
|
@@ -34,7 +34,10 @@ module SocialMiner
|
|
34
34
|
if block_given?
|
35
35
|
yield(records, cursor)
|
36
36
|
else
|
37
|
-
{
|
37
|
+
{
|
38
|
+
records: records.map { |record| SocialMiner.mapper_for_klass(self.class).map(record) },
|
39
|
+
cursor: cursor
|
40
|
+
}
|
38
41
|
end
|
39
42
|
else
|
40
43
|
raise Net::HTTPError.new("Request Failed #{response.code}", response)
|
@@ -33,7 +33,10 @@ module SocialMiner
|
|
33
33
|
if block_given?
|
34
34
|
yield(records, cursor)
|
35
35
|
else
|
36
|
-
{
|
36
|
+
{
|
37
|
+
records: records.map { |record| SocialMiner.mapper_for_klass(self.class).map(record) },
|
38
|
+
cursor: cursor
|
39
|
+
}
|
37
40
|
end
|
38
41
|
else
|
39
42
|
raise Net::HTTPError.new("Request Failed #{response.code}", response)
|
data/lib/social_miner/version.rb
CHANGED
data/lib/social_miner.rb
CHANGED
@@ -13,6 +13,18 @@ require_relative "social_miner/instagram/post_comments"
|
|
13
13
|
require_relative "social_miner/instagram/comment_mapper"
|
14
14
|
|
15
15
|
module SocialMiner
|
16
|
+
DEFAULT_MAPPERS = {
|
17
|
+
Instagram::ProfileInfo => Instagram::ProfileMapper,
|
18
|
+
Instagram::ProfilePosts => Instagram::PostMapper,
|
19
|
+
Instagram::PostComments => Instagram::CommentMapper
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
def mapper_for_klass(key)
|
23
|
+
DEFAULT_MAPPERS.fetch(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
module_function :mapper_for_klass
|
27
|
+
|
16
28
|
def Instagram.profile_info(request_headers = {}, **args, &)
|
17
29
|
Instagram::ProfileInfo.new(request_headers).call(**args, &)
|
18
30
|
end
|