forked from organicmaps/organicmaps
[editor] A method for getting a user's display name from API
This commit is contained in:
parent
ecb0ee1bca
commit
8c89278cdf
3 changed files with 36 additions and 1 deletions
|
@ -28,10 +28,16 @@ namespace
|
|||
ServerApi06 CreateAPI()
|
||||
{
|
||||
OsmOAuth auth = OsmOAuth::DevServerAuth();
|
||||
OsmOAuth::AuthResult result = auth.AuthorizePassword(kValidOsmUser, kValidOsmPassword);
|
||||
OsmOAuth::AuthResult const result = auth.AuthorizePassword(kValidOsmUser, kValidOsmPassword);
|
||||
TEST_EQUAL(result, OsmOAuth::AuthResult::OK, ());
|
||||
TEST(auth.IsAuthorized(), ("OSM authorization"));
|
||||
ServerApi06 api(auth);
|
||||
// Test user preferences reading along the way.
|
||||
osm::UserPreferences prefs;
|
||||
OsmOAuth::ResponseCode const code = api.GetUserPreferences(prefs);
|
||||
TEST_EQUAL(code, OsmOAuth::ResponseCode::OK, ("Request user preferences"));
|
||||
TEST_EQUAL(prefs.m_displayName, kValidOsmUser, ("User display name"));
|
||||
TEST_EQUAL(prefs.m_id, 3500, ("User id"));
|
||||
return api;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "std/sstream.hpp"
|
||||
|
||||
#include "3party/pugixml/src/pugixml.hpp"
|
||||
|
||||
namespace osm
|
||||
{
|
||||
|
||||
|
@ -103,6 +105,24 @@ OsmOAuth::ResponseCode ServerApi06::TestUserExists(string const & userName)
|
|||
return m_auth.DirectRequest(method, false).first;
|
||||
}
|
||||
|
||||
OsmOAuth::ResponseCode ServerApi06::GetUserPreferences(UserPreferences & pref) const
|
||||
{
|
||||
OsmOAuth::Response const response = m_auth.Request("/user/details");
|
||||
if (response.first != OsmOAuth::ResponseCode::OK)
|
||||
return response.first;
|
||||
pugi::xml_document details;
|
||||
if (!details.load_string(response.second.c_str()))
|
||||
return OsmOAuth::ResponseCode::NotFound;
|
||||
pugi::xml_node user = details.child("osm").child("user");
|
||||
if (!user || !user.attribute("id"))
|
||||
return OsmOAuth::ResponseCode::BadXML;
|
||||
pref.m_id = user.attribute("id").as_ullong();
|
||||
pref.m_displayName = user.attribute("display_name").as_string();
|
||||
pref.m_imageUrl = user.child("img").attribute("href").as_string();
|
||||
pref.m_changesets = user.child("changesets").attribute("count").as_uint();
|
||||
return OsmOAuth::ResponseCode::OK;
|
||||
}
|
||||
|
||||
OsmOAuth::Response ServerApi06::GetXmlFeaturesInRect(m2::RectD const & latLonRect) const
|
||||
{
|
||||
using strings::to_string_dac;
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
|
||||
namespace osm
|
||||
{
|
||||
struct UserPreferences
|
||||
{
|
||||
uint64_t m_id;
|
||||
string m_displayName;
|
||||
string m_imageUrl;
|
||||
uint32_t m_changesets;
|
||||
};
|
||||
|
||||
/// All methods here are synchronous and need wrappers for async usage.
|
||||
/// TODO(AlexZ): Rewrite ServerAPI interface to accept XMLFeature.
|
||||
|
@ -31,6 +38,8 @@ public:
|
|||
/// This function can be used to check if user did not confirm email validation link after registration.
|
||||
/// @returns OK if user exists, NotFound if it is not, and ServerError if there is no connection.
|
||||
OsmOAuth::ResponseCode TestUserExists(string const & userName);
|
||||
/// A convenience method for UI
|
||||
OsmOAuth::ResponseCode GetUserPreferences(UserPreferences & pref) const;
|
||||
/// Please use at least created_by=* and comment=* tags.
|
||||
bool CreateChangeSet(TKeyValueTags const & kvTags, uint64_t & outChangeSetId) const;
|
||||
/// nodeXml should be wrapped into <osm> ... </osm> tags.
|
||||
|
|
Loading…
Add table
Reference in a new issue