Module: Actions
- Included in:
- ClassMethods
- Defined in:
- lib/botinsta/actions.rb
Overview
Various actions you can do on Instagram and other related methods.
Instance Method Summary collapse
-
#follow_if_not_in_db(user) ⇒ true, false
Follows the user if it doesn’t exist in the database.
-
#follow_user(user_id) ⇒ true, false
Follows user given by user_id.
-
#like_if_not_in_db(media) ⇒ true, false
Likes the media if it doesn’t exist in the database.
-
#like_media(media_id) ⇒ true, false
Likes media given by media id.
-
#unfollow_user(user_id) ⇒ true, false
Unfollows user given by user_id.
-
#unlike_media(media_id) ⇒ true, false
Unlikes media given by media id.
Instance Method Details
#follow_if_not_in_db(user) ⇒ true, false
Follows the user if it doesn’t exist in the database.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/botinsta/actions.rb', line 95 def follow_if_not_in_db(user) return false if user.exists_in_db?(@table_follows) if follow_user(user.id) @total_follows += 1 (action: :follow, number: @total_follows, data: @user.username) user.insert_into_db(@table_follows) sleep_rand(28, 36) true else false end end |
#follow_user(user_id) ⇒ true, false
Follows user given by user_id.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/botinsta/actions.rb', line 43 def follow_user(user_id) url_follow = "https://www.instagram.com/web/friendships/#{user_id}/follow/" (action: :follow, data: user_id) begin set_request_params response = @agent.post url_follow, @params, @request_headers rescue Mechanize::ResponseCodeError return false end response_data = JSON.parse(response.body) response.code == '200' && response_data['result'] == 'following' ? true : false end |
#like_if_not_in_db(media) ⇒ true, false
Likes the media if it doesn’t exist in the database.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/botinsta/actions.rb', line 77 def like_if_not_in_db(media) return false if media.exists_in_db?(@table_likes) if like_media(media.id) @total_likes += 1 (action: :like, number: @total_likes, data: @media.id) media.insert_into_db(@table_likes) sleep_rand(28, 36) true else false end end |
#like_media(media_id) ⇒ true, false
Likes media given by media id.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/botinsta/actions.rb', line 9 def like_media(media_id) url_like = "https://www.instagram.com/web/likes/#{media_id}/like/" (action: :like, data: media_id) begin set_request_params response = @agent.post url_like, @params, @request_headers rescue Mechanize::ResponseCodeError return false end response_data = JSON.parse(response.body) response.code == '200' && response_data['status'] == 'ok' ? true : false end |
#unfollow_user(user_id) ⇒ true, false
Unfollows user given by user_id.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/botinsta/actions.rb', line 60 def unfollow_user(user_id) url_unfollow = "https://www.instagram.com/web/friendships/#{user_id}/unfollow/" (action: :unfollow, data: user_id) begin set_request_params response = @agent.post url_unfollow, @params, @request_headers rescue Mechanize::ResponseCodeError return false end response_data = JSON.parse(response.body) response.code == '200' && response_data['status'] == 'ok' ? true : false end |
#unlike_media(media_id) ⇒ true, false
Unlikes media given by media id.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/botinsta/actions.rb', line 26 def unlike_media(media_id) url_unlike = "https://www.instagram.com/web/likes/#{media_id}/unlike/" (action: :unlike, data: media_id) begin set_request_params response = @agent.post url_unlike, @params, @request_headers rescue Mechanize::ResponseCodeError return false end response_data = JSON.parse(response.body) response.code == '200' && response_data['status'] == 'ok' ? true : false end |