<s> from base import BaseClient <EOL> HUBSPOT_BROADCAST_API_VERSION = '<STR_LIT:1>' <EOL> class BaseSocialObject ( object ) : <EOL> def _camel_case_to_underscores ( self , text ) : <EOL> result = [ ] <EOL> pos = <NUM_LIT:0> <EOL> while pos < len ( text ) : <EOL> if text [ pos ] . isupper ( ) : <EOL> if pos - <NUM_LIT:1> > <NUM_LIT:0> and text [ pos - <NUM_LIT:1> ] . islower ( ) or pos - <NUM_LIT:1> > <NUM_LIT:0> and pos + <NUM_LIT:1> < len ( text ) and text [ pos + <NUM_LIT:1> ] . islower ( ) : <EOL> result . append ( "<STR_LIT>" % text [ pos ] . lower ( ) ) <EOL> else : <EOL> result . append ( text [ pos ] . lower ( ) ) <EOL> else : <EOL> result . append ( text [ pos ] ) <EOL> pos += <NUM_LIT:1> <EOL> return "<STR_LIT>" . join ( result ) <EOL> def _underscores_to_camel_case ( self , text ) : <EOL> result = [ ] <EOL> pos = <NUM_LIT:0> <EOL> while pos < len ( text ) : <EOL> if text [ pos ] == "<STR_LIT:_>" and pos + <NUM_LIT:1> < len ( text ) : <EOL> result . append ( "<STR_LIT:%s>" % text [ pos + <NUM_LIT:1> ] . upper ( ) ) <EOL> pos += <NUM_LIT:1> <EOL> else : <EOL> result . append ( text [ pos ] ) <EOL> pos += <NUM_LIT:1> <EOL> return "<STR_LIT>" . join ( result ) <EOL> def to_dict ( self ) : <EOL> dict_self = { } <EOL> for key in vars ( self ) : <EOL> dict_self [ self . _underscores_to_camel_case ( key ) ] = getattr ( self , key ) <EOL> return dict_self <EOL> def from_dict ( self , data ) : <EOL> accepted_fields = self . accepted_fields ( ) <EOL> for key in data : <EOL> if key in accepted_fields : <EOL> setattr ( self , self . _camel_case_to_underscores ( key ) , data [ key ] ) <EOL> class Broadcast ( BaseSocialObject ) : <EOL> '''<STR_LIT>''' <EOL> COS_LP = "<STR_LIT>" <EOL> COS_BLOG = "<STR_LIT>" <EOL> LEGACY_LP = "<STR_LIT>" <EOL> LEGACY_BLOG = "<STR_LIT>" <EOL> def __init__ ( self , broadcast_data ) : <EOL> self . data_parse ( broadcast_data ) <EOL> def accepted_fields ( self ) : <EOL> return [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:content>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:message>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def data_parse ( self , broadcast_data ) : <EOL> self . from_dict ( broadcast_data ) <EOL> class Channel ( BaseSocialObject ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , channel_data ) : <EOL> self . data_parse ( channel_data ) <EOL> def accepted_fields ( self ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:type>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def data_parse ( self , channel_data ) : <EOL> self . from_dict ( channel_data ) <EOL> class BroadcastClient ( BaseClient ) : <EOL> '''<STR_LIT>''' <EOL> def _get_path ( self , method ) : <EOL> return '<STR_LIT>' % ( HUBSPOT_BROADCAST_API_VERSION , method ) <EOL> def get_broadcast ( self , broadcast_guid , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> params = kwargs <EOL> broadcast = self . _call ( '<STR_LIT>' % broadcast_guid , <EOL> params = params , content_type = '<STR_LIT:application/json>' ) <EOL> return Broadcast ( broadcast ) <EOL> def get_broadcasts ( self , type = "<STR_LIT>" , page = None , <EOL> remote_content_id = None , limit = None , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if remote_content_id : <EOL> return self . get_broadcasts_by_remote ( remote_content_id ) <EOL> params = { '<STR_LIT:type>' : type } <EOL> if page : <EOL> params [ '<STR_LIT>' ] = page <EOL> params . update ( kwargs ) <EOL> result = self . _call ( '<STR_LIT>' , params = params , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> broadcasts = [ Broadcast ( b ) for b in result ] <EOL> if limit : <EOL> return broadcasts [ : limit ] <EOL> return broadcasts <EOL> def create_broadcast ( self , broadcast ) : <EOL> if not isinstance ( broadcast , dict ) : <EOL> return self . _call ( '<STR_LIT>' , data = broadcast . to_dict ( ) , <EOL> method = '<STR_LIT:POST>' , content_type = '<STR_LIT:application/json>' ) <EOL> else : <EOL> return self . _call ( '<STR_LIT>' , data = broadcast , <EOL> method = '<STR_LIT:POST>' , content_type = '<STR_LIT:application/json>' ) <EOL> def cancel_broadcast ( self , broadcast_guid ) : <EOL> '''<STR_LIT>''' <EOL> subpath = '<STR_LIT>' % broadcast_guid <EOL> broadcast = { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> bcast_dict = self . _call ( subpath , method = '<STR_LIT:POST>' , data = broadcast , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> return bcast_dict <EOL> def get_channel ( self , channel_guid ) : <EOL> channel = self . _call ( '<STR_LIT>' % channel_guid , <EOL> content_type = '<STR_LIT:application/json>' ) <EOL> return Channel ( channel ) <EOL> def get_channels ( self , current = True , publish_only = False , settings = False ) : <EOL> """<STR_LIT>""" <EOL> if publish_only : <EOL> if current : <EOL> endpoint = '<STR_LIT>' <EOL> else : <EOL> endpoint = '<STR_LIT>' <EOL> else : <EOL> if current : <EOL> endpoint = '<STR_LIT>' <EOL> else : <EOL> endpoint = '<STR_LIT>' <EOL> result = self . _call ( endpoint , content_type = '<STR_LIT:application/json>' , params = dict ( settings = settings ) ) <EOL> return [ Channel ( c ) for c in result ] </s>
