instagram_geo 0.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Instagram (Burbn, Inc.)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ The Instagram Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Instagram REST and Search APIs
4
+
5
+
6
+ Installation
7
+ ------------
8
+ gem install instagram
9
+
10
+
11
+ Follow @instagramapi on Twitter
12
+ ----------------------------
13
+ You should [follow @instagramapi on Twitter](http://twitter.com/#!/instagramapi) for announcements,
14
+ updates, and news about the Instagram gem.
15
+
16
+
17
+ Join the mailing list!
18
+ ----------------------
19
+ <https://groups.google.com/group/instagram-ruby-gem>
20
+
21
+
22
+ Does your project or organization use this gem?
23
+ -----------------------------------------------
24
+ Add it to the [apps](http://github.com/Instagram/instagram-ruby-gem/wiki/apps) wiki!
25
+
26
+
27
+ Sample Application
28
+ ------------------
29
+ require "sinatra"
30
+ require "instagram"
31
+
32
+ enable :sessions
33
+
34
+ CALLBACK_URL = "http://localhost:4567/oauth/callback"
35
+
36
+ Instagram.configure do |config|
37
+ config.client_id = "YOUR_CLIENT_ID"
38
+ config.client_secret = "YOUR_CLIENT_SECRET"
39
+ end
40
+
41
+ get "/" do
42
+ '<a href="/oauth/connect">Connect with Instagram</a>'
43
+ end
44
+
45
+ get "/oauth/connect" do
46
+ redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
47
+ end
48
+
49
+ get "/oauth/callback" do
50
+ response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
51
+ session[:access_token] = response.access_token
52
+ redirect "/feed"
53
+ end
54
+
55
+ get "/feed" do
56
+ client = Instagram.client(:access_token => session[:access_token])
57
+ user = client.user
58
+
59
+ html = "<h1>#{user.username}'s recent photos</h1>"
60
+ for media_item in client.user_recent_media
61
+ html << "<img src='#{media_item.images.thumbnail.url}'>"
62
+ end
63
+ html
64
+ end
65
+
66
+
67
+ API Usage Examples
68
+ ------------------
69
+ require "rubygems"
70
+ require "instagram"
71
+
72
+ # Get a list of a user's most recent media
73
+ puts Instagram.user_recent_media(777)
74
+
75
+ # Get the currently authenticated user's media feed
76
+ puts Instagram.user_media_feed
77
+
78
+ # Get a list of recent media at a given location, in this case, the Instagram office
79
+ puts Instagram.location_recent_media(514276)
80
+
81
+ # All methods require authentication (either by client ID or access token).
82
+ # To get your Instagram OAuth credentials, register an app at http://instagr.am/oauth/client/register/
83
+ Instagram.configure do |config|
84
+ config.client_id = YOUR_CLIENT_KEY
85
+ config.access_token = YOUR_ACCESS_TOKEN
86
+ end
87
+
88
+ # Get a list of all the users you're following
89
+ puts Instagram.follows
90
+
91
+ # Get a list of media close to a given latitude and longitude
92
+ puts Instagram.media_search("37.7808851","-122.3948632")
93
+
94
+ # Get a list of the overall most popular media items
95
+ puts Instagram.media_popular
96
+
97
+ # Search for users on instagram, by name or username
98
+ puts Instagram.user_search("shayne sweeney")
99
+
100
+
101
+ Contributing
102
+ ------------
103
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
104
+
105
+ Here are some ways *you* can contribute:
106
+
107
+ * by using alpha, beta, and prerelease versions
108
+ * by reporting bugs
109
+ * by suggesting new features
110
+ * by writing or editing documentation
111
+ * by writing specifications
112
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
113
+ * by refactoring code
114
+ * by closing [issues](http://github.com/Instagram/instagram-ruby-gem/issues)
115
+ * by reviewing patches
116
+
117
+
118
+ Submitting an Issue
119
+ -------------------
120
+ We use the [GitHub issue tracker](http://github.com/Instagram/instagram-ruby-gem/issues) to track bugs and
121
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
122
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
123
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
124
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
125
+ operating system. Ideally, a bug report should include a pull request with failing specs.
126
+
127
+
128
+ Submitting a Pull Request
129
+ -------------------------
130
+ 1. Fork the project.
131
+ 2. Create a topic branch.
132
+ 3. Implement your feature or bug fix.
133
+ 4. Add documentation for your feature or bug fix.
134
+ 5. Run <tt>rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
135
+ 6. Add specs for your feature or bug fix.
136
+ 7. Run <tt>rake spec</tt>. If your changes are not 100% covered, go back to step 6.
137
+ 8. Commit and push your changes.
138
+ 9. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
139
+
140
+
141
+ Copyright
142
+ ---------
143
+ Copyright (c) 2011 Instagram (Burbn, Inc).
144
+ See [LICENSE](https://github.com/Instagram/instagram-ruby-gem/blob/master/LICENSE.md) for details.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ namespace :doc do
10
+ begin
11
+ require 'yard'
12
+ rescue LoadError
13
+ # ignore
14
+ else
15
+ YARD::Rake::YardocTask.new do |task|
16
+ task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
17
+ task.options = [
18
+ '--protected',
19
+ '--output-dir', 'doc/yard',
20
+ '--tag', 'format:Supported formats',
21
+ '--tag', 'authenticated:Requires Authentication',
22
+ '--tag', 'rate_limited:Rate Limited',
23
+ '--markup', 'markdown',
24
+ ]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module FaradayMiddleware
5
+ # @private
6
+ class OAuth2 < Faraday::Middleware
7
+ def call(env)
8
+
9
+ if env[:method] == :get or env[:method] == :delete
10
+ if env[:url].query.nil?
11
+ query = {}
12
+ else
13
+ query = Faraday::Utils.parse_query(env[:url].query)
14
+ end
15
+
16
+ if @access_token and not query["client_secret"]
17
+ env[:url].query = Faraday::Utils.build_query(query.merge(:access_token => @access_token))
18
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
19
+ elsif @client_id
20
+ env[:url].query = Faraday::Utils.build_query(query.merge(:client_id => @client_id))
21
+ end
22
+ else
23
+ if @access_token and not env[:body] && env[:body][:client_secret]
24
+ env[:body] = {} if env[:body].nil?
25
+ env[:body] = env[:body].merge(:access_token => @access_token)
26
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
27
+ elsif @client_id
28
+ env[:body] = env[:body].merge(:client_id => @client_id)
29
+ end
30
+ end
31
+
32
+
33
+ @app.call env
34
+ end
35
+
36
+ def initialize(app, client_id, access_token=nil)
37
+ @app = app
38
+ @client_id = client_id
39
+ @access_token = access_token
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module FaradayMiddleware
5
+ # @private
6
+ class RaiseHttpException < Faraday::Middleware
7
+ def call(env)
8
+ @app.call(env).on_complete do |response|
9
+ case response[:status].to_i
10
+ when 400
11
+ raise Instagram::BadRequest, error_message_400(response)
12
+ when 404
13
+ raise Instagram::NotFound, error_message_400(response)
14
+ when 500
15
+ raise Instagram::InternalServerError, error_message_500(response, "Something is technically wrong.")
16
+ when 503
17
+ raise Instagram::ServiceUnavailable, error_message_500(response, "Instagram is rate limiting your requests.")
18
+ end
19
+ end
20
+ end
21
+
22
+ def initialize(app)
23
+ super app
24
+ @parser = nil
25
+ end
26
+
27
+ private
28
+
29
+ def error_message_400(response)
30
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
31
+ end
32
+
33
+ def error_body(body)
34
+ # body gets passed as a string, not sure if it is passed as something else from other spots?
35
+ if not body.nil? and not body.empty? and body.kind_of?(String)
36
+ # removed multi_json thanks to wesnolte's commit
37
+ body = ::JSON.parse(body)
38
+ end
39
+
40
+ if body.nil?
41
+ nil
42
+ elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
43
+ ": #{body['meta']['error_message']}"
44
+ end
45
+ end
46
+
47
+ def error_message_500(response, body=nil)
48
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+ require File.expand_path('../oauth', __FILE__)
4
+
5
+ module Instagram
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
10
+
11
+ # Creates a new API
12
+ def initialize(options={})
13
+ options = Instagram.options.merge(options)
14
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Connection
20
+ include Request
21
+ include OAuth
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Instagram
2
+ # Wrapper for the Instagram REST API
3
+ #
4
+ # @note All methods have been separated into modules and follow the same grouping used in {TODO:doc_URL the Instagram API Documentation}.
5
+ # @see TODO:doc_url
6
+ class Client < API
7
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
8
+
9
+ include Instagram::Client::Utils
10
+
11
+ include Instagram::Client::Users
12
+ include Instagram::Client::Media
13
+ include Instagram::Client::Locations
14
+ include Instagram::Client::Geographies
15
+ include Instagram::Client::Tags
16
+ include Instagram::Client::Comments
17
+ include Instagram::Client::Likes
18
+ include Instagram::Client::Subscriptions
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ module Instagram
2
+ class Client
3
+ # Defines methods related to comments
4
+ module Comments
5
+ # Returns a list of comments for a given media item ID
6
+ #
7
+ # @overload media_comments(id)
8
+ # @param id [Integer] An Instagram media item ID
9
+ # @return [Hashie::Mash] The requested comment.
10
+ # @example Returns a list of comments for the media item of ID 1234
11
+ # Instagram.media_comments(777)
12
+ # @format :json
13
+ # @authenticated true
14
+ #
15
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
16
+ # @rate_limited true
17
+ # @see TODO:docs url
18
+ def media_comments(id, *args)
19
+ response = get("media/#{id}/comments")
20
+ response["data"]
21
+ end
22
+
23
+ # Creates a comment for a given media item ID
24
+ #
25
+ # @overload create_media_comment(id, text)
26
+ # @param id [Integer] An Instagram media item ID
27
+ # @param text [String] The text of your comment
28
+ # @return [Hashie::Mash] The comment created.
29
+ # @example Creates a new comment on media item with ID 777
30
+ # Instagram.create_media_comment(777, "Oh noes!")
31
+ # @format :json
32
+ # @authenticated true
33
+ #
34
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
35
+ # @rate_limited true
36
+ # @see TODO:docs url
37
+ def create_media_comment(id, text, options={})
38
+ response = post("media/#{id}/comments", options.merge(:text => text))
39
+ response["data"]
40
+ end
41
+
42
+ # Deletes a comment for a given media item ID
43
+ #
44
+ # @overload delete_media_comment(media_id, comment_id)
45
+ # @param media_id [Integer] An Instagram media item ID.
46
+ # @param comment_id [Integer] Your comment ID of the comment you wish to delete.
47
+ # @return [nil]
48
+ # @example Delete the comment with ID of 1234, on the media item with ID of 777
49
+ # Instagram.delete_media_comment(777, 1234)
50
+ # @format :json
51
+ # @authenticated true
52
+ #
53
+ # In order to remove a comment, you must be either the owner comment or the media item (or both).
54
+ # @rate_limited true
55
+ # @see TODO:docs url
56
+ def delete_media_comment(media_id, comment_id, options={})
57
+ response = delete("media/#{media_id}/comments/#{comment_id}", options)
58
+ response["data"]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,29 @@
1
+ module Instagram
2
+ class Client
3
+ # Defines methods related to real-time geographies
4
+ module Geographies
5
+ # Returns a list of recent media items for a given real-time geography
6
+ #
7
+ # @overload geography_recent_media(id, options={})
8
+ # @param user [Integer] A geography ID from a real-time subscription.
9
+ # @param options [Hash] A customizable set of options.
10
+ # @option options [Integer] :count (nil) Limit the number of results returned
11
+ # @option options [Integer] :min_id (nil) Return media before this min_id
12
+ # @option options [Integer] :max_id (nil) Return media after this max_id
13
+ # @option options [Integer] :min_timestamp (nil) Return media after this UNIX timestamp
14
+ # @option options [Integer] :max_timestamp (nil) Return media before this UNIX timestamp
15
+ # @return [Hashie::Mash]
16
+ # @example Return a list of the most recent media items taken within a specific geography
17
+ # Instagram.geography_recent_media(514276)
18
+ # @see http://instagram.com/developer/endpoints/geographies/
19
+ # @format :json
20
+ # @authenticated false
21
+ # @rate_limited true
22
+ def geography_recent_media(id, *args)
23
+ options = args.last.is_a?(Hash) ? args.pop : {}
24
+ response = get("geographies/#{id}/media/recent", options)
25
+ response["data"]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,58 @@
1
+ module Instagram
2
+ class Client
3
+ # Defines methods related to likes
4
+ module Likes
5
+ # Returns a list of users who like a given media item ID
6
+ #
7
+ # @overload media_likes(id)
8
+ # @param media [Integer] An Instagram media item ID
9
+ # @return [Hashie::Mash] A list of users.
10
+ # @example Returns a list of users who like the media item of ID 1234
11
+ # Instagram.media_likes(777)
12
+ # @format :json
13
+ # @authenticated true
14
+ #
15
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
16
+ # @rate_limited true
17
+ # @see TODO:docs url
18
+ def media_likes(id, *args)
19
+ response = get("media/#{id}/likes")
20
+ response["data"]
21
+ end
22
+
23
+ # Issues a like by the currently authenticated user, for a given media item ID
24
+ #
25
+ # @overload like_media(id, text)
26
+ # @param id [Integer] An Instagram media item ID
27
+ # @return [nil]
28
+ # @example Like media item with ID 777
29
+ # Instagram.like_media(777)
30
+ # @format :json
31
+ # @authenticated true
32
+ #
33
+ # If getting this data of a protected user, you must be authenticated (and be allowed to see that user).
34
+ # @rate_limited true
35
+ # @see TODO:docs url
36
+ def like_media(id, options={})
37
+ response = post("media/#{id}/likes", options)
38
+ response["data"]
39
+ end
40
+
41
+ # Removes the like on a givem media item ID for the currently authenticated user
42
+ #
43
+ # @overload unlike_media(id)
44
+ # @param media_id [Integer] An Instagram media item ID.
45
+ # @return [nil]
46
+ # @example Remove the like for the currently authenticated user on the media item with the ID of 777
47
+ # Instagram.unlike_media(777)
48
+ # @format :json
49
+ # @authenticated true
50
+ # @rate_limited true
51
+ # @see TODO:docs url
52
+ def unlike_media(id, options={})
53
+ response = delete("media/#{id}/likes", options)
54
+ response["data"]
55
+ end
56
+ end
57
+ end
58
+ end