Class: MySportsFeeds

Inherits:
Object
  • Object
show all
Defined in:
lib/mysportsfeeds.rb

Overview

Main class for all interaction with the MySportsFeeds API

Instance Method Summary collapse

Constructor Details

#initialize(version = '1.0', verbose = False, store_type = 'file', store_location = 'results/') ⇒ MySportsFeeds

Constructor



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mysportsfeeds.rb', line 7

def initialize(version='1.0', verbose=False, store_type='file', store_location='results/')
    __verify_version(version)
    __verify_store(store_type, store_location)

    @version = version
    @verbose = verbose
    @store_type = store_type
    @store_location = store_location

    # Instantiate an instance of the appropriate API depending on version

    if @version == '1.0'
        @api_instance = Mysportsfeeds::Api::API_v1_0.new(@verbose, @store_type, @store_location)
    end
end

Instance Method Details

#__verify_store(store_type, store_location) ⇒ Object

Verify the type and location of the stored data



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mysportsfeeds.rb', line 30

def __verify_store(store_type, store_location)
    if !store_type.nil? and store_type != 'file'
        raiseException.new("Unrecognized storage type specified.  Supported values are: nil,'file'")
    end

    if store_type == 'file'
        if store_location.nil?
            raise Exception.new("Must specify a location for stored data.")
      end
    end
end

#__verify_version(version) ⇒ Object

Make sure the version is supported



23
24
25
26
27
# File 'lib/mysportsfeeds.rb', line 23

def __verify_version(version)
    if version != '1.0'
        raise Exception.new("Unrecognized version specified.  Supported versions are: '1.0'")
    end
end

#authenticate(username, password) ⇒ Object

Authenticate against the API (for v1.0)



43
44
45
46
47
48
49
# File 'lib/mysportsfeeds.rb', line 43

def authenticate(username, password)
    if !@api_instance.supports_basic_auth()
        raise Exception.new("BASIC authentication not supported for version " + @version)
    end

    @api_instance.set_auth_credentials(username, password)
end

#msf_get_data(league, season, feed, output_format, *kwargs) ⇒ Object

Request data (and store it if applicable)



52
53
54
# File 'lib/mysportsfeeds.rb', line 52

def msf_get_data(league, season, feed, output_format, *kwargs)
    return @api_instance.get_data(league, season, feed, output_format, kwargs)
end