instagram-fixed 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 +145 -0
  7. data/Rakefile +27 -0
  8. data/instagram.gemspec +37 -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 +253 -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,145 @@
1
+ The Instagram Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Instagram REST and Search APIs
4
+
5
+ ***This is fixed to not have dodgy dependencies...***
6
+
7
+ Installation
8
+ ------------
9
+ gem install instagram
10
+
11
+
12
+ Follow @instagramapi on Twitter
13
+ ----------------------------
14
+ You should [follow @instagramapi on Twitter](http://twitter.com/#!/instagramapi) for announcements,
15
+ updates, and news about the Instagram gem.
16
+
17
+
18
+ Join the mailing list!
19
+ ----------------------
20
+ <https://groups.google.com/group/instagram-ruby-gem>
21
+
22
+
23
+ Does your project or organization use this gem?
24
+ -----------------------------------------------
25
+ Add it to the [apps](http://github.com/Instagram/instagram-ruby-gem/wiki/apps) wiki!
26
+
27
+
28
+ Sample Application
29
+ ------------------
30
+ require "sinatra"
31
+ require "instagram"
32
+
33
+ enable :sessions
34
+
35
+ CALLBACK_URL = "http://localhost:4567/oauth/callback"
36
+
37
+ Instagram.configure do |config|
38
+ config.client_id = "YOUR_CLIENT_ID"
39
+ config.client_secret = "YOUR_CLIENT_SECRET"
40
+ end
41
+
42
+ get "/" do
43
+ '<a href="/oauth/connect">Connect with Instagram</a>'
44
+ end
45
+
46
+ get "/oauth/connect" do
47
+ redirect Instagram.authorize_url(:redirect_uri => CALLBACK_URL)
48
+ end
49
+
50
+ get "/oauth/callback" do
51
+ response = Instagram.get_access_token(params[:code], :redirect_uri => CALLBACK_URL)
52
+ session[:access_token] = response.access_token
53
+ redirect "/feed"
54
+ end
55
+
56
+ get "/feed" do
57
+ client = Instagram.client(:access_token => session[:access_token])
58
+ user = client.user
59
+
60
+ html = "<h1>#{user.username}'s recent photos</h1>"
61
+ for media_item in client.user_recent_media
62
+ html << "<img src='#{media_item.images.thumbnail.url}'>"
63
+ end
64
+ html
65
+ end
66
+
67
+
68
+ API Usage Examples
69
+ ------------------
70
+ require "rubygems"
71
+ require "instagram"
72
+
73
+ # Get a list of a user's most recent media
74
+ puts Instagram.user_recent_media(777)
75
+
76
+ # Get the currently authenticated user's media feed
77
+ puts Instagram.user_media_feed
78
+
79
+ # Get a list of recent media at a given location, in this case, the Instagram office
80
+ puts Instagram.location_recent_media(514276)
81
+
82
+ # All methods require authentication (either by client ID or access token).
83
+ # To get your Instagram OAuth credentials, register an app at http://instagr.am/oauth/client/register/
84
+ Instagram.configure do |config|
85
+ config.client_id = YOUR_CLIENT_KEY
86
+ config.access_token = YOUR_ACCESS_TOKEN
87
+ end
88
+
89
+ # Get a list of all the users you're following
90
+ puts Instagram.follows
91
+
92
+ # Get a list of media close to a given latitude and longitude
93
+ puts Instagram.media_search("37.7808851,-122.3948632")
94
+
95
+ # Get a list of the overall most popular media items
96
+ puts Instagram.media_popular
97
+
98
+ # Search for users on instagram, by name or username
99
+ puts Instagram.user_search("shayne sweeney")
100
+
101
+
102
+ Contributing
103
+ ------------
104
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
105
+
106
+ Here are some ways *you* can contribute:
107
+
108
+ * by using alpha, beta, and prerelease versions
109
+ * by reporting bugs
110
+ * by suggesting new features
111
+ * by writing or editing documentation
112
+ * by writing specifications
113
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
114
+ * by refactoring code
115
+ * by closing [issues](http://github.com/Instagram/instagram-ruby-gem/issues)
116
+ * by reviewing patches
117
+
118
+
119
+ Submitting an Issue
120
+ -------------------
121
+ We use the [GitHub issue tracker](http://github.com/Instagram/instagram-ruby-gem/issues) to track bugs and
122
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
123
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
124
+ bug report, please include a [Gist](http://gist.github.com/) that includes a stack trace and any
125
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
126
+ operating system. Ideally, a bug report should include a pull request with failing specs.
127
+
128
+
129
+ Submitting a Pull Request
130
+ -------------------------
131
+ 1. Fork the project.
132
+ 2. Create a topic branch.
133
+ 3. Implement your feature or bug fix.
134
+ 4. Add documentation for your feature or bug fix.
135
+ 5. Run <tt>rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
136
+ 6. Add specs for your feature or bug fix.
137
+ 7. Run <tt>rake spec</tt>. If your changes are not 100% covered, go back to step 6.
138
+ 8. Commit and push your changes.
139
+ 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.)
140
+
141
+
142
+ Copyright
143
+ ---------
144
+ Copyright (c) 2011 Instagram (Burbn, Inc).
145
+ 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,37 @@
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')
9
+ s.add_runtime_dependency('faraday_middleware')
10
+ s.add_runtime_dependency('multi_json')
11
+ s.add_runtime_dependency('hashie')
12
+ s.authors = ["Shayne Sweeney"]
13
+ s.description = %q{A Ruby wrapper for the Instagram REST and Search APIs}
14
+ s.post_install_message =<<eos
15
+ ********************************************************************************
16
+
17
+ Follow @instagram on Twitter for announcements, updates, and news.
18
+ https://twitter.com/instagramapi
19
+
20
+ Join the mailing list!
21
+ https://groups.google.com/group/instagram-ruby-gem
22
+
23
+ ********************************************************************************
24
+ eos
25
+ s.email = ['shayne@instagr.am']
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.files = `git ls-files`.split("\n")
28
+ s.homepage = 'https://github.com/Instagram/instagramrb'
29
+ s.name = 'instagram-fixed'
30
+ s.platform = Gem::Platform::RUBY
31
+ s.require_paths = ['lib']
32
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
33
+ s.rubyforge_project = s.name
34
+ s.summary = %q{Ruby wrapper for the Instagram API}
35
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
+ s.version = Instagram::VERSION.dup
37
+ 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