Permalink
Browse files

add helpful comments to models code

  • Loading branch information...
1 parent 96b01ee commit cd42290d02f1eeac126d12f372ca4056c22adabd @mislav committed with Dec 12, 2010
Showing with 22 additions and 3 deletions.
  1. +5 −2 README.md
  2. +17 −1 lib/instagram/models.rb
View
@@ -28,8 +28,9 @@ Caveat: you need to know user IDs; usernames can't be used. However, you can sta
photo.comments[1].text #=> "That's so cute"
photo.images.last.width #=> 612
+ # available sizes: 150px / 306px / 612px square
photo.image_url(612)
- # => "http://distillery.s3.amazonaws.com/media/-.jpg"
+ # => "http://distillery.s3.amazonaws.com/media/-.jpg" (612×612px image)
# fetch extended info for John
john_info = Instagram::user_info(photo.user.id)
@@ -41,6 +42,7 @@ Caveat: you need to know user IDs; usernames can't be used. However, you can sta
# find more photos by John
photos_by_john = Instagram::by_user(photo.user.id)
+To see which models and properties are available, see [models.rb][models].
## Credits
@@ -49,4 +51,5 @@ Instagram API documentation and Ruby library written by Mislav Marohnić.
[instagram]: http://instagr.am/
[web]: http://instagram.heroku.com
-[wiki]: https://github.com/mislav/instagram/wiki "Instagram API"
+[wiki]: https://github.com/mislav/instagram/wiki "Instagram API"
+[models]: https://github.com/mislav/instagram/blob/master/lib/instagram/models.rb
View
@@ -4,6 +4,7 @@
module Instagram
class Base < NibblerJSON
+ # `pk` is such a dumb property name
element 'pk' => :id
end
@@ -32,40 +33,55 @@ def parse() super.user end
end
class Media < Base
+ # short string used for permalink
element :code
+ # type is always 1 (other values possibly reserved for video in the future?)
element :media_type
+ # filter code; use `filter_name` to get human name of the filter used
element :filter_type
+ # I don't know what "device timestamp" is and how it relates to `taken_at`?
element :device_timestamp
+ # timestamp of when the picture was taken
element :taken_at, :with => lambda { |sec| Time.at(sec) }
+ # user who uploaded the media
element :user, :with => User
+ # array of people who liked this media
elements :likers, :with => User
elements :comments, :with => NibblerJSON do
element :created_at, :with => lambda { |sec| Time.at(sec) }
+ # content type is always "comment"
element :content_type
+ # `type` is always 1 (other values possibly reserved for comments in form of media?)
element :type
+ # the `pk` of parent media
element :media_id
+ # comment body
element :text
+ # comment author
element :user, :with => User
end
elements 'image_versions' => :images, :with => NibblerJSON do
element :url
+ # `type` is 5 for 150px, 6 for 306px and 7 for 612px
element :type
element :width
element :height
alias to_s url
end
+ # author's caption for the image; can be nil
def caption
- # a bit of guesswork
+ # caption is implemented as a first comment made by the owner
if comments.first and self.user == comments.first.user
comments.first.text
end
end
+ # typical sizes: 150px / 306px / 612px square
def image_url(size = 150)
self.images.find { |img| img.width == size }.to_s
end

0 comments on commit cd42290

Please sign in to comment.