Sha256: fe954e177caa3ac87c5df9928737c4462aafc0c09e638dab78174a23f5c54082
Contents?: true
Size: 1.2 KB
Versions: 9
Compression:
Stored size: 1.2 KB
Contents
module ApiUserAuth module Providers # Instagram class Instagram API_PATH = 'https://api.instagram.com/v1/users/self/'.freeze def initialize(token) @token = token @data = {} end def api_info_url params = { access_token: @token } URI("#{API_PATH}?#{params.to_query}") end def get_user_data api_get_request user_data end def user_data { id: @data[:id], name: @data[:full_name], email: "#{@data[:username]}@instagram.com", provider: 'instagram', img_url: @data[:profile_picture], info: {} } end def self.get_user(token) inst = Instagram.new(token) inst.get_user_data end private def api_get_request response = ::Net::HTTP.get_response(api_info_url) case response.code.to_i when 200 @data = JSON.parse(response.body, symbolize_names: true)[:data] when 400 raise ApiUserAuth::Exceptions::InvalidToken, 'Invalid Token' else raise ApiUserAuth::Exceptions::ProviderError, 'Provider Error' end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems