fbwish 1.0.2 → 1.0.3

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.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +13 -3
  3. data/lib/fbwish.rb +46 -15
  4. data/lib/fbwish/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmRhNzNhMmZhOGU2MWFhZjM2YjliNDI5N2NkMmMxY2MxNTE3NTNlOA==
4
+ MzA4YmZiOGQxYjQ4ODcxMjMzZjgwZThlNjliNTRjNDBhNjFiOWEyNA==
5
5
  data.tar.gz: !binary |-
6
- ZTI2Y2UzYmRiNjE3NmZiMjg2ODljZGJmZjE0OTNhZTZlMzBjYzE4ZQ==
6
+ NTVhMDA2NTkxMTIyOTNkY2I5ODdmYjZmNmQ1ODljMmM5MDc4ZDcyZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDI3MTlhNzI2MzNjYjQ0OTgxNDNlNTMwMjJmMzVjZjM2MDUwNjJmOTIzNDE1
10
- MTdmZmQ2Y2M1OWNlZDcyYmYwOTlkMThmYTI2ZTEwMThlZmNmODEyMjM0ZmNj
11
- MWFjYTFiYTg4NzVmZjQ5ODAxZmU2ZWExYjBlYzQ2MzIxOGNmYjI=
9
+ YjZmNDA5MTFhZjUxMzQ1YTkyODM0YzlmNmNmNWVlMTY0MDRkODk0Zjg1Nzg3
10
+ NWE0YmU2ZjVhMzYzYjZmNzUxOGZlYjM4OTVhMGU1ZGFlY2IyOTA1YzNkYWUx
11
+ Y2FmZDkxOGExNmI1NTZkNjJiYTU0ODJkYjgwYzRiNTExNTBlMTM=
12
12
  data.tar.gz: !binary |-
13
- NTYwOWEyZDljNmY3YTA4MWMzNjk4ZDUzNDMyYmQ4OGIwOTBhZmY5ZjZjMzQ5
14
- YjA1OWE2Y2ZkZDYyMmFkNGZjOWVlZDU2ZmNkZmVlMGE3YTcwODE2MWU1OTQ0
15
- NzY2ZjYyNTVlOTJhMjU1NTZlOTI2YjcwM2ExOWNkNzcyOWRlMzY=
13
+ OGUyNWNiMDc2ZjI0MWI2MjRhOGE1ZmRlOTg3MDNjZDQyZGYwNWYzZWI5NGE2
14
+ ZmQ3NWQ2MDY0MjUxODg2ZjY5N2M1OTUzMGIwMTM3OGYyOTY1ZmRlYjFlNmY5
15
+ ZjFjNDRhZDViMTI5NDVjOGIyYzkwOGYyOTNmZTkzNDhhYWIyYzM=
data/README.md CHANGED
@@ -4,7 +4,7 @@ Ruby Gem to automate facebook like & comment on the birthday wishes using Gr
4
4
 
5
5
  If you have alot of friends in your facebook network & when they wish you on your birthday, it's pretty cumbersome to reply to each one of them. This gem helps you in automating your replies by liking & commenting on those wishes using facebook's graph API (powered by ruby gem [koala](https://github.com/arsduo/koala)).
6
6
 
7
- ## Installation
7
+ ## Installation (Make sure you have [Ruby](https://www.ruby-lang.org/en/installation/) installed)
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
@@ -30,6 +30,11 @@ Getting your facebook access token
30
30
  6. Copy the generated access token.
31
31
 
32
32
  #### Final step
33
+ Open ruby's interactive terminal using the following command
34
+
35
+ $ irb
36
+
37
+ Once you are into the terminal run the following commands, with appropriate configuration
33
38
  ```ruby
34
39
  require('fbwish')
35
40
  wisher = Fbwish::Wisher.new({
@@ -40,7 +45,10 @@ wisher = Fbwish::Wisher.new({
40
45
  access_token: "PASTE YOUR ACCESS TOKEN HERE",
41
46
  # Number of people who wished you on your birthday, you'll know this
42
47
  # on your timeline when facebook says "foo, bar & 254 others wished you"
43
- wish_count: 256
48
+ wish_count: 256,
49
+ # Optional attribute, false by default.
50
+ # If true, it logs the replies
51
+ verbose: true
44
52
  })
45
53
  wisher.wish_em_all! # Sit back & relax ;-)
46
54
  ```
@@ -62,8 +70,10 @@ wisher = Fbwish::Wisher.new({
62
70
  tam: ["நன்றி !!! :D"]
63
71
  },
64
72
  access_token: "PASTE YOUR ACCESS TOKEN HERE",
65
- wish_count: 256
73
+ wish_count: 256,
74
+ verbose: true
66
75
  })
76
+ wisher.wish_em_all!
67
77
  ```
68
78
 
69
79
  ## Contributing
data/lib/fbwish.rb CHANGED
@@ -4,7 +4,7 @@ require "koala"
4
4
  module Fbwish
5
5
  class Wisher
6
6
 
7
- attr_accessor :graph, :matcher, :replies, :wish_count
7
+ attr_accessor :graph, :matcher, :replies, :wish_count, :verbose
8
8
 
9
9
  def initialize(options={})
10
10
  required_options = [:access_token, :matcher, :replies, :wish_count]
@@ -18,6 +18,7 @@ module Fbwish
18
18
  self.matcher = options[:matcher]
19
19
  self.replies = options[:replies]
20
20
  self.wish_count = options[:wish_count]
21
+ self.verbose = options[:verbose] || false
21
22
  end
22
23
 
23
24
  def wish_em_all!
@@ -33,7 +34,38 @@ module Fbwish
33
34
  end
34
35
  end
35
36
 
37
+ def should_log?
38
+ verbose
39
+ end
40
+
36
41
  private
42
+ def like_and_comment(wish)
43
+ did_reply = false
44
+
45
+ if matcher.is_a?(Hash)
46
+ matcher.each do |locale, regex|
47
+ did_reply = reply_if_match_found(regex, wish, replies[locale])
48
+ break if did_reply
49
+ end
50
+ else
51
+ reply_if_match_found(matcher, wish, replies)
52
+ end
53
+ end
54
+
55
+ def reply_if_match_found(regex, wish, replies)
56
+ if regex.match(wish['message'])
57
+ like(wish)
58
+ my_reply = comment(wish, replies)
59
+ log_result(wish, my_reply) if should_log?
60
+
61
+ true
62
+ else
63
+ log_failure(wish) if should_log?
64
+
65
+ false
66
+ end
67
+ end
68
+
37
69
  def like(wish)
38
70
  graph.put_like(wish['id'])
39
71
  end
@@ -43,23 +75,22 @@ module Fbwish
43
75
  reply = replies.is_a?(Array) ?
44
76
  replies[rand(replies.length-1)] :
45
77
  replies
78
+ reply += " #{wisher(wish)}"
46
79
  graph.put_comment(wish['id'], reply)
80
+
81
+ return reply
47
82
  end
48
83
 
49
- def like_and_comment(wish)
50
- if matcher.is_a?(Hash)
51
- matcher.each do |locale, regex|
52
- if regex.match(wish['message'])
53
- like(wish)
54
- comment(wish, replies[locale])
55
- end
56
- end
57
- else
58
- if matcher.match(wish['message'])
59
- like(wish)
60
- comment(wish, replies)
61
- end
62
- end
84
+ def wisher(wish)
85
+ wish['from']['name']
86
+ end
87
+
88
+ def log_result(wish, reply)
89
+ puts "Liked & replied '#{reply}' to '#{wisher(wish)}'"
90
+ end
91
+
92
+ def log_failure(wish)
93
+ puts "#{wisher(wish)}'s wish '#{wish["message"]}' did not match the pattern, Hence ignored."
63
94
  end
64
95
  end
65
96
  end
@@ -1,3 +1,3 @@
1
1
  module Fbwish
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbwish
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mudassir Ali