Skip to content

Commit

Permalink
Merge #589
Browse files Browse the repository at this point in the history
589: fix: Prepare v4.6.0 r=myConsciousness a=myConsciousness

# 1. Description

<!-- Provide a description of what this PR is doing.
If you're modifying existing behavior, describe the existing behavior, how this PR is changing it,
and what motivated the change. If this is a breaking change, specify explicitly which APIs have been
changed. -->

## 1.1. Checklist

<!-- Before you create this PR confirm that it meets all requirements listed below by checking the
relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. -->

- [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc).
- [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs.
- [x] I have updated/added tests for ALL new/updated/fixed functionality.
- [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`.
- [x] I have updated/added relevant examples in `examples`.

## 1.2. Breaking Change

<!-- Does your PR require users to manually update their apps to accommodate your change?

If the PR is a breaking change this should be indicated with suffix "!"  (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details.
-->

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

## 1.3. Related Issues

<!-- Provide a list of issues related to this PR from the [issue database].
Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !-->

<!-- Links -->

[issue database]: https://github.com/twitter-dart/twitter-api-v2/issues
[contributor guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/CONTRIBUTING.md
[style guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <[email protected]>
  • Loading branch information
bors[bot] and myConsciousness authored Dec 5, 2022
2 parents f28a54b + 821dcd5 commit 26293e9
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 36 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Decahose",
"Elon",
"geocode",
"Geocoded",
"hashtagged",
"hmac",
"Kato",
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- `GET /1.1/trends/place.json`
- `GET /1.1/trends/available.json`
- `GET /1.1/trends/closest.json`
- Supported `/1.1/geo/reverse_geocode.json` endpoint for `Geo` service. ([#584](https://github.com/twitter-dart/twitter-api-v2/issues/584))


## v4.5.0

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ Future<void> main() async {
| Endpoint | Method Name |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------- |
| GET /1.1/geo/id/:placeId.json | [lookupById](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/GeoService/lookupById.html) |
| [GET /1.1/geo/reverse_geocode.json](https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-reverse_geocode) | [lookupReverseGeocodedLocations](https://pub.dev/documentation/twitter_api_v2/latest/twitter_api_v2/GeoService/lookupReverseGeocodedLocations.html) |

#### 1.3.7.2. Search Locations

Expand Down
121 changes: 85 additions & 36 deletions lib/src/service/geo/geo_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,67 @@ abstract class GeoService {
/// This request is an informative call and will deliver generalized
/// results about geography.
///
/// ## Parameters
///
/// - [granularity]: This is the minimal granularity of place types to
/// return and must be one of: [GeoGranularity.neighborhood],
/// [GeoGranularity.city], [GeoGranularity.admin] or
/// [GeoGranularity.country]. If no granularity is provided
/// for the request [GeoGranularity.neighborhood] is assumed.
/// Setting this to [GeoGranularity.city], for example,
/// will find places which have a type of
/// [GeoGranularity.city], [GeoGranularity.admin] or
/// [GeoGranularity.country].
///
/// - [maxResults]: A hint as to the number of results to return.
/// This does not guarantee that the number of results
/// returned will equal max_results, but instead informs how
/// many "nearby" results to return. Ideally, only pass in
/// the number of places you intend to display to the user
/// here.
///
/// - [accuracy]: A hint on the "region" in which to search. If a number,
/// then this is a radius in meters, but it can also take a
/// string that is suffixed with ft to specify feet.
/// If this is not passed in, then it is assumed to be `0m`.
/// If coming from a device, in practice, this value is
/// whatever accuracy the device has measuring its location
/// (whether it be coming from a GPS, WiFi triangulation, etc.).
///
/// - [latitude]: The latitude to search around. This parameter will be
/// ignored unless it is inside the range -90.0 to +90.0
/// (North is positive) inclusive. It will also be ignored if
/// there isn't a corresponding [longitude] parameter
///
/// - [longitude]: The longitude to search around. The valid ranges for
/// longitude are -180.0 to +180.0 (East is positive)
/// inclusive. This parameter will be ignored if outside
/// that range, if it is not a number, or if there not a
/// corresponding [latitude] parameter.
///
/// ## Authentication Methods
///
/// - OAuth 1.0a
///
/// ## Rate Limits
///
/// - **User rate limit (OAuth 1.0a)**:
/// 15 requests per 15-minute window per each authenticated user
///
/// ## Endpoint Url
///
/// - https://api.twitter.com/1.1/geo/reverse_geocode.json
///
/// ## Reference
///
/// - https://developer.twitter.com/en/docs/twitter-api/v1/geo/places-near-location/api-reference/get-geo-reverse_geocode
Future<TwitterResponse<List<PlaceData>, void>> reverseGeocodeLocations({
GeoGranularity? granularity,
Future<TwitterResponse<List<PlaceData>, void>>
lookupReverseGeocodedLocations({
required double latitude,
required double longitude,
int? maxResults,
String? accuracy,
double? latitude,
double? longitude,
GeoGranularity? granularity,
});
}

Expand Down Expand Up @@ -208,6 +256,39 @@ class _GeoService extends BaseService implements GeoService {
);
}

@override
Future<TwitterResponse<List<PlaceData>, void>>
lookupReverseGeocodedLocations({
required double latitude,
required double longitude,
int? maxResults,
String? accuracy,
GeoGranularity? granularity,
}) async {
final response = await super.get(
core.UserContext.oauth1Only,
'/1.1/geo/reverse_geocode.json',
queryParameters: {
'lat': latitude,
'long': longitude,
'max_results': maxResults,
'accuracy': accuracy,
'granularity': granularity,
},
);

final places = _checkResponse(response)['result']['places'];

return TwitterResponse(
rateLimit: RateLimit.fromJson(
rateLimitConverter.convert(response.headers),
),
data: _toV2Format(places)
.map<PlaceData>((json) => PlaceData.fromJson(json))
.toList(),
);
}

dynamic _checkResponse(final core.Response response) {
final json = jsonDecode(response.body);

Expand Down Expand Up @@ -242,36 +323,4 @@ class _GeoService extends BaseService implements GeoService {

return json;
}

@override
Future<TwitterResponse<List<PlaceData>, void>> reverseGeocodeLocations({
GeoGranularity? granularity,
int? maxResults,
String? accuracy,
double? latitude,
double? longitude,
}) async {
final response = await super.get(
core.UserContext.oauth1Only,
'/1.1/geo/reverse_geocode.json',
queryParameters: {
'granularity': granularity,
'max_results': maxResults,
'lat': latitude,
'long': longitude,
'accuracy': accuracy,
},
);

final places = _checkResponse(response)['result']['places'];

return TwitterResponse(
rateLimit: RateLimit.fromJson(
rateLimitConverter.convert(response.headers),
),
data: _toV2Format(places)
.map<PlaceData>((json) => PlaceData.fromJson(json))
.toList(),
);
}
}
147 changes: 147 additions & 0 deletions test/src/service/geo/data/lookup_reversed_geocoded_locations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"query": {
"url": "https://api.twitter.com/1.1/geo/reverse_geocode.json?lat=10.0&long=10.0",
"type": "reverse_geocode",
"params": {
"accuracy": 0.0,
"coordinates": {
"coordinates": [
10.0,
10.0
],
"type": "Point"
},
"granularity": "neighborhood"
}
},
"result": {
"places": [
{
"id": "0050229b40144026",
"name": "Bauchi",
"full_name": "Bauchi, Nigeria",
"country": "Nigeria",
"country_code": "NG",
"url": "https://api.twitter.com/1.1/geo/id/0050229b40144026.json",
"place_type": "admin",
"attributes": {},
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
8.7283121,
9.4556761
],
[
8.7283121,
12.5264415
],
[
11.0409839,
12.5264415
],
[
11.0409839,
9.4556761
],
[
8.7283121,
9.4556761
]
]
]
},
"centroid": [
9.318905992315942,
10.9908484
],
"contained_within": [
{
"id": "59b27337f38d658b",
"name": "Nigeria",
"full_name": "Nigeria",
"country": "Nigeria",
"country_code": "NG",
"url": "https://api.twitter.com/1.1/geo/id/59b27337f38d658b.json",
"place_type": "country",
"attributes": {},
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
2.6654364,
4.1974055
],
[
2.6654364,
13.8881151
],
[
14.6777951,
13.8881151
],
[
14.6777951,
4.1974055
],
[
2.6654364,
4.1974055
]
]
]
},
"centroid": [
7.822704037915037,
9.04266935
]
}
]
},
{
"id": "59b27337f38d658b",
"name": "Nigeria",
"full_name": "Nigeria",
"country": "Nigeria",
"country_code": "NG",
"url": "https://api.twitter.com/1.1/geo/id/59b27337f38d658b.json",
"place_type": "country",
"attributes": {},
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
2.6654364,
4.1974055
],
[
2.6654364,
13.8881151
],
[
14.6777951,
13.8881151
],
[
14.6777951,
4.1974055
],
[
2.6654364,
4.1974055
]
]
]
},
"centroid": [
7.822704037915037,
9.04266935
],
"contained_within": []
}
]
}
}
Loading

0 comments on commit 26293e9

Please sign in to comment.