@@ -8,7 +8,7 @@ def find_posts_for(source)
8
8
9
9
FacebookProvider . client . get_connections ( source . key , KEYS )
10
10
. select { |e | e . key? 'object_id' } . each do |post |
11
- condition = breakers! post [ 'object_id' ] , last , source
11
+ condition = breakers post [ 'object_id' ] , last , source
12
12
13
13
next if condition == 'next'
14
14
break if condition == 'break'
@@ -23,10 +23,10 @@ def find_posts_for(source)
23
23
24
24
private
25
25
26
- FIELDS = %w( id object_id message link created_time full_picture ) . freeze
26
+ FIELDS = %w( id object_id message link created_time full_picture type ) . freeze
27
27
KEYS = "posts?fields=#{ FIELDS . join ( ',' ) } " . freeze
28
28
29
- def breakers! ( id , last , source )
29
+ def breakers ( id , last , source )
30
30
if reached_limit? ( id , last )
31
31
'break'
32
32
elsif Micropost . exists? ( source : source , provider_id : id )
@@ -53,15 +53,19 @@ def create_micropost_using!(post, source)
53
53
end
54
54
55
55
def attach_content_to ( post , from :)
56
- Medium . create do | m |
57
- m . micropost = post
58
- m . remote_file_url = from [ 'full_picture' ]
59
- end
56
+ Medium . create micropost : post ,
57
+ remote_file_url : from [ 'full_picture' ] ,
58
+ kind : MediumKind . value_for ( from [ 'type' ] ) ,
59
+ url : get_media_video ( from [ 'object_id' ] , from [ 'type' ] )
60
60
end
61
61
62
62
def attach_troller_to ( post , from :)
63
63
post . trollers << Troller . new ( trollerable : from . club )
64
64
end
65
+
66
+ def get_media_video ( object_id , kind )
67
+ "https://www.facebook.com/video/embed?video_id=#{ object_id } " if kind == 'video'
68
+ end
65
69
end
66
70
end
67
71
end
0 commit comments