1616 */
1717class ContentGenerationServiceRequest {
1818
19+ /**
20+ * Default production base URL
21+ */
22+ const DEFAULT_PRODUCTION_BASE_URL = 'https://patterns.hiive.cloud ' ;
23+
24+ /**
25+ * Default local base URL
26+ */
27+ const DEFAULT_LOCAL_BASE_URL = 'http://localhost:8888 ' ;
28+
1929 /**
2030 * API URL
2131 *
2232 * @var string
2333 */
24- private $ url = ' https://patterns.hiive.cloud/api/v1/content-generation/ ' ;
34+ private $ url ;
2535
2636 /**
2737 * API endpoint
@@ -54,20 +64,37 @@ class ContentGenerationServiceRequest {
5464 /**
5565 * Constructor
5666 *
57- * @param array $body Request body data.
58- * @param array $headers Additional headers to include in the request.
67+ * @param string $endpoint API endpoint.
68+ * @param array $body Request body data.
69+ * @param array $headers Additional headers to include in the request.
5970 */
6071 public function __construct ( string $ endpoint , array $ body , array $ headers = array () ) {
6172 $ this ->endpoint = $ endpoint ;
62- $ this ->body = $ body ;
63- $ this ->headers = array_merge (
73+ $ this ->body = $ body ;
74+ $ this ->url = $ this ->get_api_url ();
75+ $ this ->headers = array_merge (
6476 array (
6577 'Content-Type ' => 'application/json ' ,
6678 'Authorization ' => 'Bearer ' . HiiveConnection::get_auth_token (),
6779 ),
6880 $ headers
6981 );
82+ }
7083
84+ /**
85+ * Get the API URL based on configuration
86+ *
87+ * @return string The API URL to use.
88+ */
89+ private function get_api_url (): string {
90+
91+ if ( defined ( 'NFD_WB_DEV_MODE ' ) && NFD_WB_DEV_MODE ) {
92+ $ base_url = defined ( 'NFD_WB_LOCAL_BASE_URL ' ) ? NFD_WB_LOCAL_BASE_URL : self ::DEFAULT_LOCAL_BASE_URL ;
93+ } else {
94+ $ base_url = defined ( 'NFD_WB_PRODUCTION_BASE_URL ' ) ? NFD_WB_PRODUCTION_BASE_URL : self ::DEFAULT_PRODUCTION_BASE_URL ;
95+ }
96+
97+ return $ base_url . '/api/v1/content-generation/ ' ;
7198 }
7299
73100 /**
@@ -88,7 +115,7 @@ public function send(): ContentGenerationServiceRequest {
88115 $ this ->response = $ response ;
89116 return $ this ;
90117 }
91-
118+
92119 /**
93120 * Check if the request was successful
94121 *
@@ -98,7 +125,7 @@ public function is_successful(): bool {
98125 if ( ! $ this ->response || is_wp_error ( $ this ->response ) ) {
99126 return false ;
100127 }
101-
128+
102129 $ code = wp_remote_retrieve_response_code ( $ this ->response );
103130 return $ code >= 200 && $ code < 300 ;
104131 }
0 commit comments