class Poke::API::Auth::PTC
Constants
- PTC_LOGIN_CLIENT_SECRET
- PTC_LOGIN_OAUTH
- PTC_LOGIN_URL
Attributes
access_token[R]
expiry[R]
provider[R]
Public Class Methods
new(username, password, _refresh_token)
click to toggle source
# File lib/poke-api/auth/ptc.rb, line 17 def initialize(username, password, _refresh_token) @username = username @password = password @provider = 'ptc' @client = HTTPClient.new(agent_name: 'PokeAPI/0.0.1') @expiry = 0 end
Public Instance Methods
connect()
click to toggle source
# File lib/poke-api/auth/ptc.rb, line 25 def connect resp = @client.get_content(PTC_LOGIN_URL) parsed_resp = JSON.parse(resp) data = { username: @username, password: @password, _eventId: 'submit', lt: parsed_resp['lt'], execution: parsed_resp['execution'] } fetch_ticket(data) end
Private Instance Methods
fetch_access_token(ticket)
click to toggle source
# File lib/poke-api/auth/ptc.rb, line 54 def fetch_access_token(ticket) logger.debug '[>] Fetching PTC access token' data = { client_id: 'mobile-app_pokemon-go', redirect_uri: 'https://www.nianticlabs.com/pokemongo/error', client_secret: PTC_LOGIN_CLIENT_SECRET, grant_type: 'refresh_token', code: ticket } resp = Hash[URI.decode_www_form(@client.post(PTC_LOGIN_OAUTH, data).body)] @access_token = resp['access_token'] @expiry = resp['expires'].to_i + Helpers.fetch_time(ms: false) end
fetch_ticket(data)
click to toggle source
# File lib/poke-api/auth/ptc.rb, line 42 def fetch_ticket(data) logger.debug '[>] Fetching PTC ticket' ticket = begin @client.post_content(PTC_LOGIN_URL, data) rescue StandardError => ex ex.res.http_header.request_uri.to_s.match(/ticket=(.*)/)[1] end fetch_access_token(ticket) end