Created
November 10, 2017 09:57
-
-
Save edipofederle/72adc2bf0e461d08320374a76e4ad3ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Airbnb | |
class AuthService | |
class << self | |
def authorize(username, password) | |
proxy = next_proxy | |
res = HTTParty.post(AIRBNB_AUTHORIZE_USER, http_proxyaddr: proxy[0], http_proxyport: proxy[1], | |
body: {client_id: CLIENT_ID, | |
username: username, | |
password: password, | |
grant_type: 'password'}, | |
headers: HEADERS) | |
if res.code.to_i == 200 || res.code.to_i == 420 | |
response = JSON.parse(res.body) | |
return response['access_token'] | |
end | |
raise RequestError.new("Cannot Authorize the user #{username}. #{res}") | |
end | |
private | |
def params(username, password) | |
{ | |
username: username, | |
password: password, | |
client_id: CLIENT_ID | |
} | |
end | |
def next_proxy | |
token = 'e5c18eb290a5c25e2613d70d5b2df58b616bb223a7a69694a09a0e6bfec809b5' | |
uri = "https://api.proxicity.io/v2/#{token}/proxy/?httpsSupport=true&isAnonymous=true" | |
res = HTTParty.get(uri).parsed_response | |
[res['ipAddress'], res['port']] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment