lib/gattica.rb
# Creates a valid query string for GA
Creates a valid query string for GA
Creates a valid query string for GA
def build_query_string(args,profile)
      output = "ids=ga:#{profile}&start-date=#{args[:start_date]}&end-date=#{args[:end_date]}"
      if (start_index = args[:start_index].to_i) > 0
        output += "&start#index=#{start_index}"
      end
      unless args[:dimensions].empty?
        output += '&dimensions=' + args[:dimensions].collect do |dimension|
          "ga:#{dimension}"
        end.join(',')
      end
      unless args[:metrics].empty?
        output += '&metrics=' + args[:metrics].collect do |metric|
          "ga:#{metric}"
        end.join(',')
      end
      unless args[:sort].empty?
        output += '&sort=' + args[:sort].collect do |sort|
          sort[0..0] == '-' ? "-ga:#{sort[1..-1]}" : "ga:#{sort}"  
        end.join(',')
      end
      unless args[:segment].nil?
        output += "&segment=#{args[:segment]}"
      end
      unless args[:filters].empty?    
        output += '&filters=' + args[:filters].collect do |filter|
          match, name, operator, expression = *filter.match(/^(\w*)\s*([=!<>~@]*)\s*(.*)$/)           
          unless name.empty? || operator.empty? || expression.empty?                      
            "ga:#{name}#{CGI::escape(operator.gsub(/ /,''))}#{CGI::escape(expression)}"   
          else
            raise GatticaError::InvalidFilter, "The filter '#{filter}' is invalid. Filters should look like 'browser == Firefox' or 'browser==Firefox'"
          end
        end.join(';')
      end
      return output
    end
def build_query_string ( args , profile ) output = "ids=ga:#{profile}&start-date=#{args[:start_date]}&end-date=#{args[:end_date]}" if ( start_index = args [ :start_index ] . to_i ) > 0 output += "&start#index=#{start_index}" end unless args [ :dimensions ] . empty? output += '&dimensions=' + args [ :dimensions ] . collect do | dimension | "ga:#{dimension}" end . join ( ',' ) end unless args [ :metrics ] . empty? output += '&metrics=' + args [ :metrics ] . collect do | metric | "ga:#{metric}" end . join ( ',' ) end unless args [ :sort ] . empty? output += '&sort=' + args [ :sort ] . collect do | sort | sort [ 0 .. 0 ] == '-' ? "-ga:#{sort[1..-1]}" : "ga:#{sort}" end . join ( ',' ) end unless args [ :segment ] . nil? output += "&segment=#{args[:segment]}" end unless args [ :filters ] . empty? output += '&filters=' + args [ :filters ] . collect do | filter | match , name , operator , expression = * filter . match ( / ^( \w *) \s *([=!<>~@]*) \s *(.*)$ / ) unless name . empty? || operator . empty? || expression . empty? "ga:#{name}#{CGI::escape(operator.gsub(/ /,''))}#{CGI::escape(expression)}" else raise GatticaError :: InvalidFilter , "The filter '#{filter}' is invalid. Filters should look like 'browser == Firefox' or 'browser==Firefox'" end end . join ( ';' ) end return output end
Creates a valid query string for GA
Creates a valid query string for GA
# if the first character is a dash, move it before the ga: # TODO: update so that in regular expression filters (=~ and !~), any initial special characters in the regular expression aren't also picked up as part of the operator (doesn't cause a problem, but just feels dirty) # filters are a little more complicated because they can have all kinds of modifiers # splat the resulting Match object to pull out the parts automatically # make sure they all contain something # remove any whitespace from the operator before output
args
<not_specific>
profile
<not_specific>