<s> """<STR_LIT:U+0020>""" <EOL> import functools <EOL> import yaml <EOL> import addressable <EOL> from . import utils <EOL> from . import query <EOL> from . import columns <EOL> from . columns import Column , Segment , ColumnList , SegmentList <EOL> class Account ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , raw , service , credentials ) : <EOL> self . service = service <EOL> self . credentials = credentials <EOL> self . raw = raw <EOL> self . id = raw [ '<STR_LIT:id>' ] <EOL> self . name = raw [ '<STR_LIT:name>' ] <EOL> self . permissions = raw [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> @ property <EOL> @ utils . memoize <EOL> def webproperties ( self ) : <EOL> """<STR_LIT>""" <EOL> raw_properties = self . service . management ( ) . webproperties ( ) . list ( <EOL> accountId = self . id ) . execute ( ) [ '<STR_LIT>' ] <EOL> _webproperties = [ WebProperty ( raw , self ) for raw in raw_properties ] <EOL> return addressable . List ( _webproperties , indices = [ '<STR_LIT:id>' , '<STR_LIT:name>' ] , insensitive = True ) <EOL> @ property <EOL> def query ( self , * vargs , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . webproperties [ <NUM_LIT:0> ] . query ( * vargs , ** kwargs ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( <EOL> self . name , self . id ) <EOL> class WebProperty ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , raw , account ) : <EOL> self . account = account <EOL> self . raw = raw <EOL> self . id = raw [ '<STR_LIT:id>' ] <EOL> self . name = raw [ '<STR_LIT:name>' ] <EOL> self . url = raw . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def profile ( self ) : <EOL> default = self . raw [ '<STR_LIT>' ] <EOL> return self . profiles [ default ] <EOL> @ property <EOL> @ utils . memoize <EOL> def profiles ( self ) : <EOL> """<STR_LIT>""" <EOL> raw_profiles = self . account . service . management ( ) . profiles ( ) . list ( <EOL> accountId = self . account . id , <EOL> webPropertyId = self . id ) . execute ( ) [ '<STR_LIT>' ] <EOL> profiles = [ Profile ( raw , self ) for raw in raw_profiles ] <EOL> return addressable . List ( profiles , indices = [ '<STR_LIT:id>' , '<STR_LIT:name>' ] , insensitive = True ) <EOL> def query ( self , * vargs , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . profiles [ <NUM_LIT:0> ] . query ( * vargs , ** kwargs ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( <EOL> self . name , self . id ) <EOL> class Profile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , raw , webproperty ) : <EOL> self . raw = raw <EOL> self . webproperty = webproperty <EOL> self . account = webproperty . account <EOL> self . id = raw [ '<STR_LIT:id>' ] <EOL> self . name = raw [ '<STR_LIT:name>' ] <EOL> self . core = CoreReportingAPI ( self ) <EOL> self . realtime = RealTimeReportingAPI ( self ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( <EOL> self . name , self . id ) <EOL> class ReportingAPI ( object ) : <EOL> REPORT_TYPES = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> QUERY_TYPES = { <EOL> '<STR_LIT>' : query . CoreQuery , <EOL> '<STR_LIT>' : query . RealTimeQuery , <EOL> } <EOL> def __init__ ( self , endpoint , profile ) : <EOL> """<STR_LIT>""" <EOL> self . profile = profile <EOL> self . account = account = profile . account <EOL> self . service = service = profile . account . service <EOL> root = service . data ( ) <EOL> self . endpoint_type = endpoint <EOL> self . endpoint = getattr ( root , endpoint ) ( ) <EOL> self . report_type = self . REPORT_TYPES [ endpoint ] <EOL> Query = self . QUERY_TYPES [ endpoint ] <EOL> self . query = Query ( self ) <EOL> self . cache = None <EOL> @ property <EOL> @ utils . memoize <EOL> def all_columns ( self ) : <EOL> query = self . service . metadata ( ) . columns ( ) . list ( <EOL> reportType = self . report_type <EOL> ) <EOL> raw_columns = query . execute ( ) [ '<STR_LIT>' ] <EOL> hydrated_columns = utils . flatten ( map ( Column . from_metadata , raw_columns ) ) <EOL> return ColumnList ( hydrated_columns , unique = False ) <EOL> @ property <EOL> @ utils . memoize <EOL> def columns ( self ) : <EOL> return addressable . filter ( columns . is_supported , self . all_columns ) <EOL> @ property <EOL> @ utils . memoize <EOL> def segments ( self ) : <EOL> query = self . service . management ( ) . segments ( ) . list ( ) <EOL> raw_segments = query . execute ( ) [ '<STR_LIT>' ] <EOL> hydrated_segments = [ Segment ( raw , self ) for raw in raw_segments ] <EOL> return SegmentList ( hydrated_segments ) <EOL> @ property <EOL> @ utils . memoize <EOL> def metrics ( self ) : <EOL> return addressable . filter ( columns . is_metric , self . columns ) <EOL> @ property <EOL> @ utils . memoize <EOL> def dimensions ( self ) : <EOL> return addressable . filter ( columns . is_dimension , self . columns ) <EOL> @ property <EOL> @ utils . memoize <EOL> def goals ( self ) : <EOL> raise NotImplementedError ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ ) <EOL> class CoreReportingAPI ( ReportingAPI ) : <EOL> def __init__ ( self , profile ) : <EOL> super ( CoreReportingAPI , self ) . __init__ ( '<STR_LIT>' , profile ) <EOL> class RealTimeReportingAPI ( ReportingAPI ) : <EOL> def __init__ ( self , profile ) : <EOL> super ( RealTimeReportingAPI , self ) . __init__ ( '<STR_LIT>' , profile ) <EOL> @ property <EOL> @ utils . memoize <EOL> def all_columns ( self ) : <EOL> raw_columns = yaml . load ( open ( utils . here ( '<STR_LIT>' ) ) ) <EOL> hydrated_columns = utils . flatten ( map ( Column . from_metadata , raw_columns ) ) <EOL> return ColumnList ( hydrated_columns ) </s>
