class Asianodds::Login

Attributes

ao_key[R]
ao_token[R]
base_url[R]
code[R]
message[R]
successful_login[R]

Public Class Methods

new(user, password) click to toggle source

Initialize the user with a username and password, as well as hashed password as requested from AO

# File lib/asianodds/login.rb, line 36
def initialize(user, password)
  @user = user
  @password = password
  @password_md5 = Digest::MD5.hexdigest(@password)
  @ao_token = 'default'
  @ao_key = 'default'
  @base_url = BASE_API_URL
  login
end

Public Instance Methods

get_account_summary() click to toggle source

Get the users account summary (i.e. users currency, users credit, outstanding amount, P&L’s etc.)

# File lib/asianodds/login.rb, line 140
def get_account_summary
  if loggedin?
    return get_request('GetAccountSummary')
  else
    #raise NotLoggedIn
  end
end
get_bet_by_reference(bet_reference) click to toggle source

You can also request a single bet with its reference - useful to check whether the bet was accepted by the bookmaker

# File lib/asianodds/login.rb, line 113
def get_bet_by_reference(bet_reference)
  if loggedin?
    return get_request("GetBetByReference?betReference=#{bet_reference}")
  else
    #raise NotLoggedIn
  end
end
get_bet_history_summary(attributes) click to toggle source

Get all the transactions of a specific day (defaults to yesterday) including win and loss values

# File lib/asianodds/login.rb, line 179
def get_bet_history_summary(attributes)
  attributes[:date].nil? ? date = (Date.today - 1).strftime('%m/%d/%Y') : date = attributes[:date]
  attributes[:bookies].nil? ? bookies = 'ALL' : bookies = attributes[:bookies]
  if loggedin?
    return get_request("GetBetHistorySummary?date=#{date}&bookies=#{bookies}")
  else
    #raise NotLoggedIn
  end
end
get_bets() click to toggle source

Get all active bets (= running, outstanding, finished) of the current user

# File lib/asianodds/login.rb, line 104
def get_bets
  if loggedin?
    return get_request('GetBets')
  else
    #raise NotLoggedIn
  end
end
get_bookies() click to toggle source

Get the list of bookmakers available on the Asianodds platform

# File lib/asianodds/login.rb, line 161
def get_bookies
  if loggedin?
    return get_request('GetBookies')
  else
    #raise NotLoggedIn
  end
end
get_feeds(attributes) click to toggle source

Get all the Match Feeds (odds, status, etc.) based on the settings provided

# File lib/asianodds/login.rb, line 88
def get_feeds(attributes)
  attributes[:sports_type].nil? ? sports_type = 1 : sports_type = attributes[:sports_type]
  attributes[:market_type].nil? ? market_type = 1 : market_type = attributes[:market_type]
  attributes[:bookies].nil? ? bookies = 'ALL' : bookies = attributes[:bookies]
  attributes[:leagues].nil? ? leagues = 'ALL' : leagues = attributes[:leagues]
  attributes[:odds_format].nil? ? odds_format = '00' : odds_format = attributes[:odds_format]
  attributes[:since].nil? ? since = '0' : since = attributes[:since]

  if loggedin?
    return get_request("GetFeeds?sportsType=#{sports_type}&marketTypeId=#{market_type}&bookies=#{bookies}&leagues=#{leagues}&oddsFormat=#{odds_format}&since=#{since}")
  else
    #raise NotLoggedIn
  end
end
get_history_statement(attributes) click to toggle source

Get a transaction history of a certain time-frame - defaults to the last 7 days

# File lib/asianodds/login.rb, line 149
def get_history_statement(attributes)
  attributes[:from_date].nil? ? from_date = (Date.today - 7).strftime('%m/%d/%Y') : from_date = attributes[:from_date]
  attributes[:to_date].nil? ? to_date = Date.today.strftime('%m/%d/%Y') : to_date = attributes[:to_date]
  attributes[:bookies].nil? ? bookies = 'ALL' : bookies = attributes[:bookies]
  if loggedin?
    return get_request("GetHistoryStatement?from=#{from_date}&to=#{to_date}&bookies=#{bookies}&shouldHideTransactionData=false")
  else
    #raise NotLoggedIn
  end
end
get_leagues(attributes) click to toggle source

Get the ids for all leagues for a certain sport (football as default)

# File lib/asianodds/login.rb, line 190
def get_leagues(attributes)
  attributes[:sports_type].nil? ? sports_type = 1 : sports_type = attributes[:sports_type]
  attributes[:market_type].nil? ? market_type = 1 : market_type = attributes[:market_type]
  attributes[:bookies].nil? ? bookies = 'ALL' : bookies = attributes[:bookies]
  attributes[:since].nil? ? since = '0' : since = attributes[:since]
  if loggedin?
    return get_request("GetLeagues?sportsType=#{sports_type}&marketTypeId=#{market_type}&bookies=#{bookies}&since=#{since}")
  else
    #raise NotLoggedIn
  end
end
get_matches(attributes) click to toggle source

Get all the Matches (!= feeds) based on the settings provided

# File lib/asianodds/login.rb, line 212
def get_matches(attributes)
  attributes[:sports_type].nil? ? sports_type = 1 : sports_type = attributes[:sports_type]
  attributes[:market_type].nil? ? market_type = 1 : market_type = attributes[:market_type]
  attributes[:bookies].nil? ? bookies = 'ALL' : bookies = attributes[:bookies]
  attributes[:leagues].nil? ? leagues = 'ALL' : leagues = attributes[:leagues]
  attributes[:since].nil? ? since = '0' : since = attributes[:since]

  if loggedin?
    return get_request("GetMatches?sportsType=#{sports_type}&marketTypeId=#{market_type}&bookies=#{bookies}&leagues=#{leagues}&since=#{since}")
  else
    #raise NotLoggedIn
  end
end
get_non_running_bets() click to toggle source

A subset of GetBets which returns only the currently not running bets

# File lib/asianodds/login.rb, line 131
def get_non_running_bets
  if loggedin?
    return get_request('GetNonRunningBets')
  else
    #raise NotLoggedIn
  end
end
get_placement_info(attributes) click to toggle source

Get information about the odds, minimum and maximum amounts to bet etc. for a certain match THIS IS A POST REQUEST

# File lib/asianodds/login.rb, line 228
def get_placement_info(attributes)
  body = {
    "GameId": attributes[:game_id],
    "GameType": attributes[:game_type],
    "IsFullTime": attributes[:is_full_time],
    "Bookies": attributes[:bookies],
    "MarketTypeId": attributes[:market_type],
    "OddsFormat": attributes[:odds_format],
    "OddsName": attributes[:odds_name],
    "SportsType": attributes[:sports_type]
  }.to_json

  if loggedin?
    return post_request('GetPlacementInfo', body)
  else
    #raise NotLoggedIn
  end
end
get_request(route) click to toggle source

The API has a very standard request format for get requests - Use this one to stay DRY

# File lib/asianodds/login.rb, line 13
def get_request(route)
  response = Faraday.get "#{@base_url}/#{route}", {}, {
    'Accept': 'application/json',
    'AOToken': @ao_token,
    'AOKey': @ao_key
  }
  return JSON.parse(response.body, :symbolize_names => true)
end
get_running_bets() click to toggle source

A subset of GetBets which returns only the currently running bets

# File lib/asianodds/login.rb, line 122
def get_running_bets
  if loggedin?
    return get_request('GetRunningBets')
  else
    #raise NotLoggedIn
  end
end
get_sports() click to toggle source

Get the ids for the sports offered by Asianodds (football and basketball as of today)

# File lib/asianodds/login.rb, line 203
def get_sports
  if loggedin?
    return get_request('GetSports')
  else
    #raise NotLoggedIn
  end
end
get_user_information() click to toggle source

Get user setting, such as account status, ip address, username etc.

# File lib/asianodds/login.rb, line 170
def get_user_information
  if loggedin?
    return get_request('GetUserInformation')
  else
    #raise NotLoggedIn
  end
end
loggedin?() click to toggle source

Before executing any request which requires a logged in user (all), check for login Check for all following requests whether user is logged in and if not, log her in

# File lib/asianodds/login.rb, line 72
def loggedin?
  if @ao_token
    response = get_request('IsLoggedIn')
    return response[:Result][:CurrentlyLoggedIn] ? true : false
  else
    return false
  end
end
login() click to toggle source

Log the user in to receive a token and key

# File lib/asianodds/login.rb, line 47
def login
  response = get_request("Login?username=#{@user}&password=#{@password_md5}")
  @code = response[:Code]
  @ao_token = response[:Result][:Token]
  @ao_key = response[:Result][:Key]
  @base_url = response[:Result][:Url]
  @successful_login = response[:Result][:SuccessfulLogin]

  # All logged in users need to be registered with a token and key
  if @successful_login
    @message = "You successfully logged in - registering..."
    register
  else
    @message = response[:Result][:TextMessage]
  end
end
logout() click to toggle source

Log the user out. In order for this to work, the user must be logged in

# File lib/asianodds/login.rb, line 82
def logout
  response = get_request('Logout')
  return response[:Result]
end
place_bet(attributes) click to toggle source

Get information about the odds, minimum and maximum amounts to bet etc. for a certain match THIS IS A POST REQUEST

# File lib/asianodds/login.rb, line 249
def place_bet(attributes)
  body = {
    "GameId": attributes[:game_id],
    "GameType": attributes[:game_type],
    "IsFullTime": attributes[:is_full_time],
    "Bookies": attributes[:bookies],
    "MarketTypeId": attributes[:market_type],
    "OddsFormat": attributes[:odds_format],
    "OddsName": attributes[:odds_name],
    "SportsType": attributes[:sports_type],
    "BookieOdds": attributes[:bookie_odds],
    "Amount": attributes[:amount]
  }.to_json

  if loggedin?
    # Always needs to be called before placing the bet
    get_placement_info(attributes)
    return post_request('PlaceBet', body)
  else
    #raise NotLoggedIn
  end
end
post_request(route, body) click to toggle source

The API has a very standard request format for post requests - Use this one to stay DRY

# File lib/asianodds/login.rb, line 23
def post_request(route, body)
  response = Faraday.post "#{@base_url}/#{route}",
  body,
  {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'AOToken': @ao_token
  }

  return JSON.parse(response.body, :symbolize_names => true)
end
register() click to toggle source

With the token and key the user has to be registered

# File lib/asianodds/login.rb, line 65
def register
  response = get_request("Register?username=#{@user}")
  response[:Result][:Success] == true ? @message = response[:Result][:TextMessage] : @message = "Registration failed"
end