instagram 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -7
- data/lib/instagram.rb +1 -1
- data/lib/instagram/models.rb +64 -4
- metadata +3 -3
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
# Instagram Ruby library
|
1
|
+
# [Instagram][] Ruby library
|
2
2
|
|
3
|
-
|
3
|
+
This library acts as a client for the [unofficial Instagram API][wiki]. It was used to create [the missing Instagram web interface][web].
|
4
4
|
|
5
|
-
|
5
|
+
$ gem install instagram
|
6
|
+
|
7
|
+
With it, you can:
|
6
8
|
|
7
9
|
* fetch popular photos;
|
8
10
|
* get user info;
|
@@ -19,28 +21,35 @@ Caveat: you need to know user IDs; usernames can't be used. However, you can sta
|
|
19
21
|
|
20
22
|
photo.caption #=> "Extreme dog closeup"
|
21
23
|
photo.likes.size #=> 54
|
24
|
+
photo.filter_name #=> "X-Pro II"
|
22
25
|
|
23
26
|
photo.user.username #=> "johndoe"
|
24
27
|
photo.user.full_name #=> "John Doe"
|
25
28
|
photo.comments[1].text #=> "That's so cute"
|
26
29
|
photo.images.last.width #=> 612
|
27
30
|
|
31
|
+
# available sizes: 150px / 306px / 612px square
|
32
|
+
photo.image_url(612)
|
33
|
+
# => "http://distillery.s3.amazonaws.com/media/-.jpg" (612×612px image)
|
28
34
|
|
29
35
|
# fetch extended info for John
|
30
36
|
john_info = Instagram::user_info(photo.user.id)
|
31
37
|
|
32
|
-
john_info.media_count
|
33
|
-
john_info.
|
38
|
+
john_info.media_count #=> 32
|
39
|
+
john_info.follower_count #=> 160
|
34
40
|
|
35
41
|
|
36
42
|
# find more photos by John
|
37
43
|
photos_by_john = Instagram::by_user(photo.user.id)
|
38
44
|
|
45
|
+
To see which models and properties are available, see [models.rb][models].
|
39
46
|
|
40
47
|
## Credits
|
41
48
|
|
42
|
-
Instagram API
|
49
|
+
Instagram API documentation and Ruby library written by Mislav Marohnić.
|
43
50
|
|
44
51
|
|
45
52
|
[instagram]: http://instagr.am/
|
46
|
-
[
|
53
|
+
[web]: http://instagram.heroku.com
|
54
|
+
[wiki]: https://github.com/mislav/instagram/wiki "Instagram API"
|
55
|
+
[models]: https://github.com/mislav/instagram/blob/master/lib/instagram/models.rb
|
data/lib/instagram.rb
CHANGED
data/lib/instagram/models.rb
CHANGED
@@ -4,18 +4,22 @@ require 'nibbler/json'
|
|
4
4
|
module Instagram
|
5
5
|
|
6
6
|
class Base < NibblerJSON
|
7
|
+
# `pk` is such a dumb property name
|
7
8
|
element 'pk' => :id
|
8
9
|
end
|
9
10
|
|
10
11
|
class User < Base
|
11
12
|
element :username
|
12
13
|
element :full_name
|
13
|
-
element 'profile_pic_url' => :
|
14
|
+
element 'profile_pic_url' => :avatar_url
|
15
|
+
alias avatar avatar_url # `avatar` is deprecated
|
14
16
|
|
15
17
|
# extended info
|
16
18
|
element :media_count
|
17
|
-
element
|
18
|
-
|
19
|
+
element :following_count
|
20
|
+
alias following following_count # `following` will return an array of users in future!
|
21
|
+
element :follower_count
|
22
|
+
alias followers follower_count # `followers` will return an array of users in future!
|
19
23
|
|
20
24
|
def ==(other)
|
21
25
|
User === other and other.id == self.id
|
@@ -29,26 +33,39 @@ module Instagram
|
|
29
33
|
end
|
30
34
|
|
31
35
|
class Media < Base
|
36
|
+
# short string used for permalink
|
32
37
|
element :code
|
38
|
+
# type is always 1 (other values possibly reserved for video in the future?)
|
33
39
|
element :media_type
|
40
|
+
# filter code; use `filter_name` to get human name of the filter used
|
34
41
|
element :filter_type
|
42
|
+
# I don't know what "device timestamp" is and how it relates to `taken_at`?
|
35
43
|
element :device_timestamp
|
44
|
+
# timestamp of when the picture was taken
|
36
45
|
element :taken_at, :with => lambda { |sec| Time.at(sec) }
|
46
|
+
# user who uploaded the media
|
37
47
|
element :user, :with => User
|
38
48
|
|
49
|
+
# array of people who liked this media
|
39
50
|
elements :likers, :with => User
|
40
51
|
|
41
52
|
elements :comments, :with => NibblerJSON do
|
42
53
|
element :created_at, :with => lambda { |sec| Time.at(sec) }
|
54
|
+
# content type is always "comment"
|
43
55
|
element :content_type
|
56
|
+
# `type` is always 1 (other values possibly reserved for comments in form of media?)
|
44
57
|
element :type
|
58
|
+
# the `pk` of parent media
|
45
59
|
element :media_id
|
60
|
+
# comment body
|
46
61
|
element :text
|
62
|
+
# comment author
|
47
63
|
element :user, :with => User
|
48
64
|
end
|
49
65
|
|
50
66
|
elements 'image_versions' => :images, :with => NibblerJSON do
|
51
67
|
element :url
|
68
|
+
# `type` is 5 for 150px, 6 for 306px and 7 for 612px
|
52
69
|
element :type
|
53
70
|
element :width
|
54
71
|
element :height
|
@@ -56,16 +73,59 @@ module Instagram
|
|
56
73
|
alias to_s url
|
57
74
|
end
|
58
75
|
|
76
|
+
# image location
|
77
|
+
element :lat
|
78
|
+
element :lng
|
79
|
+
|
80
|
+
def geolocated?
|
81
|
+
self.lat and self.lng
|
82
|
+
end
|
83
|
+
|
84
|
+
element :location, :with => Base do
|
85
|
+
# ID on a 3rd-party service
|
86
|
+
element :external_id
|
87
|
+
# name of 3rd-party service, like "foursquare"
|
88
|
+
element :external_source
|
89
|
+
# name of location
|
90
|
+
element :name
|
91
|
+
# address in the external service's database
|
92
|
+
element :address
|
93
|
+
element :lat
|
94
|
+
element :lng
|
95
|
+
end
|
96
|
+
|
97
|
+
# author's caption for the image; can be nil
|
59
98
|
def caption
|
60
|
-
# a
|
99
|
+
# caption is implemented as a first comment made by the owner
|
61
100
|
if comments.first and self.user == comments.first.user
|
62
101
|
comments.first.text
|
63
102
|
end
|
64
103
|
end
|
65
104
|
|
105
|
+
# typical sizes: 150px / 306px / 612px square
|
66
106
|
def image_url(size = 150)
|
67
107
|
self.images.find { |img| img.width == size }.to_s
|
68
108
|
end
|
109
|
+
|
110
|
+
FILTERS = {
|
111
|
+
1 => 'X-Pro II',
|
112
|
+
2 => 'Lomo-fi',
|
113
|
+
3 => 'Earlybird',
|
114
|
+
17 => 'Lily',
|
115
|
+
5 => 'Poprocket',
|
116
|
+
18 => 'Sutro',
|
117
|
+
19 => 'Toaster',
|
118
|
+
10 => 'Inkwell',
|
119
|
+
4 => 'Apollo',
|
120
|
+
15 => 'Nashville',
|
121
|
+
13 => 'Gotham',
|
122
|
+
14 => '1977',
|
123
|
+
16 => 'Lord Kelvin'
|
124
|
+
}
|
125
|
+
|
126
|
+
def filter_name
|
127
|
+
FILTERS[filter_type.to_i]
|
128
|
+
end
|
69
129
|
end
|
70
130
|
|
71
131
|
class Timeline < NibblerJSON
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Mislav Marohni\xC4\x87"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-27 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|