Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the Geolocation API call. #164

Merged
merged 14 commits into from
Sep 30, 2016

Conversation

kwnevarez
Copy link
Member

This pull request is to initiate a discussion on the proposed changes to support the Geolocation API. Geolocation uses POST calls so support for POST was implemented in both the OkHttp and GAE handlers.

A simple test case was created, it fails, but I believe that's because I am using assert wrong or creating the result object incorrectly. The call to the server is working and that can be seen by running the tests with the --info flag.

The new code can be exercised with:
$ API_KEY=AIza... ./gradlew test --info --tests com.google.maps.GeolocationApiTest

Output:

com.google.maps.GeolocationApiTest > testSimpleGeolocation[0] STANDARD_ERROR
    Jun 17, 2016 3:22:44 PM com.google.maps.OkHttpRequestHandler handlePost
    INFO: Request: https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyB5fznx33Gskw8n0vJx9GCz_3FcASNe09s
    Jun 17, 2016 3:22:44 PM com.google.maps.OkHttpRequestHandler handlePost
    INFO: Request Body: {"homeMobileCountryCode":310,"homeMobileNetworkCode":410,"radioType":"gsm","carrier":"Vodafone","considerIp":true,"wifiAccessPoints":[{"macAddress":"01:23:45:67:89:AB","signalStrength":-65,"age":0,"channel":11,"signalToNoiseRatio":40}]}
    Jun 17, 2016 3:22:44 PM com.google.maps.internal.OkHttpPendingResult parseResponse
    INFO: response body{
     "location": {
      "lat": 37.428433999999996,
      "lng": -122.0723816
     },
     "accuracy": 2855.0
    }

@@ -15,13 +15,17 @@

package com.google.maps;

import static com.google.appengine.repackaged.com.google.common.base.StringUtil.JsEscapingMode.JSON;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be an issue, we don't want to require appengine code for users who aren't on GAE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is just a bad import from an IDE. You can drop the com.google.appengine.repackaged. prefix and you should be fine.

@domesticmouse
Copy link
Contributor

Hey @markmcd can you please check this PR for sanity? Thanks!

/**
* {@code signalStrength}: The current signal strength measured in dBm.
*/
public int signalStrength;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the int fields optional? If so, is it OK that the API will still be sent the default value for int even if the user doesn't provide it?

Closes #9
Closes #17
Closes #16
Closes #1
Closes #2
Closes #4
Closes #8
Closes #14
Closes #10
Closes #12
Closes #11
Closes #13
Code still contains some extraneous logging messages that will be removed when the builder-izing is done.

Closes #22
Closes #21
Closes #20
Closes #19
Closes #15
Closes #7
Closes #3
@kwnevarez
Copy link
Member Author

Hello @markmcd, @domesticmouse ,
I need some guidance on how to "builder-ize" the post request and its payload. The most recent push uses a basic builder pattern, but its not the model used by the the other API calls. The class upon which all the other API builders are created, PendingResultBase, is tied specifically to the GET verb and I need it to be flexible enough to also call POST.

The specific line is PendingResultBase.java:78 in the method makeRequest(). I'd like to override makeRequest but it, and the variables it uses are private. Do you have any objections to me making them protected so that I can override makeRequest in my GeolocationApiRequest class?

@markmcd
Copy link
Contributor

markmcd commented Jul 4, 2016

Can you use ApiConfig to define which verb(s) the API uses?

}
ApiException e;
// try and fit the older error codes into the new style geo api error formats
if(reason.equals("keyInvalid")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these into the ApiException.from method, where the rest of the string-to-exception mapping occurs?

Builder patter utilized in the model of the other API calls.

POST payload serialized GeolocationApiRequest and passed as string to POST handler

Error mapping moved to ApiException.from()

Closes #27
Closes #26
Closes #24
Closes #18
Closes #6
Closes #28
@@ -57,32 +60,36 @@ public OkHttpRequestHandler() {

return new OkHttpPendingResult<T, R>(req, client, clazz, fieldNamingPolicy, errorTimeout);
}
@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that you have dropped a bunch of blank lines here. Can you put them back please?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,122 @@
package com.google.maps.internal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file appears to be missing it's copyright header. Plz add

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@@ -0,0 +1,140 @@
/*
* Copyright 2014 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is a new file, so it should have a Copyright year of 2016.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,165 @@
/*
* Copyright 2014 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect copyright year?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,37 @@
/*
* Copyright 2014 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,89 @@
/*
* Copyright 2014 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this date.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,111 @@
/*
* Copyright 2014 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@domesticmouse domesticmouse merged commit 6de4f3e into googlemaps:master Sep 30, 2016
@domesticmouse
Copy link
Contributor

Thanks for working through all the issues in this PR Kenneth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants