Skip to content

Instantly share code, notes, and snippets.

@tigris
Created November 11, 2016 03:47
Show Gist options
  • Save tigris/8ef366412804cee97385e0ae156fa450 to your computer and use it in GitHub Desktop.
Save tigris/8ef366412804cee97385e0ae156fa450 to your computer and use it in GitHub Desktop.
Scrape untappd checkins
#!/usr/bin/env ruby
require 'json'
require 'open-uri'
class UntappdApi
attr_accessor :access_token
def url_for(user_id, max_id)
"https://api.untappd.com/v4/user/checkins/#{user_id}?access_token=#{access_token}&max_id=#{max_id}&limit=50"
end
def user_feed(user_id, max_id = '0')
Enumerator.new do |y|
loop do
data = open(url_for(user_id, max_id)).read
json = JSON.parse data
json['response']['checkins']['items'].map do |checkin|
y.yield(checkin)
end
max_id = json['response']['pagination']['max_id']
break if max_id == ''
end
end
end
end
client = UntappdApi.new.tap{|c| c.access_token = ENV['UNTAPPD_TOKEN'] }
client.user_feed('tigris666').each do |checkin|
puts checkin.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment