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: dceb80b76ae8ca6044e919608765d26e0e76508672b9a2bfe5e3179d05a0a040
4
- data.tar.gz: 32da50a190e4ac98d30f88d5710ad2883a3bcf3eedc1a66d8e3e2bb96d20bcfa
3
+ metadata.gz: 439119f6aead2784171285a078b203445960b155c0fa0e08af5dcc686d3d6f4f
4
+ data.tar.gz: 71e386b92baaa07f8142d362952ac530e1485f60eb542031e2db79884d50d64f
5
5
  SHA512:
6
- metadata.gz: 931ed6f7546d1a477489b25d378c6b7c444ed6087c1323b2ad4c8fb27d47aca6d03d8ec0a287fc37e529c991c56c579c05c43b1efb7ee23cc0270f2c6c6bea84
7
- data.tar.gz: 7c063258a95a5e6c0f3339652d1823a5521f3b24f6e959eba5afaaf6e88d5e14f678dcf5af5d110db857b91bde991f13fa96964617828624c0037422f777cd5a
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
- mapper = SocialMiner::Instagram::ProfileMapper
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, cursor = SocialMiner::Instagram.profile_posts(user_id: "user_id") do |posts_attrs, cursor|
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]) do |posts_attrs, _|
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
- mapper = SocialMiner::Instagram::CommentMapper
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]) do |comments_attrs, _|
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
- posts, cursor = SocialMiner::Instagram.profile_posts(user_id: user_id, cursor: cursor) do |posts_attrs, cursor|
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(posts)
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
- { records: records, cursor: cursor }
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)
@@ -21,7 +21,7 @@ module SocialMiner
21
21
  if block_given?
22
22
  yield(record)
23
23
  else
24
- record
24
+ SocialMiner.mapper_for_klass(self.class).map(record)
25
25
  end
26
26
  else
27
27
  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
- { records: records, cursor: cursor }
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SocialMiner
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_miner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - null0vector