class Gamewisp::Client

Attributes

auth[RW]
token_store[RW]

Public Class Methods

new() click to toggle source
Only works if this class is derived (includes) HTTParty

if ENV

debug_output $stdout

end

# File lib/gamewisp/client.rb, line 26
def initialize
  self.token_store = TokenStore.new
  self.auth = Authorizer.new 'createauth', self.token_store
end

Public Instance Methods

authorize() click to toggle source
# File lib/gamewisp/client.rb, line 31
def authorize
  puts "Visit the following URL in your browser and authorize #{token_store.app_name} to access your subscription metrics"
  puts "   #{auth.app_authorization_url}"
  puts

  server = auth.create_server_instance
  auth_result = server.get_authentication_token

  puts auth_result
  if auth_result["code"]
    puts "Authorization received"
  else
    raise GamewispError, "Authorization failed."
  end

  auth.renew_tokens_with_auth_code auth_result["code"]
end
get_subscribers() click to toggle source
# File lib/gamewisp/client.rb, line 57
def get_subscribers
  url = "https://api.gamewisp.com/pub/v1/channel/subscribers"

  dbg "Client.get_subscribers [access_token]", token_store.access_token

  response = HTTParty
    .get(url,
        :query => {
          :access_token => token_store.access_token,
          :include => 'user,channel,benefits',
        }
      )

  dbg "Client.get_subscribers [response.code]", response.code
  dbg "Client.get_subscribers [response]", response

  response
end
renew_access_token() click to toggle source
# File lib/gamewisp/client.rb, line 49
def renew_access_token
  if token_store.refresh_token.nil? || token_store.refresh_token.empty?
    return authorize
  end

  auth.renew_tokens_with_refresh_token token_store.refresh_token
end