lib/mysportsfeeds/api/API_v1_0.rb
# Save a feed response based on the store_type
Save a feed response based on the store_type
Save a feed response based on the store_type
def __save_feed(response, league, season, feed, output_format, params)
                if output_format == "json"
                    store_output = JSON.parse(response)
                elsif output_format == "xml"
                    store_output = response
                elsif output_format == "csv"
                    store_output = response
                end
                if @store_type == "file"
                    if !File.exist?(@store_location)
                        FileUtils::mkdir_p(@store_location)
                    end
                    filename = __make_output_filename(league, season, feed, output_format, params)
                    outfile = File.open(@store_location + filename, "w")
                    if output_format == "json"  
                        json_out = response.to_json.gsub('\\', '').strip
                        outfile.write(json_out[1..json_out.size-2])
                    elsif output_format == "xml"  
                        outfile.write(store_output)
                    elsif output_format == "csv"  
                        outfile.write(store_output)
                    else
                        raise Exception.new("Could not interpret feed output format")
                    end
                end
            end
def __save_feed ( response , league , season , feed , output_format , params ) if output_format == "json" store_output = JSON . parse ( response ) elsif output_format == "xml" store_output = response elsif output_format == "csv" store_output = response end if @store_type == "file" if ! File . exist? ( @store_location ) FileUtils :: mkdir_p ( @store_location ) end filename = __make_output_filename ( league , season , feed , output_format , params ) outfile = File . open ( @store_location + filename , "w" ) if output_format == "json" json_out = response . to_json . gsub ( '\\' , '' ) . strip outfile . write ( json_out [ 1 .. json_out . size - 2 ] ) elsif output_format == "xml" outfile . write ( store_output ) elsif output_format == "csv" outfile . write ( store_output ) else raise Exception . new ( "Could not interpret feed output format" ) end end end
Save a feed response based on the store_type
Save a feed response based on the store_type
# Save to memory regardless of selected method # This is JSON # This is xml # This is csv
response
league
season
feed
output_format
params