-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.rb
More file actions
51 lines (40 loc) · 1.15 KB
/
Copy pathserver.rb
File metadata and controls
51 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'sinatra'
require 'json'
require 'open-uri'
require 'lightly'
lightly = Lightly.new life: 86400
set :public_folder, File.dirname(__FILE__) + '/dist'
# bearer token seems to be hardcoded for logged out users
authorization = "Bearer 7356455548d0a1d886db010883388d08be84d0c9"
# api seems to 403 on requests with no user-agent
user_agent = "vsco-map"
headers = { 'Authorization' => authorization, 'User-Agent' => user_agent }
get '/' do
send_file File.join(settings.public_folder, 'index.html')
end
get '/ping' do
'pong'
end
get '/users/:user' do
content_type :json
lightly.get params['user'] do
puts params['user']
user = params['user']
begin
sites = JSON.load open "https://vsco.co/api/2.0/sites?subdomain=#{user}", headers
site_id = sites['sites'][0]['id']
rescue OpenURI::HTTPError => e
return 404, 'user not found' if e.message == "404 Not Found"
end
page = 1
size = 99
images = []
loop do
response = JSON.load open "https://vsco.co/api/2.0/medias?site_id=#{site_id}&page=#{page}&size=#{size}", headers
images.concat response['media']
break if response['total'] <= page * size
page += 1
end
images.to_json
end
end