3838 Intercom.app_api_key to use this client."
3939
4040
41- class _Config (object ):
42- app_id = None
43- app_api_key = None
44- hostname = "api.intercom.io"
45- protocol = "https"
46- endpoints = None
47- current_endpoint = None
48- target_base_url = None
49- endpoint_randomized_at = None
50-
51-
5241class IntercomType (type ): # noqa
5342
43+ _app_id = None
44+ _app_api_key = None
45+ _hostname = "api.intercom.io"
46+ _protocol = "https"
47+ _endpoints = None
48+ _current_endpoint = None
49+ _target_base_url = None
50+ _endpoint_randomized_at = None
51+
5452 @property
5553 def app_id (self ):
56- return self ._config . app_id
54+ return self ._app_id
5755
5856 @app_id .setter
5957 def app_id (self , value ):
60- self ._config . app_id = value
58+ self ._app_id = value
6159
6260 @property
6361 def app_api_key (self ):
64- return self ._config . app_api_key
62+ return self ._app_api_key
6563
6664 @app_api_key .setter
6765 def app_api_key (self , value ):
68- self ._config . app_api_key = value
66+ self ._app_api_key = value
6967
7068 @property
7169 def _auth (self ):
@@ -88,63 +86,63 @@ def _alternative_random_endpoint(self):
8886 return endpoints [0 ]
8987
9088 @property
91- def _target_base_url (self ):
89+ def target_base_url (self ):
9290 if None in [self .app_id , self .app_api_key ]:
9391 raise ArgumentError ('%s %s' % (
9492 CONFIGURATION_REQUIRED_TEXT , RELATED_DOCS_TEXT ))
95- if self ._config . target_base_url is None :
93+ if self ._target_base_url is None :
9694 basic_auth_part = '%s:%s@' % (self .app_id , self .app_api_key )
9795 if self .current_endpoint :
98- self ._config . target_base_url = re .sub (
96+ self ._target_base_url = re .sub (
9997 r'(https?:\/\/)(.*)' ,
10098 '\g<1>%s\g<2>' % (basic_auth_part ),
10199 self .current_endpoint )
102- return self ._config . target_base_url
100+ return self ._target_base_url
103101
104102 @property
105103 def hostname (self ):
106- return self ._config . hostname
104+ return self ._hostname
107105
108106 @hostname .setter
109107 def hostname (self , value ):
110- self ._config . hostname = value
108+ self ._hostname = value
111109 self .current_endpoint = None
112110 self .endpoints = None
113111
114112 @property
115113 def protocol (self ):
116- return self ._config . protocol
114+ return self ._protocol
117115
118116 @protocol .setter
119117 def protocol (self , value ):
120- self ._config . protocol = value
118+ self ._protocol = value
121119 self .current_endpoint = None
122120 self .endpoints = None
123121
124122 @property
125123 def current_endpoint (self ):
126124 now = time .mktime (datetime .utcnow ().timetuple ())
127- expired = self ._config . endpoint_randomized_at < (now - (60 * 5 ))
128- if self ._config . endpoint_randomized_at is None or expired :
129- self ._config . endpoint_randomized_at = now
130- self .current_endpoint = self ._random_endpoint
131- return self ._config . current_endpoint
125+ expired = self ._endpoint_randomized_at < (now - (60 * 5 ))
126+ if self ._endpoint_randomized_at is None or expired :
127+ self ._endpoint_randomized_at = now
128+ self ._current_endpoint = self ._random_endpoint
129+ return self ._current_endpoint
132130
133131 @current_endpoint .setter
134132 def current_endpoint (self , value ):
135- self ._config . current_endpoint = value
136- self ._config . target_base_url = None
133+ self ._current_endpoint = value
134+ self ._target_base_url = None
137135
138136 @property
139137 def endpoints (self ):
140- if not self ._config . endpoints :
138+ if not self ._endpoints :
141139 return ['%s://%s' % (self .protocol , self .hostname )]
142140 else :
143- return self ._config . endpoints
141+ return self ._endpoints
144142
145143 @endpoints .setter
146144 def endpoints (self , value ):
147- self ._config . endpoints = value
145+ self ._endpoints = value
148146 self .current_endpoint = self ._random_endpoint
149147
150148 @SetterProperty
@@ -153,7 +151,6 @@ def endpoint(self, value):
153151
154152
155153class Intercom (object ):
156- _config = _Config ()
157154 _class_register = {}
158155 __metaclass__ = IntercomType
159156
@@ -165,18 +162,23 @@ def get_url(cls, path):
165162 url = cls .current_endpoint + path
166163 return url
167164
165+ @classmethod
166+ def request (cls , method , path , params ):
167+ return Request .send_request_to_path (
168+ method , cls .get_url (path ), cls ._auth , params )
169+
168170 @classmethod
169171 def get (cls , path , ** params ):
170- return Request . send_request_to_path ('GET' , cls . get_url ( path ), cls . _auth , params )
172+ return cls . request ('GET' , path , params )
171173
172174 @classmethod
173175 def post (cls , path , ** params ):
174- return Request . send_request_to_path ('POST' , cls . get_url ( path ), cls . _auth , params )
176+ return cls . request ('POST' , path , params )
175177
176178 @classmethod
177179 def put (cls , path , ** params ):
178- return Request . send_request_to_path ('PUT' , cls . get_url ( path ), cls . _auth , params )
180+ return cls . request ('PUT' , path , params )
179181
180182 @classmethod
181183 def delete (cls , path , ** params ):
182- return Request . send_request_to_path ('DELETE' , cls . get_url ( path ), cls . _auth , params )
184+ return cls . request ('DELETE' , path , params )
0 commit comments