 < ? x m l   v e r s i o n = ' 1 . 0 '   e n c o d i n g = ' U T F - 8 ' ? > 
 < d u n e s - s c r i p t - m o d u l e   n a m e = " i n v o k e R e s t O p e r a t i o n "   r e s u l t - t y p e = " s t r i n g "   a p i - v e r s i o n = " 6 . 0 . 0 "   i d = " 6 2 a e 8 2 6 0 - e 1 f e - 4 d 4 7 - 8 a a d - a 0 0 9 1 8 6 2 e 0 4 d "   v e r s i o n = " 0 . 0 . 2 "   a l l o w e d - o p e r a t i o n s = " v f e " > 
     < p a r a m   n = " v r a H o s t "   t = " V R A : H o s t " > < ! [ C D A T A [ ] ] > < / p a r a m > 
     < p a r a m   n = " o p e r a t i o n "   t = " s t r i n g " > < ! [ C D A T A [ ] ] > < / p a r a m > 
     < p a r a m   n = " u r l "   t = " s t r i n g " > < ! [ C D A T A [ ] ] > < / p a r a m > 
     < p a r a m   n = " c o n t e n t "   t = " s t r i n g " > < ! [ C D A T A [ ] ] > < / p a r a m > 
     < p a r a m   n = " p a r a m e t e r s "   t = " A r r a y / s t r i n g " > < ! [ C D A T A [ ] ] > < / p a r a m > 
     < s c r i p t   e n c o d e d = " f a l s e " > < ! [ C D A T A [ i f   ( v r a H o s t   = =   n u l l )   t h r o w   " v r a H o s t   i s   n u l l " ; 
 i f   ( o p e r a t i o n   = =   n u l l )   t h r o w   " o p e r a t i o n   i s   n u l l " ; 
 i f   ( u r l   = =   n u l l )   t h r o w   " u r l   i s   n u l l " ; 
 
 v a r   r e t r y C o u n t   =   5 
 i f   ( p a r a m e t e r s   = =   n u l l )   p a r a m e t e r s   =   n e w   A r r a y ( ) ; 
 
 
 / / R e p l a c e   U R L   p a r a m e t e r s 
 v a r   s t r i n g s T o R e p l a c e   =   u r l . m a t c h ( n e w   R e g E x p ( " \ { ( \ s * ? . * ? ) * ? \ } " ,   " g " ) ) ; 
 
 i f   ( s t r i n g s T o R e p l a c e   ! =   n u l l   & &   s t r i n g s T o R e p l a c e . l e n g t h   >   0 )   { 
 	 i f   ( s t r i n g s T o R e p l a c e . l e n g t h   ! =   p a r a m e t e r s . l e n g t h )   { 
 	 	 S y s t e m . w a r n ( " U R L   :   "   +   u r l   +   "   c o n t a i n s   "   +   s t r i n g s T o R e p l a c e . l e n g t h   +   "   s t r i n g s   t o   r e p l a c e   a n d   p a r a m s   h a s   "   +   p a r a m e t e r s . l e n g t h ) ; 
 	 	 / / r e t u r n   n u l l ; 
 	 } 
 	 f o r   ( v a r   i   =   0 ;   i   <   p a r a m e t e r s . l e n g t h ;   i + + )   { 
 	 	 S y s t e m . l o g ( " R e p l a c i n g   "   +   s t r i n g s T o R e p l a c e [ i ]   +   "   w i t h   "   +   p a r a m e t e r s [ i ] ) ; 
 	 	 u r l   =   u r l . r e p l a c e ( s t r i n g s T o R e p l a c e [ i ] ,   p a r a m e t e r s [ i ] ) ; 
 	 } 
 } 
 
 i f   ( c o n t e n t   ! =   n u l l )   { 
 	 t r y   { 
 	 	 v a r   c o n t e n t O b j e c t   =   J S O N . p a r s e ( c o n t e n t ) ; 
 	 	 S y s t e m . d e b u g ( " C o n t e n t   :   \ n "   +   J S O N . s t r i n g i f y ( c o n t e n t O b j e c t ,   n u l l ,   2 ) ) ; 
 	 }   c a t c h   ( e )   {   S y s t e m . d e b u g ( " C o n t e n t   :   \ n "   +   c o n t e n t )   } 
 } 
 
 r e t u r n   e x e c u t e W i t h R e t r y ( v r a H o s t ,   o p e r a t i o n ,   u r l ,   c o n t e n t ,   r e t r y C o u n t ) 
 
 f u n c t i o n   e x e c u t e R e q u e s t ( h o s t ,   o p ,   u r l S u f f i x ,   c o n t e n t )   { 
 	 v a r   h o s t U R L   =   v r a H o s t . c o n n e c t i o n T y p e   = =   " v r a - c l o u d "   ?   v r a H o s t . c l o u d H o s t   :   v r a H o s t . v r a H o s t ; 
 
 	 S y s t e m . d e b u g ( " * * * * * * R e s t   R e q u e s t * * * * *   " ) ; 
 	 S y s t e m . d e b u g ( o p   +   "   "   +   h o s t U R L   +   u r l S u f f i x ) ; 
 	 v a r   r e s t C l i e n t   =   h o s t . c r e a t e R e s t C l i e n t ( ) ; 
 	 v a r   r e q u e s t   =   r e s t C l i e n t . c r e a t e R e q u e s t ( o p ,   u r l S u f f i x ,   c o n t e n t ) ; 
 	 v a r   r e s p o n s e   =   r e s t C l i e n t . e x e c u t e ( r e q u e s t ) ; 
 
 	 S y s t e m . d e b u g ( " * * * * * * R e s t   R e s p o n s e * * * * *   " ) ; 
 	 s t a t u s C o d e   =   r e s p o n s e . s t a t u s C o d e ; 
 	 S y s t e m . d e b u g ( " S t a t u s   c o d e :   "   +   s t a t u s C o d e ) ; 
 
 	 s t a t u s M e s s a g e   =   r e s p o n s e . s t a t u s M e s s a g e ; 
 	 S y s t e m . d e b u g ( " S t a t u s   M e s s a g e :   "   +   s t a t u s M e s s a g e ) ; 
 
 	 / /   N o t   t h e   f a s t e s t   b u t   d i s p l a y   n i c e l y   t h e   J S O N   :   b e t t e r   f o r   l e a r n i n g   a n d   t r o u b l e s h o o t i n g   p u r p o s e s . 
 	 i f   ( r e s p o n s e . c o n t e n t A s S t r i n g   ! =   " " )   S y s t e m . d e b u g ( " C o n t e n t   a s   s t r i n g :   "   +   J S O N . s t r i n g i f y ( J S O N . p a r s e ( r e s p o n s e . c o n t e n t A s S t r i n g ) ,   n u l l ,   2 ) ) ; 
 
 
 	 i f   ( s t a t u s C o d e   ! =   2 0 0   & &   s t a t u s C o d e   ! =   2 0 1   & &   s t a t u s C o d e   ! =   2 0 2   & &   s t a t u s C o d e   ! =   2 0 3   & &   s t a t u s C o d e   ! =   2 0 4 ) 
 	 	 t h r o w   " H T T P   "   +   s t a t u s C o d e   +   "   -   "   +   s t a t u s M e s s a g e   +   "   :   "   +   r e s p o n s e . c o n t e n t A s S t r i n g ; 
 
 	 S y s t e m . d e b u g ( " * * * * A l l   H e a d e r s * * * * " ) ; 
 
 	 f o r   e a c h ( v a r   k e y   i n   r e s p o n s e . a l l H e a d e r s . k e y s )   { 
 	 	 S y s t e m . d e b u g ( k e y   +   "   :   "   +   r e s p o n s e . a l l H e a d e r s . g e t ( k e y ) ) ; 
 	 } 
 
 	 r e t u r n   r e s p o n s e . c o n t e n t A s S t r i n g ; 
 } 
 
 f u n c t i o n   e x e c u t e W i t h R e t r y ( h o s t ,   o p ,   u r l S u f f i x ,   c o n t e n t ,   r e t r y C o u n t ) { 
 	 v a r   r e t r y I n t e r v a l   =   5 0 0 0   / / m s 
 	 v a r   r e t r y O n E r r o r   =   t r u e 
 	 v a r   t i m e s T r i e d   =   0 ; 
 	 v a r   a t t e m p t s   =   [ ] 
 	 d o   { 
 	 	 t i m e s T r i e d + + 
 	 	 e r r o r   =   n u l l ; 
 	 	 t r y   { 
 	 	 	 r e t u r n   e x e c u t e R e q u e s t ( h o s t ,   o p ,   u r l S u f f i x ,   c o n t e n t ) 
 	 	 }   c a t c h   ( e x )   { 
 	 	 	 S y s t e m . e r r o r ( e x ) ; 
 	 	 	 e r r o r   =   e x ; 
 	 	 	 s u c c e s s   =   f a l s e 
 	 	 	 i f   ( r e t r y O n E r r o r )   { 
 	 	 	 	 r e t r y T r i g g e r e d   =   e v a l u a t e R e t r y ( t i m e s T r i e d ,   r e t r y C o u n t ,   r e t r y I n t e r v a l ) ; 
 	 	 	 } 
 
 	 	 }   f i n a l l y   { 
 	 	 	 i f   ( e r r o r )   { 
 	 	 	 	 v a r   a t t e m p t   =   { } ; 
 	 	 	 	 a t t e m p t . n u m b e r   =   t i m e s T r i e d 
 	 	 	 	 a t t e m p t . e r r o r   =   e r r o r ; 
 	 	 	 	 a t t e m p t s . p u s h ( a t t e m p t ) ; 
 	 	 	 } 
 	 	 	 
 	 	 } 
 
 	 }   w h i l e   ( r e t r y T r i g g e r e d ) ; 
 
 	 t h r o w   " A P I   r e q u e s t   f a i l e d .   "   +   " \ n "   +   " L a s t   E r r o r :   "   +   a t t e m p t s [ a t t e m p t s . l e n g t h   -   1 ] . e r r o r   +   " \ n "   +   " R e t r y   A t t e m p t s :   "   +   ( a t t e m p t s . l e n g t h   -   1 ) 
 } 
 
 
 f u n c t i o n   e v a l u a t e R e t r y ( t i m e s T r i e d ,   m a x R e t r i e s ,   r e t r y I n t e r v a l )   { 
         v a r   r e s u l t   =   t i m e s T r i e d   < =   m a x R e t r i e s 
         i f   ( r e s u l t )   { 
                 S y s t e m . l o g ( " R e t r y i n g . .   A t t e m p t   #   "   +   t i m e s T r i e d   +   "   o f   "   +   m a x R e t r i e s ) ; 
                 S y s t e m . s l e e p ( r e t r y I n t e r v a l ) ; 
         } 
         r e t u r n   r e s u l t ; 
 } ] ] > < / s c r i p t > 
 < / d u n e s - s c r i p t - m o d u l e >