Limiting the REST API attributes Based on User - api

I have an REST API
Fruits {
Apple:10
Orange: 12
}
Price{
Apple:110.9
Orange:90,8
}
I need Mr X will access All the attributes and Mr Y shouldnt access Price values. Any solution for this.

Related

Get Account ID in PUBG API

I'm trying to get a PUBG player's details using the Players developer API.
I'm aware that both the operations of this Players API require the account ID of the respective player, whose account details are required.
However, I tried my best to find the account ID (starting with account. and having 32 alphanumeric characters), but all in vain.
In this aspect, I've two specific questions:
How can I find my PUBG account ID?
If I want to fetch other players' details via API, how do I get their account ID programmatically? Or should I need to ask for their account ID explicitly?
Use filter[playerNames]=myPlayerName as shown in the player docs
On succes, it wil return a object containing the account_id;
https://api.pubg.com/shards/steam/players?filter[playerNames]=myPlayerName
{
"data": [
{
"type": "player",
"id": "account.c0e511111111111893af",
...
Replace myPlayerName with the username you're looking for.
edit;
This Community Manager says that only - and _ are allowed in nicknames, url-escaping won't be necessary!

How to find a set of users are following or followed by another particular user using the Twitter API?

I want to know if there is any Twitter API via which I can get to know that if the set of users either following or followed by a particular user.
For example:
set_of_users are: { a,b,c}
particular user is: d
Then the result is a kind of
a:
following: true //(means a is following d)
friend: true //(means d is following a)
b:
following: false //(means b is not following d)
friend: false // (means
c:
following: false //(means c is not following d)
friend: true //(means c is following d)
Also, some API which tells it a, b, c, and d are all interconnected with each other as friend or follower?
You can use the friends/ids endpoint for friends:
https://dev.twitter.com/rest/reference/get/friends/ids
Use the followers/ids endpoint for followers:
https://dev.twitter.com/rest/reference/get/followers/ids
These return ids, which is good because it's fast and lets you pull in the whole list with a smaller number of queries.
Once you have id's, use the users/lookup endpoint to pull in user data. It has a user_id parameter that you can use to gather multiple user records at a time, via a comma-separated list of id's:
https://dev.twitter.com/rest/reference/get/users/lookup
If you're new, you should visit the Twitter Documentation page and review Overview and Best Practices. These will answer a lot of questions you'll have. e.g. the type of querying you'll be doing will likely cause you to bump into rate limits, so reading up on that will save a lot of frustration later.
https://dev.twitter.com/overview/documentation
There isn't an API to manage graphs.

Haproxy map: Mapping 1 ID to multiple rows

I am trying to achieve a form of authentication in HAProxy where 1 authentication ID can be mapped to multiple data ID's which pretty much restrict data access to my Api's when in the user is calling them. I want to do this in a map file since these ID's are going to change very frequently. So writing individual rules isn't plausible.
So in theory I want to do this:
user X calls endpoint with data ID 123. User is given access.
user X calls endpoint with data ID 456. User is given access.
user y calls endpoint with data ID 123. User is denied access.
Example map file:
Left coloumn is ID and right is DataID
X 123
X 456
X 789
Y 121
Y 111
Z 123
Is this doable? If not, what would be a good alternative to mimic this behavior?
The key (left column) should be unique in your case.
That said, this is perfectly doable with a map file like the one below:
X-123 allow
X-456 allow
X-789 allow
Y-121 allow
Y-111 allow
Z-123 allow
First, you must concatenate both username and data-id in a temporary HTTP header, then you use it like:
http-request set-header X-my-internal-key %[req.hdr(Username)]-%[req.hr(myendpoint_id)]
http-request deny unless { req.hdr(X-my-internal-key),map(/path/to/mapfile.map) -m found }
Baptiste

Apex - SalesForce - Accessing a Parent object field through Junction object

Hello Folks,
I am working on customizing some functionality on the Force.com platform. I have a question for you; I am not too sure if this is possible!
What I have? : 2 custom objects - abc and pqr. Abc is the junction object between the Standard object Account and pqr i.e. Account is the parent of abc and then Pqr is the parent of abc. I am retrieving everything through these objects into a List of type Account (i.e. from Account object).
What I need? : I can access the abc object in Apex i.e. the First child of Account. Is there a possibility to access the fields of pqr through account?
What I have tried : Accessing the object through relationship name - Account.abc_r[0].pqr_r[0].FIELDNAME
But it hasnt worked. Could some salesforce/apex developer help me with this?
You should be able to get the information you need using a subquery. The real question here is how your query is setup. Your query will need to access all levels of the data model for it to be available. If you are relying on data returned in a trigger or standard controller then I would recommend requiring the account object to get access to the additional information.
So I would expect to see something along the lines of:
List<Account> accounts = [SELECT Id, Name, (SELECT Id, pqr__r.Id, pqr__r.Name FROM abc__r) FROM Account];
for (Account acct : accounts) {
string someValue = acct.abc__r[0].pqr__r.Name;
}
Keep in mind though that as a best practice you shouldn't access the child records the way I did above because if there are no ABC records that object will be null so as a best practice you will want to test for that ahead of time. Same goes for PQR object data.
The answer to this question is the following:
List<Account> accounts = [SELECT Id, Name, (SELECT Id, pqr__r.Id, pqr__r.Name FROM abc__r) FROM Account];
for (Account acct : accounts) {
for(Abc__c abc : acct.abc__r)
{
String someValue = abc.pqr__r.Name;
}
}
Note: Here, abc_r is the relationship of object Abc_c with Account. Please comment on this if you have any questions.

how to get the latitude or longitude in HTML 5

few month ago i write something to get the latitude or longitude from google API. latter i get the database from drupal for latitude or longitude to most of city in worlds.
but the problem is that the same city name can be found two or more times in a area. like Firozabad in India and bangladesh both. Agra in UP and agar in Rajasthan.
means the confusion in name by user if they found two city by same name they are confused.
i hear that HTML 5 support latitude or longitude of the visiter but i need latitude or longitude where they are born or city they want to use to fill a form.
how i can get the latitude or longtiude from API like google and some other.
the process is that:
user put the location in textbox for getting their latitude or longitude.
for right thing i want to show them all location [if same thing found more then one].
they can choose the right location and after click they can get the lati and langitude.
how i can do this using any API.
If I understood you correctly then here's a Javascript function that returns a list of actual locations based on the address (full or partial) that user has entered:
getLocationsByAddress = function(address, onComplete) {
var geocoder = null;
var locations = [];
var location = null;
geocoder = new GClientGeocoder();
geocoder.getLocations(address, function(response) {
if (!response || response.Status.code != 200) {
if (typeof (onComplete) != 'undefined') {
onComplete([]);
}
} else {
for (var i = 0; i < response.Placemark.length; i++) {
location = response.Placemark[i];
locations[locations.length] = {
address: location.address,
x: location.Point.coordinates[1],
y: location.Point.coordinates[0],
zoom: 14
}
}
if (typeof (onComplete) != 'undefined') {
onComplete(locations);
}
}
});
}
The code uses API version 2 but I think it should be fairly easy to make it work with V3 (please see this API reference for details).
UPDATE
As #Maxym stated the V2 API is considered as deprecated and therefore shouldn't be used any further.
Take a look at this jQuery plugin. It claims to work with both V2 and V3 so you may want to examine the source code in order to find out how they do an it with V3.
I am not sure that it is about HTML 5. You just need to create sort of hints, where user can select which exactly city she means (the way Google does on maps.google.com - you enter "Odessa" and see list of cities with such name). Google has geocoder API but probably it should be used with Google Map (just read license).
So the process is easy: user enters city, you send it to geocoder to get list of cities with such a name and their coordinates. THen you show that list, user selects one and you have its coordinates.
There is documentation how to use Geocoding API v3 in JavaScript, as well as examples. This one show how to get coordinates from address, take into account that they process results[0] only, but you need to iterate over results to get all cities.