Class: FacebookPhotos::Facebook
- Inherits:
-
Object
- Object
- FacebookPhotos::Facebook
- Defined in:
- lib/facebook_photos.rb
Overview
Your code goes hereā¦
Constant Summary collapse
- FACEBOOK_TOKEN =
"AAAGiiJTk5tQBAIJzVhwtTMNiAzsI6YE5xZBACV0LgszCFRZCa1YlcN48RUtj7dJP02R3A5MYZBMl8eBLbeKaOdG1NOZCduYxT2RGiJNR0gZDZD"
Instance Method Summary collapse
- #facebook_photos ⇒ Object
- #facebook_tag_photos ⇒ Object
-
#initialize(dir, username) ⇒ Facebook
constructor
dir: directory facebook_username.
- #save(f_photo) ⇒ Object
Constructor Details
#initialize(dir, username) ⇒ Facebook
dir: directory facebook_username
12 13 14 15 |
# File 'lib/facebook_photos.rb', line 12 def initialize dir, username @dir = dir @username = username end |
Instance Method Details
#facebook_photos ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/facebook_photos.rb', line 17 def facebook_photos user = FbGraph::User.fetch(@username,access_token: FACEBOOK_TOKEN) albums = user.albums count = 1 albums.each do |album| album.photos.each do |photo| save(photo) end end end |
#facebook_tag_photos ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/facebook_photos.rb', line 30 def facebook_tag_photos user = FbGraph::User.fetch(@username,access_token: FACEBOOK_TOKEN) photos = user.photos count = 1 photos.each do |photo| save(photo) end end |
#save(f_photo) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/facebook_photos.rb', line 41 def save f_photo p url = f_photo.source photo_name = File.basename(url) File.open(@dir + photo_name, 'wb') do |file| uri = URI.parse(url) Net::HTTP.start(uri.host,uri.port){ |http| http.request_get(uri.path){ |res| res.read_body{ |seg| file << seg sleep 0.1 } } } end end |