instagram 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/instagram.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.add_runtime_dependency('faraday_middleware', '~> 0.3.1')
14
14
  s.add_runtime_dependency('multi_json', '~> 0.0.5')
15
15
  s.add_runtime_dependency('hashie', '~> 1.0.0')
16
+ s.add_runtime_dependency('ruby-hmac', '~> 0.4.0')
16
17
  s.authors = ["Shayne Sweeney"]
17
18
  s.description = %q{A Ruby wrapper for the Instagram REST and Search APIs}
18
19
  s.post_install_message =<<eos
@@ -1,3 +1,5 @@
1
+ require 'hmac-sha1'
2
+
1
3
  module Instagram
2
4
  class Client
3
5
  # Defines methods related to real-time
@@ -98,6 +100,7 @@ module Instagram
98
100
  # @overload process_subscription(json, &block)
99
101
  # @param json [String] The JSON response received by the Instagram real-time server
100
102
  # @param block [Proc] A callable in which callbacks are defined
103
+ # @option options [String] :signature Pass in an X-Hub-Signature to use for payload validation
101
104
  # @return [nil]
102
105
  # @example Process and handle a notification for a user media change
103
106
  # Instagram.process_subscription(params[:body]) do |handler|
@@ -117,8 +120,20 @@ module Instagram
117
120
  # Requires client_secret to be set on the client or passed in options
118
121
  # @rate_limited true
119
122
  # @see https://api.instagram.com/developer/realtime/
120
- def process_subscription(json, &block)
123
+ def process_subscription(json, options={}, &block)
121
124
  raise ArgumentError, "callbacks block expected" unless block_given?
125
+
126
+ if options[:signature]
127
+ if !client_secret
128
+ raise ArgumentError, "client_secret must be set during configure"
129
+ end
130
+ verify_signature = HMAC::SHA1.hexdigest(client_secret, json)
131
+
132
+ if options[:signature] != verify_signature
133
+ raise Instagram::InvalidSignature, "invalid X-Hub-Signature does not match verify signature against client_secret"
134
+ end
135
+ end
136
+
122
137
  payload = MultiJson.decode(json)
123
138
  @changes = Hash.new { |h,k| h[k] = [] }
124
139
  for change in payload
@@ -13,4 +13,7 @@ module Instagram
13
13
 
14
14
  # Raised when Instagram returns the HTTP status code 503
15
15
  class ServiceUnavailable < Error; end
16
+
17
+ # Raised when a subscription payload hash is invalid
18
+ class InvalidSignature < Error; end
16
19
  end
@@ -1,3 +1,3 @@
1
1
  module Instagram
2
- VERSION = '0.6'.freeze unless defined?(::Instagram::VERSION)
2
+ VERSION = '0.6.1'.freeze unless defined?(::Instagram::VERSION)
3
3
  end
@@ -113,6 +113,36 @@ describe Instagram::Client do
113
113
  end
114
114
  end
115
115
  end
116
+
117
+ context "with a valid signature" do
118
+
119
+ before do
120
+ @json = fixture("subscription_payload.json").read
121
+ end
122
+
123
+ it "should not raise an Instagram::InvalidSignature error" do
124
+ lambda do
125
+ @client.process_subscription(@json, :signature => "f1dbe2b6184ac2131209c87bba8e0382d089a8a2") do |handler|
126
+ # hi
127
+ end
128
+ end.should_not raise_error(Instagram::InvalidSignature)
129
+ end
130
+ end
131
+
132
+ context "with an invalid signature" do
133
+
134
+ before do
135
+ @json = fixture("subscription_payload.json").read
136
+ end
137
+
138
+ it "should raise an Instagram::InvalidSignature error" do
139
+ lambda do
140
+ @client.process_subscription(@json, :signature => "31337H4X0R") do |handler|
141
+ # hi
142
+ end
143
+ end.should raise_error(Instagram::InvalidSignature)
144
+ end
145
+ end
116
146
  end
117
147
  end
118
148
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start do
3
- add_group 'Instagram', 'lib/Instagram'
3
+ add_group 'Instagram', 'lib/instagram'
4
4
  add_group 'Faraday Middleware', 'lib/faraday'
5
5
  add_group 'Specs', 'spec'
6
6
  end
7
7
 
8
- require File.expand_path('../../lib/Instagram', __FILE__)
8
+ require File.expand_path('../../lib/instagram', __FILE__)
9
9
 
10
10
  require 'rspec'
11
11
  require 'webmock/rspec'
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- version: "0.6"
8
+ - 1
9
+ version: 0.6.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Shayne Sweeney
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2011-02-24 00:00:00 -08:00
17
+ date: 2011-03-04 00:00:00 -08:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
@@ -174,6 +175,21 @@ dependencies:
174
175
  version: 1.0.0
175
176
  type: :runtime
176
177
  version_requirements: *id011
178
+ - !ruby/object:Gem::Dependency
179
+ name: ruby-hmac
180
+ prerelease: false
181
+ requirement: &id012 !ruby/object:Gem::Requirement
182
+ none: false
183
+ requirements:
184
+ - - ~>
185
+ - !ruby/object:Gem::Version
186
+ segments:
187
+ - 0
188
+ - 4
189
+ - 0
190
+ version: 0.4.0
191
+ type: :runtime
192
+ version_requirements: *id012
177
193
  description: A Ruby wrapper for the Instagram REST and Search APIs
178
194
  email:
179
195
  - shayne@instagr.am