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.
- checksums.yaml +8 -8
- data/README.md +13 -3
- data/lib/fbwish.rb +46 -15
- data/lib/fbwish/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzA4YmZiOGQxYjQ4ODcxMjMzZjgwZThlNjliNTRjNDBhNjFiOWEyNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTVhMDA2NTkxMTIyOTNkY2I5ODdmYjZmNmQ1ODljMmM5MDc4ZDcyZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjZmNDA5MTFhZjUxMzQ1YTkyODM0YzlmNmNmNWVlMTY0MDRkODk0Zjg1Nzg3
|
10
|
+
NWE0YmU2ZjVhMzYzYjZmNzUxOGZlYjM4OTVhMGU1ZGFlY2IyOTA1YzNkYWUx
|
11
|
+
Y2FmZDkxOGExNmI1NTZkNjJiYTU0ODJkYjgwYzRiNTExNTBlMTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
data/lib/fbwish/version.rb
CHANGED