fbwish 1.0.0 → 1.0.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 +8 -8
- data/lib/fbwish.rb +41 -39
- 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
|
+
Mzc0OTA3MTAxMjMyMDlhYTU1ZTA4NGM0MmY5ZWU1MjYxZjA4NjhmMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWRlODExZThlYzhlODAxZWQ2ZWVlYjBhNTY0MTk2OTY4NGJmYjM0NA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjU0MzhlOWI0ZmZhMTgxNjhiMmMzMDk1NDZkY2U5ZTViZGRiYWIyNzA0NzY2
|
10
|
+
ODM2NDkxNDNmYzdiNzUxOWJlODcwYTg0NjVmNDdhMmVlOGNkYzJhOGQwYjAw
|
11
|
+
NGQ4OGExNGFlNGM2NTVkNDZjODg4MjI1YjE4Y2FkZGUyZWQ1N2Y=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjlmYTY1ZTZhYzUwYmYzODFmYThjZWMwZWY0NTYwMDI0NmI5ZTc0NzkwZWYx
|
14
|
+
ZThlM2MwNzdkYTg1YWFhOWRiODgyNGFkMDZhYzJlN2JhZTJkNTNlMDk2NTI1
|
15
|
+
MWJhNjc4ZWQ5YTk2ZmEyY2I2ODBjNTdhYjIwYTUxODAyZmU0MWM=
|
data/lib/fbwish.rb
CHANGED
@@ -2,57 +2,59 @@ require "fbwish/version"
|
|
2
2
|
require "koala"
|
3
3
|
|
4
4
|
module Fbwish
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class Wisher
|
6
|
+
def initialize(options={})
|
7
|
+
required_options = [:access_token, :matcher, :replies]
|
8
|
+
unspecified_options = options.keys.reject{ |key| options[key] }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
unless unspecified_options.empty?
|
11
|
+
raise ArgumentError("Following options are required: #{unspecified_options.join(', ')}")
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
self.graph = Koala::Facebook::API.new(options[:access_token])
|
15
|
+
self.matcher = options[:matcher]
|
16
|
+
self.replies = options[:replies]
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def wish_em_all!
|
20
|
+
wishes = nil
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
1.upto(13) do |idx|
|
23
|
+
wishes = wishes.next_page rescue graph.get_connections('me', 'feed')
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
wishes.each do |wish|
|
26
|
+
like_and_comment(wish)
|
27
|
+
end
|
26
28
|
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
private
|
32
|
+
def like(wish)
|
33
|
+
graph.put_like(wish['id'])
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def comment(wish, replies)
|
37
|
+
# If it is an array pick random else pick itself(assuming it is a string)
|
38
|
+
reply = replies.is_a?(Array) ?
|
39
|
+
replies[rand(replies.length-1)] :
|
40
|
+
replies
|
41
|
+
graph.put_comment(wish['id'], reply)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def like_and_comment(wish)
|
45
|
+
if matcher.is_a?(Object)
|
46
|
+
matcher.each do |locale, regex|
|
47
|
+
if regex.match(wish['message'])
|
48
|
+
like(wish)
|
49
|
+
comment(wish, replies[locale])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
if matcher.match(wish['message'])
|
47
54
|
like(wish)
|
48
|
-
comment(wish, replies
|
55
|
+
comment(wish, replies)
|
49
56
|
end
|
50
57
|
end
|
51
|
-
else
|
52
|
-
if matcher.match(wish['message'])
|
53
|
-
like(wish)
|
54
|
-
comment(wish, replies)
|
55
|
-
end
|
56
58
|
end
|
57
|
-
|
59
|
+
end
|
58
60
|
end
|
data/lib/fbwish/version.rb
CHANGED