instagram_geo 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +144 -0
- data/Rakefile +27 -0
- data/lib/faraday/oauth2.rb +42 -0
- data/lib/faraday/raise_http_exception.rb +51 -0
- data/lib/instagram/api.rb +23 -0
- data/lib/instagram/client.rb +20 -0
- data/lib/instagram/client/comments.rb +62 -0
- data/lib/instagram/client/geographies.rb +29 -0
- data/lib/instagram/client/likes.rb +58 -0
- data/lib/instagram/client/locations.rb +59 -0
- data/lib/instagram/client/media.rb +63 -0
- data/lib/instagram/client/subscriptions.rb +158 -0
- data/lib/instagram/client/tags.rb +59 -0
- data/lib/instagram/client/users.rb +309 -0
- data/lib/instagram/client/utils.rb +15 -0
- data/lib/instagram/configuration.rb +90 -0
- data/lib/instagram/connection.rb +31 -0
- data/lib/instagram/error.rb +19 -0
- data/lib/instagram/oauth.rb +27 -0
- data/lib/instagram/request.rb +45 -0
- data/lib/instagram/version.rb +3 -0
- data/lib/instagram_geo.rb +26 -0
- metadata +195 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
module Instagram
|
2
|
+
class Client
|
3
|
+
# @private
|
4
|
+
module Utils
|
5
|
+
private
|
6
|
+
|
7
|
+
# Returns the configured user name or the user name of the authenticated user
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
def get_username
|
11
|
+
@user_name ||= self.user.username
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module Instagram
|
5
|
+
# Defines constants and methods related to configuration
|
6
|
+
module Configuration
|
7
|
+
# An array of valid keys in the options hash when configuring a {Instagram::API}
|
8
|
+
VALID_OPTIONS_KEYS = [
|
9
|
+
:adapter,
|
10
|
+
:client_id,
|
11
|
+
:client_secret,
|
12
|
+
:access_token,
|
13
|
+
:endpoint,
|
14
|
+
:format,
|
15
|
+
:user_agent,
|
16
|
+
:proxy
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
# An array of valid request/response formats
|
20
|
+
#
|
21
|
+
# @note Not all methods support the XML format.
|
22
|
+
VALID_FORMATS = [
|
23
|
+
:json].freeze
|
24
|
+
|
25
|
+
# The adapter that will be used to connect if none is set
|
26
|
+
#
|
27
|
+
# @note The default faraday adapter is Net::HTTP.
|
28
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
29
|
+
|
30
|
+
# By default, don't set an application ID
|
31
|
+
DEFAULT_CLIENT_ID = nil
|
32
|
+
|
33
|
+
# By default, don't set an application secret
|
34
|
+
DEFAULT_CLIENT_SECRET = nil
|
35
|
+
|
36
|
+
# By default, don't set an application redirect uri
|
37
|
+
DEFAULT_REDIRECT_URI = nil
|
38
|
+
|
39
|
+
# By default, don't set a user access token
|
40
|
+
DEFAULT_ACCESS_TOKEN = nil
|
41
|
+
|
42
|
+
# The endpoint that will be used to connect if none is set
|
43
|
+
#
|
44
|
+
# @note There is no reason to use any other endpoint at this time
|
45
|
+
DEFAULT_ENDPOINT = 'https://api.instagram.com/v1/'.freeze
|
46
|
+
|
47
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
48
|
+
#
|
49
|
+
# @note JSON is the only available format at this time
|
50
|
+
DEFAULT_FORMAT = :json
|
51
|
+
|
52
|
+
# By default, don't use a proxy server
|
53
|
+
DEFAULT_PROXY = nil
|
54
|
+
|
55
|
+
# The user agent that will be sent to the API endpoint if none is set
|
56
|
+
DEFAULT_USER_AGENT = "Instagram Ruby Gem #{Instagram::VERSION}".freeze
|
57
|
+
|
58
|
+
# @private
|
59
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
60
|
+
|
61
|
+
# When this module is extended, set all configuration options to their default values
|
62
|
+
def self.extended(base)
|
63
|
+
base.reset
|
64
|
+
end
|
65
|
+
|
66
|
+
# Convenience method to allow configuration options to be set in a block
|
67
|
+
def configure
|
68
|
+
yield self
|
69
|
+
end
|
70
|
+
|
71
|
+
# Create a hash of options and their values
|
72
|
+
def options
|
73
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
74
|
+
option.merge!(key => send(key))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Reset all configuration options to defaults
|
79
|
+
def reset
|
80
|
+
self.adapter = DEFAULT_ADAPTER
|
81
|
+
self.client_id = DEFAULT_CLIENT_ID
|
82
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
83
|
+
self.access_token = DEFAULT_ACCESS_TOKEN
|
84
|
+
self.endpoint = DEFAULT_ENDPOINT
|
85
|
+
self.format = DEFAULT_FORMAT
|
86
|
+
self.user_agent = DEFAULT_USER_AGENT
|
87
|
+
self.proxy = DEFAULT_PROXY
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module Instagram
|
5
|
+
# @private
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection(raw=false)
|
10
|
+
options = {
|
11
|
+
:headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
|
12
|
+
:proxy => proxy,
|
13
|
+
:ssl => {:verify => false},
|
14
|
+
:url => endpoint,
|
15
|
+
}
|
16
|
+
|
17
|
+
Faraday::Connection.new(options) do |connection|
|
18
|
+
connection.use FaradayMiddleware::OAuth2, client_id, access_token
|
19
|
+
connection.use Faraday::Request::UrlEncoded
|
20
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
21
|
+
unless raw
|
22
|
+
case format.to_s.downcase
|
23
|
+
when 'json' then connection.use Faraday::Response::ParseJson
|
24
|
+
end
|
25
|
+
end
|
26
|
+
connection.use FaradayMiddleware::RaiseHttpException
|
27
|
+
connection.adapter(adapter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Instagram
|
2
|
+
# Custom error class for rescuing from all Instagram errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Instagram returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Instagram returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when Instagram returns the HTTP status code 500
|
12
|
+
class InternalServerError < Error; end
|
13
|
+
|
14
|
+
# Raised when Instagram returns the HTTP status code 503
|
15
|
+
class ServiceUnavailable < Error; end
|
16
|
+
|
17
|
+
# Raised when a subscription payload hash is invalid
|
18
|
+
class InvalidSignature < Error; end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Instagram
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module OAuth
|
4
|
+
# Return URL for OAuth authorization
|
5
|
+
def authorize_url(options={})
|
6
|
+
options[:response_type] ||= "code"
|
7
|
+
params = access_token_params.merge(options)
|
8
|
+
connection.build_url("/oauth/authorize/", params).to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
# Return an access token from authorization
|
12
|
+
def get_access_token(code, options={})
|
13
|
+
options[:grant_type] ||= "authorization_code"
|
14
|
+
params = access_token_params.merge(options)
|
15
|
+
post("/oauth/access_token/", params.merge(:code => code), raw=false, unformatted=true)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def access_token_params
|
21
|
+
{
|
22
|
+
:client_id => client_id,
|
23
|
+
:client_secret => client_secret
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Instagram
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options={}, raw=false, unformatted=false)
|
6
|
+
request(:get, path, options, raw, unformatted)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options={}, raw=false, unformatted=false)
|
11
|
+
request(:post, path, options, raw, unformatted)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options={}, raw=false, unformatted=false)
|
16
|
+
request(:put, path, options, raw, unformatted)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options={}, raw=false, unformatted=false)
|
21
|
+
request(:delete, path, options, raw, unformatted)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Perform an HTTP request
|
27
|
+
def request(method, path, options, raw=false, unformatted=false)
|
28
|
+
response = connection(raw).send(method) do |request|
|
29
|
+
path = formatted_path(path) unless unformatted
|
30
|
+
case method
|
31
|
+
when :get, :delete
|
32
|
+
request.url(path, options)
|
33
|
+
when :post, :put
|
34
|
+
request.path = path
|
35
|
+
request.body = options unless options.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
raw ? response : response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def formatted_path(path)
|
42
|
+
[path, format].compact.join('.')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instagram_geo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shayne Sweeney
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.4'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.4'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: webmock
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.6'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.6'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bluecloth
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.11
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.11
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: faraday
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.7'
|
70
|
+
- - <
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0.9'
|
73
|
+
type: :runtime
|
74
|
+
prerelease: false
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0.7'
|
81
|
+
- - <
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.9'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: faraday_middleware
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.8'
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.8'
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: multi_json
|
102
|
+
requirement: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 1.0.3
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
type: :runtime
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.0.3
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.0'
|
122
|
+
- !ruby/object:Gem::Dependency
|
123
|
+
name: hashie
|
124
|
+
requirement: !ruby/object:Gem::Requirement
|
125
|
+
none: false
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 0.4.0
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.4.0
|
138
|
+
description: A Ruby wrapper for the Instagram REST and Search APIs with geosearch
|
139
|
+
email:
|
140
|
+
- shayne@instagr.am
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- lib/faraday/oauth2.rb
|
146
|
+
- lib/faraday/raise_http_exception.rb
|
147
|
+
- lib/instagram/api.rb
|
148
|
+
- lib/instagram/client/comments.rb
|
149
|
+
- lib/instagram/client/geographies.rb
|
150
|
+
- lib/instagram/client/likes.rb
|
151
|
+
- lib/instagram/client/locations.rb
|
152
|
+
- lib/instagram/client/media.rb
|
153
|
+
- lib/instagram/client/subscriptions.rb
|
154
|
+
- lib/instagram/client/tags.rb
|
155
|
+
- lib/instagram/client/users.rb
|
156
|
+
- lib/instagram/client/utils.rb
|
157
|
+
- lib/instagram/client.rb
|
158
|
+
- lib/instagram/configuration.rb
|
159
|
+
- lib/instagram/connection.rb
|
160
|
+
- lib/instagram/error.rb
|
161
|
+
- lib/instagram/oauth.rb
|
162
|
+
- lib/instagram/request.rb
|
163
|
+
- lib/instagram/version.rb
|
164
|
+
- lib/instagram_geo.rb
|
165
|
+
- Gemfile
|
166
|
+
- LICENSE.md
|
167
|
+
- Rakefile
|
168
|
+
- README.md
|
169
|
+
homepage: https://github.com/Instagram/instagram-ruby-gem
|
170
|
+
licenses: []
|
171
|
+
post_install_message: ! "********************************************************************************\n\n
|
172
|
+
\ Follow @instagram on Twitter for announcements, updates, and news.\n https://twitter.com/instagramapi\n\n
|
173
|
+
\ Join the mailing list!\n https://groups.google.com/group/instagram-ruby-gem\n\n********************************************************************************\n"
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
none: false
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 1.3.6
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project: instagram_geo
|
191
|
+
rubygems_version: 1.8.25
|
192
|
+
signing_key:
|
193
|
+
specification_version: 3
|
194
|
+
summary: Ruby wrapper for the Instagram API with geosearch
|
195
|
+
test_files: []
|