instagram-innonate 0.8

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.
Files changed (80) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +3 -0
  3. data/.yardopts +9 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.md +20 -0
  6. data/README.md +144 -0
  7. data/Rakefile +27 -0
  8. data/instagram.gemspec +26 -0
  9. data/lib/faraday/oauth2.rb +36 -0
  10. data/lib/faraday/raise_http_4xx.rb +37 -0
  11. data/lib/faraday/raise_http_5xx.rb +29 -0
  12. data/lib/instagram.rb +26 -0
  13. data/lib/instagram/api.rb +23 -0
  14. data/lib/instagram/client.rb +20 -0
  15. data/lib/instagram/client/comments.rb +62 -0
  16. data/lib/instagram/client/geographies.rb +29 -0
  17. data/lib/instagram/client/likes.rb +58 -0
  18. data/lib/instagram/client/locations.rb +59 -0
  19. data/lib/instagram/client/media.rb +63 -0
  20. data/lib/instagram/client/subscriptions.rb +157 -0
  21. data/lib/instagram/client/tags.rb +59 -0
  22. data/lib/instagram/client/users.rb +309 -0
  23. data/lib/instagram/client/utils.rb +15 -0
  24. data/lib/instagram/configuration.rb +90 -0
  25. data/lib/instagram/connection.rb +31 -0
  26. data/lib/instagram/error.rb +19 -0
  27. data/lib/instagram/oauth.rb +27 -0
  28. data/lib/instagram/request.rb +45 -0
  29. data/lib/instagram/version.rb +3 -0
  30. data/spec/faraday/response_spec.rb +28 -0
  31. data/spec/fixtures/access_token.json +9 -0
  32. data/spec/fixtures/approve_user.json +8 -0
  33. data/spec/fixtures/block_user.json +8 -0
  34. data/spec/fixtures/deny_user.json +8 -0
  35. data/spec/fixtures/follow_user.json +8 -0
  36. data/spec/fixtures/followed_by.json +1 -0
  37. data/spec/fixtures/follows.json +1 -0
  38. data/spec/fixtures/geography_recent_media.json +1 -0
  39. data/spec/fixtures/liked_media.json +1 -0
  40. data/spec/fixtures/location.json +1 -0
  41. data/spec/fixtures/location_recent_media.json +1 -0
  42. data/spec/fixtures/location_search.json +1 -0
  43. data/spec/fixtures/media.json +1 -0
  44. data/spec/fixtures/media_comment.json +1 -0
  45. data/spec/fixtures/media_comment_deleted.json +1 -0
  46. data/spec/fixtures/media_comments.json +1 -0
  47. data/spec/fixtures/media_liked.json +1 -0
  48. data/spec/fixtures/media_likes.json +1 -0
  49. data/spec/fixtures/media_popular.json +1 -0
  50. data/spec/fixtures/media_search.json +1 -0
  51. data/spec/fixtures/media_unliked.json +1 -0
  52. data/spec/fixtures/mikeyk.json +1 -0
  53. data/spec/fixtures/recent_media.json +1 -0
  54. data/spec/fixtures/relationship.json +9 -0
  55. data/spec/fixtures/requested_by.json +12 -0
  56. data/spec/fixtures/shayne.json +1 -0
  57. data/spec/fixtures/subscription.json +12 -0
  58. data/spec/fixtures/subscription_deleted.json +1 -0
  59. data/spec/fixtures/subscription_payload.json +14 -0
  60. data/spec/fixtures/subscriptions.json +22 -0
  61. data/spec/fixtures/tag.json +1 -0
  62. data/spec/fixtures/tag_recent_media.json +1 -0
  63. data/spec/fixtures/tag_search.json +1 -0
  64. data/spec/fixtures/unblock_user.json +8 -0
  65. data/spec/fixtures/unfollow_user.json +8 -0
  66. data/spec/fixtures/user_media_feed.json +1 -0
  67. data/spec/fixtures/user_search.json +1 -0
  68. data/spec/instagram/api_spec.rb +110 -0
  69. data/spec/instagram/client/comments_spec.rb +71 -0
  70. data/spec/instagram/client/geography_spec.rb +37 -0
  71. data/spec/instagram/client/likes_spec.rb +66 -0
  72. data/spec/instagram/client/locations_spec.rb +78 -0
  73. data/spec/instagram/client/media_spec.rb +78 -0
  74. data/spec/instagram/client/subscriptions_spec.rb +148 -0
  75. data/spec/instagram/client/tags_spec.rb +78 -0
  76. data/spec/instagram/client/users_spec.rb +400 -0
  77. data/spec/instagram/client_spec.rb +23 -0
  78. data/spec/instagram_spec.rb +97 -0
  79. data/spec/spec_helper.rb +59 -0
  80. metadata +303 -0
@@ -0,0 +1,12 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .rvmrc
6
+ .yardoc
7
+ .rake_tasks~
8
+ Gemfile.lock
9
+ coverage/*
10
+ doc/*
11
+ log/*
12
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
@@ -0,0 +1,9 @@
1
+ --no-private
2
+ --protected
3
+ --tag format:"Supported formats"
4
+ --tag authenticated:"Requires Authentication"
5
+ --tag rate_limited:"Rate Limited"
6
+ --markup markdown
7
+ -
8
+ HISTORY.mkd
9
+ LICENSE.mkd
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -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.
@@ -0,0 +1,144 @@
1
+ The Instagram Ruby Gem (adapted poorly but workingly by innonate - not the official gem!)
2
+ ====================
3
+ A Ruby wrapper for the Instagram REST and Search APIs
4
+
5
+
6
+ Installation
7
+ ------------
8
+ gem install instagram-innonate
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.
@@ -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,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/instagram/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.add_development_dependency('rspec', '~> 2.4')
6
+ s.add_development_dependency('webmock', '~> 1.6')
7
+ s.add_development_dependency('bluecloth', '~> 2.0.11')
8
+ s.add_runtime_dependency('faraday', '>= 0.5.4')
9
+ s.add_runtime_dependency('faraday_middleware', '>= 0.3.1')
10
+ s.add_runtime_dependency('multi_json', '>= 0.0.5')
11
+ s.add_runtime_dependency('hashie', '>= 0.4.0')
12
+ s.authors = ["Shayne Sweeney, Nate Westheimer"]
13
+ s.description = %q{A Ruby wrapper for the Instagram REST and Search APIs - adapted poorly but workingly by innonate.}
14
+ s.email = ['nate@innonate.com']
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.files = `git ls-files`.split("\n")
17
+ s.homepage = 'https://github.com/innonate/instagram-ruby-gem/'
18
+ s.name = 'instagram-innonate'
19
+ s.platform = Gem::Platform::RUBY
20
+ s.require_paths = ['lib']
21
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
22
+ s.rubyforge_project = s.name
23
+ s.summary = %q{Ruby wrapper for the Instagram API}
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.version = Instagram::VERSION.dup
26
+ end
@@ -0,0 +1,36 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Request::OAuth2 < Faraday::Middleware
7
+ def call(env)
8
+
9
+ if env[:method] == :get or env[:method] == :delete
10
+ env[:url].query_values = {} if env[:url].query_values.nil?
11
+ if @access_token and not env[:url].query_values["client_secret"]
12
+ env[:url].query_values = env[:url].query_values.merge(:access_token => @access_token)
13
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
14
+ elsif @client_id
15
+ env[:url].query_values = env[:url].query_values.merge(:client_id => @client_id)
16
+ end
17
+ else
18
+ if @access_token and not env[:body] && env[:body][:client_secret]
19
+ env[:body] = {} if env[:body].nil?
20
+ env[:body] = env[:body].merge(:access_token => @access_token)
21
+ env[:request_headers] = env[:request_headers].merge('Authorization' => "Token token=\"#{@access_token}\"")
22
+ elsif @client_id
23
+ env[:body] = env[:body] #.merge(:client_id => @client_id)
24
+ end
25
+ end
26
+
27
+ @app.call env
28
+ end
29
+
30
+ def initialize(app, client_id, access_token=nil)
31
+ @app = app
32
+ @client_id = client_id
33
+ @access_token = access_token
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp4xx < Response::Middleware
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ case response[:status].to_i
10
+ when 400
11
+ raise Instagram::BadRequest, error_message(response)
12
+ when 404
13
+ raise Instagram::NotFound, error_message(response)
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(app)
19
+ super
20
+ @parser = nil
21
+ end
22
+
23
+ private
24
+
25
+ def self.error_message(response)
26
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
27
+ end
28
+
29
+ def self.error_body(body)
30
+ if body.nil?
31
+ nil
32
+ elsif body['meta'] and body['meta']['error_message'] and not body['meta']['error_message'].empty?
33
+ ": #{body['meta']['error_message']}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module Faraday
5
+ # @private
6
+ class Response::RaiseHttp5xx < Response::Middleware
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ case response[:status].to_i
10
+ when 500
11
+ raise Instagram::InternalServerError, error_message(response, "Something is technically wrong.")
12
+ when 503
13
+ raise Instagram::ServiceUnavailable, error_message(response, "Instagram is rate limiting your requests.")
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(app)
19
+ super
20
+ @parser = nil
21
+ end
22
+
23
+ private
24
+
25
+ def self.error_message(response, body=nil)
26
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../instagram/error', __FILE__)
2
+ require File.expand_path('../instagram/configuration', __FILE__)
3
+ require File.expand_path('../instagram/api', __FILE__)
4
+ require File.expand_path('../instagram/client', __FILE__)
5
+
6
+ module Instagram
7
+ extend Configuration
8
+
9
+ # Alias for Instagram::Client.new
10
+ #
11
+ # @return [Instagram::Client]
12
+ def self.client(options={})
13
+ Instagram::Client.new(options)
14
+ end
15
+
16
+ # Delegate to Instagram::Client
17
+ def self.method_missing(method, *args, &block)
18
+ return super unless client.respond_to?(method)
19
+ client.send(method, *args, &block)
20
+ end
21
+
22
+ # Delegate to Instagram::Client
23
+ def self.respond_to?(method)
24
+ return client.respond_to?(method) || super
25
+ end
26
+ 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