Skip to content

Commit

Permalink
Merge pull request facebookarchive#139 from wishpond-dev/master
Browse files Browse the repository at this point in the history
Ratelimit support for responses from Instagram
  • Loading branch information
heatonjb committed Oct 24, 2014
2 parents b8f9e2c + e560777 commit d1f02d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/instagram/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def request(method, path, options, signature=false, raw=false, unformatted=false
end
return response if raw
return response.body if no_response_wrapper
return Response.create( response.body )
return Response.create( response.body, {:limit => response.headers['x-ratelimit-limit'].to_i,
:remaining => response.headers['x-ratelimit-remaining'].to_i} )
end

def formatted_path(path)
Expand Down
4 changes: 3 additions & 1 deletion lib/instagram/response.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
module Instagram
module Response
def self.create( response_hash )
def self.create( response_hash, ratelimit_hash )
data = response_hash.data.dup rescue response_hash
data.extend( self )
data.instance_exec do
@pagination = response_hash.pagination
@meta = response_hash.meta
@ratelimit = ::Hashie::Mash.new(ratelimit_hash)
end
data
end

attr_reader :pagination
attr_reader :meta
attr_reader :ratelimit
end
end

0 comments on commit d1f02d9

Please sign in to comment.