instagram 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2010 Mislav Marohnić
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # Instagram Ruby library
2
+
3
+ So far, the only way to browse [Instagram][] photos was their iPhone app. Well, no more.
4
+
5
+ This library acts as a client for the [unofficial Instagram API][wiki]. You can:
6
+
7
+ * fetch popular photos;
8
+ * get user info;
9
+ * browse photos by a user.
10
+
11
+ Caveat: you need to know user IDs; usernames can't be used. However, you can start from the popular feed and drill down from there.
12
+
13
+ ## Example usage
14
+
15
+ require 'instagram'
16
+
17
+ photos = Instagram::popular
18
+ photo = photos.first
19
+
20
+ photo.caption #=> "Extreme dog closeup"
21
+ photo.likes.size #=> 54
22
+
23
+ photo.user.username #=> "johndoe"
24
+ photo.user.full_name #=> "John Doe"
25
+ photo.comments[1].text #=> "That's so cute"
26
+ photo.images.last.width #=> 612
27
+
28
+
29
+ # fetch extended info for John
30
+ john_info = Instagram::user_info(photo.user.id)
31
+
32
+ john_info.media_count #=> 32
33
+ john_info.followers #=> 160
34
+
35
+
36
+ # find more photos by John
37
+ photos_by_john = Instagram::by_user(photo.user.id)
38
+
39
+
40
+ ## Credits
41
+
42
+ Instagram API reverse-engineered and Ruby library written by Mislav Marohnić.
43
+
44
+
45
+ [instagram]: http://instagr.am/
46
+ [wiki]: https://github.com/mislav/instagram/wiki "Instagram API"
@@ -0,0 +1,33 @@
1
+ require 'addressable/uri'
2
+ require 'addressable/template'
3
+ require 'net/http'
4
+ require 'instagram/models'
5
+
6
+ module Instagram
7
+
8
+ Popular = Addressable::URI.parse 'http://instagr.am/api/v1/feed/popular/'
9
+ UserFeed = Addressable::Template.new 'http://instagr.am/api/v1/feed/user/{user_id}/'
10
+ UserInfo = Addressable::Template.new 'http://instagr.am/api/v1/users/{user_id}/info/'
11
+
12
+ def self.popular(params = {})
13
+ url = Popular.dup
14
+ parse_response(url, params, Timeline)
15
+ end
16
+
17
+ def self.by_user(user_id, params = {})
18
+ url = UserFeed.expand :user_id => user_id
19
+ parse_response(url, params, Timeline)
20
+ end
21
+
22
+ def self.user_info(user_id, params = {})
23
+ url = UserInfo.expand :user_id => user_id
24
+ parse_response(url, params, UserWrap)
25
+ end
26
+
27
+ def self.parse_response(url, params, parser)
28
+ url.query_values = params
29
+ body = Net::HTTP.get url
30
+ parser.parse body
31
+ end
32
+
33
+ end
@@ -0,0 +1,71 @@
1
+ require 'yajl/json_gem'
2
+ require 'nibbler/json'
3
+
4
+ module Instagram
5
+
6
+ class Base < NibblerJSON
7
+ element 'pk' => :id
8
+ end
9
+
10
+ class User < Base
11
+ element :username
12
+ element :full_name
13
+ element 'profile_pic_url' => :avatar
14
+
15
+ # extended info
16
+ element :media_count
17
+ element 'following_count' => :following
18
+ element 'follower_count' => :followers
19
+
20
+ def ==(other)
21
+ User === other and other.id == self.id
22
+ end
23
+ end
24
+
25
+ class UserWrap < NibblerJSON
26
+ element :user, :with => User
27
+ # return user instead of self when done
28
+ def parse() super.user end
29
+ end
30
+
31
+ class Media < Base
32
+ element :code
33
+ element :media_type
34
+ element :filter_type
35
+ element :device_timestamp
36
+ element :taken_at, :with => lambda { |sec| Time.at(sec) }
37
+ element :user, :with => User
38
+
39
+ elements :likers, :with => User
40
+
41
+ elements :comments, :with => NibblerJSON do
42
+ element :created_at, :with => lambda { |sec| Time.at(sec) }
43
+ element :content_type
44
+ element :type
45
+ element :media_id
46
+ element :text
47
+ element :user, :with => User
48
+ end
49
+
50
+ elements 'image_versions' => :images, :with => NibblerJSON do
51
+ element :url
52
+ element :type
53
+ element :width
54
+ element :height
55
+ end
56
+
57
+ def caption
58
+ # a bit of guesswork
59
+ if comments.first and self.user == comments.first.user
60
+ comments.first.text
61
+ end
62
+ end
63
+ end
64
+
65
+ class Timeline < NibblerJSON
66
+ elements :items, :with => Media
67
+ # return items instead of self when done
68
+ def parse() super.items end
69
+ end
70
+
71
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instagram
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - "Mislav Marohni\xC4\x87"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-30 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: addressable
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: yajl-ruby
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: nibbler
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 31
58
+ segments:
59
+ - 1
60
+ - 2
61
+ - 0
62
+ version: 1.2.0
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ description: Ruby library for consuming the Instagram public API.
66
+ email: mislav.marohnic@gmail.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - lib/instagram/models.rb
75
+ - lib/instagram.rb
76
+ - README.md
77
+ - MIT-LICENSE
78
+ has_rdoc: false
79
+ homepage: http://github.com/mislav/instagram
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options: []
84
+
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.7
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Instagram API client
112
+ test_files: []
113
+