forked from renshao/beta-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoto.rb
42 lines (38 loc) · 1.29 KB
/
photo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Photo
attr_accessor :name, :lat, :lng, :url_s, :url_sq, :username, :created_at
def initialize(options)
@id = options[:id]
@name = options[:caption]
@lat = options[:latitude]
@lng = options[:longitude]
@url_s = options[:url_s]
@url_sq = options[:url_sq]
@username = options[:username]
@created_at = options[:created_at]
end
def self.from_instagram_photo(instagram_photo)
self.new :id => instagram_photo.id,
:caption => (instagram_photo.caption ? instagram_photo.caption.text : ""),
:latitude => instagram_photo.location.latitude,
:longitude => instagram_photo.location.longitude,
:url_s => instagram_photo.images.standard_resolution.url,
:url_sq => instagram_photo.images.standard_resolution.url,
:username => instagram_photo.user.full_name,
:created_at => Time.at(instagram_photo.created_time.to_i).strftime("%I:%M%p %d %b %Y")
end
def to_json(*a)
{
:id => @id,
:name => @name,
:lat => @lat,
:lng => @lng,
:url_s => @url_s,
:url_sq => @url_sq,
:username => @username,
:created_at => @created_at
}.to_json(*a)
end
def to_s
"#{name} (#{lat}, #{lng}) #{url_s} #{url_sq} #{username} #{created_at}"
end
end