|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Optional |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..types import news_search_params |
| 10 | +from .._types import Body, Omit, Query, Headers, NotGiven, SequenceNotStr, omit, not_given |
| 11 | +from .._utils import maybe_transform, async_maybe_transform |
| 12 | +from .._compat import cached_property |
| 13 | +from .._resource import SyncAPIResource, AsyncAPIResource |
| 14 | +from .._response import ( |
| 15 | + to_raw_response_wrapper, |
| 16 | + to_streamed_response_wrapper, |
| 17 | + async_to_raw_response_wrapper, |
| 18 | + async_to_streamed_response_wrapper, |
| 19 | +) |
| 20 | +from .._base_client import make_request_options |
| 21 | +from ..types.news_search_response import NewsSearchResponse |
| 22 | + |
| 23 | +__all__ = ["NewsResource", "AsyncNewsResource"] |
| 24 | + |
| 25 | + |
| 26 | +class NewsResource(SyncAPIResource): |
| 27 | + """Search live first-party RSS and free historical news data by company identity.""" |
| 28 | + |
| 29 | + @cached_property |
| 30 | + def with_raw_response(self) -> NewsResourceWithRawResponse: |
| 31 | + """ |
| 32 | + This property can be used as a prefix for any HTTP method call to return |
| 33 | + the raw response object instead of the parsed content. |
| 34 | +
|
| 35 | + For more information, see https://www.github.com/context-dot-dev/context-python-sdk#accessing-raw-response-data-eg-headers |
| 36 | + """ |
| 37 | + return NewsResourceWithRawResponse(self) |
| 38 | + |
| 39 | + @cached_property |
| 40 | + def with_streaming_response(self) -> NewsResourceWithStreamingResponse: |
| 41 | + """ |
| 42 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 43 | +
|
| 44 | + For more information, see https://www.github.com/context-dot-dev/context-python-sdk#with_streaming_response |
| 45 | + """ |
| 46 | + return NewsResourceWithStreamingResponse(self) |
| 47 | + |
| 48 | + def search( |
| 49 | + self, |
| 50 | + *, |
| 51 | + search_by: news_search_params.SearchBy, |
| 52 | + cursor: Optional[str] | Omit = omit, |
| 53 | + filter_by: news_search_params.FilterBy | Omit = omit, |
| 54 | + limit: int | Omit = omit, |
| 55 | + sort_by: news_search_params.SortBy | Omit = omit, |
| 56 | + tags: SequenceNotStr[str] | Omit = omit, |
| 57 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 58 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 59 | + extra_headers: Headers | None = None, |
| 60 | + extra_query: Query | None = None, |
| 61 | + extra_body: Body | None = None, |
| 62 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 63 | + ) -> NewsSearchResponse: |
| 64 | + """ |
| 65 | + Searches live and historical company news for one company, identified in |
| 66 | + searchBy by name, domain, ticker (optionally disambiguated by exchange), or |
| 67 | + ISIN. Results can be filtered by publisher domain, publisher country, article |
| 68 | + language, article type, and published-at date, and include stable story IDs, |
| 69 | + source metadata, verified entity relevance, and cursor pagination. |
| 70 | +
|
| 71 | + Args: |
| 72 | + search_by: What to search for. |
| 73 | +
|
| 74 | + cursor: Opaque next_cursor from the previous response, or null for the first page. |
| 75 | +
|
| 76 | + filter_by: Optional result filters. |
| 77 | +
|
| 78 | + limit: Maximum results to return. Defaults to 10. |
| 79 | +
|
| 80 | + sort_by: Result ordering. Defaults to newest. |
| 81 | +
|
| 82 | + tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. |
| 83 | +
|
| 84 | + extra_headers: Send extra headers |
| 85 | +
|
| 86 | + extra_query: Add additional query parameters to the request |
| 87 | +
|
| 88 | + extra_body: Add additional JSON properties to the request |
| 89 | +
|
| 90 | + timeout: Override the client-level default timeout for this request, in seconds |
| 91 | + """ |
| 92 | + return self._post( |
| 93 | + "/news/search", |
| 94 | + body=maybe_transform( |
| 95 | + { |
| 96 | + "search_by": search_by, |
| 97 | + "cursor": cursor, |
| 98 | + "filter_by": filter_by, |
| 99 | + "limit": limit, |
| 100 | + "sort_by": sort_by, |
| 101 | + "tags": tags, |
| 102 | + }, |
| 103 | + news_search_params.NewsSearchParams, |
| 104 | + ), |
| 105 | + options=make_request_options( |
| 106 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 107 | + ), |
| 108 | + cast_to=NewsSearchResponse, |
| 109 | + ) |
| 110 | + |
| 111 | + |
| 112 | +class AsyncNewsResource(AsyncAPIResource): |
| 113 | + """Search live first-party RSS and free historical news data by company identity.""" |
| 114 | + |
| 115 | + @cached_property |
| 116 | + def with_raw_response(self) -> AsyncNewsResourceWithRawResponse: |
| 117 | + """ |
| 118 | + This property can be used as a prefix for any HTTP method call to return |
| 119 | + the raw response object instead of the parsed content. |
| 120 | +
|
| 121 | + For more information, see https://www.github.com/context-dot-dev/context-python-sdk#accessing-raw-response-data-eg-headers |
| 122 | + """ |
| 123 | + return AsyncNewsResourceWithRawResponse(self) |
| 124 | + |
| 125 | + @cached_property |
| 126 | + def with_streaming_response(self) -> AsyncNewsResourceWithStreamingResponse: |
| 127 | + """ |
| 128 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 129 | +
|
| 130 | + For more information, see https://www.github.com/context-dot-dev/context-python-sdk#with_streaming_response |
| 131 | + """ |
| 132 | + return AsyncNewsResourceWithStreamingResponse(self) |
| 133 | + |
| 134 | + async def search( |
| 135 | + self, |
| 136 | + *, |
| 137 | + search_by: news_search_params.SearchBy, |
| 138 | + cursor: Optional[str] | Omit = omit, |
| 139 | + filter_by: news_search_params.FilterBy | Omit = omit, |
| 140 | + limit: int | Omit = omit, |
| 141 | + sort_by: news_search_params.SortBy | Omit = omit, |
| 142 | + tags: SequenceNotStr[str] | Omit = omit, |
| 143 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 144 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 145 | + extra_headers: Headers | None = None, |
| 146 | + extra_query: Query | None = None, |
| 147 | + extra_body: Body | None = None, |
| 148 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 149 | + ) -> NewsSearchResponse: |
| 150 | + """ |
| 151 | + Searches live and historical company news for one company, identified in |
| 152 | + searchBy by name, domain, ticker (optionally disambiguated by exchange), or |
| 153 | + ISIN. Results can be filtered by publisher domain, publisher country, article |
| 154 | + language, article type, and published-at date, and include stable story IDs, |
| 155 | + source metadata, verified entity relevance, and cursor pagination. |
| 156 | +
|
| 157 | + Args: |
| 158 | + search_by: What to search for. |
| 159 | +
|
| 160 | + cursor: Opaque next_cursor from the previous response, or null for the first page. |
| 161 | +
|
| 162 | + filter_by: Optional result filters. |
| 163 | +
|
| 164 | + limit: Maximum results to return. Defaults to 10. |
| 165 | +
|
| 166 | + sort_by: Result ordering. Defaults to newest. |
| 167 | +
|
| 168 | + tags: Optional tags for tracking usage. Up to 20 tags, each 1 to 50 characters. |
| 169 | +
|
| 170 | + extra_headers: Send extra headers |
| 171 | +
|
| 172 | + extra_query: Add additional query parameters to the request |
| 173 | +
|
| 174 | + extra_body: Add additional JSON properties to the request |
| 175 | +
|
| 176 | + timeout: Override the client-level default timeout for this request, in seconds |
| 177 | + """ |
| 178 | + return await self._post( |
| 179 | + "/news/search", |
| 180 | + body=await async_maybe_transform( |
| 181 | + { |
| 182 | + "search_by": search_by, |
| 183 | + "cursor": cursor, |
| 184 | + "filter_by": filter_by, |
| 185 | + "limit": limit, |
| 186 | + "sort_by": sort_by, |
| 187 | + "tags": tags, |
| 188 | + }, |
| 189 | + news_search_params.NewsSearchParams, |
| 190 | + ), |
| 191 | + options=make_request_options( |
| 192 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 193 | + ), |
| 194 | + cast_to=NewsSearchResponse, |
| 195 | + ) |
| 196 | + |
| 197 | + |
| 198 | +class NewsResourceWithRawResponse: |
| 199 | + def __init__(self, news: NewsResource) -> None: |
| 200 | + self._news = news |
| 201 | + |
| 202 | + self.search = to_raw_response_wrapper( |
| 203 | + news.search, |
| 204 | + ) |
| 205 | + |
| 206 | + |
| 207 | +class AsyncNewsResourceWithRawResponse: |
| 208 | + def __init__(self, news: AsyncNewsResource) -> None: |
| 209 | + self._news = news |
| 210 | + |
| 211 | + self.search = async_to_raw_response_wrapper( |
| 212 | + news.search, |
| 213 | + ) |
| 214 | + |
| 215 | + |
| 216 | +class NewsResourceWithStreamingResponse: |
| 217 | + def __init__(self, news: NewsResource) -> None: |
| 218 | + self._news = news |
| 219 | + |
| 220 | + self.search = to_streamed_response_wrapper( |
| 221 | + news.search, |
| 222 | + ) |
| 223 | + |
| 224 | + |
| 225 | +class AsyncNewsResourceWithStreamingResponse: |
| 226 | + def __init__(self, news: AsyncNewsResource) -> None: |
| 227 | + self._news = news |
| 228 | + |
| 229 | + self.search = async_to_streamed_response_wrapper( |
| 230 | + news.search, |
| 231 | + ) |
0 commit comments