Skip to content
TORNLIFE More

Numbers are strings... Sometimes

Started by Mauk [1494436] on in API Development.

9 replies · 160 views · thread synced · 5 days ago · View on torn.com
About this thread

Posts archived: 10 / 10 posts (100%) · the total is Torn's reply count + the opening post at the last fetch

Counted by TornLife from the archived posts.

Archived posts
10
Discussion span
→
People posting
6
Likes on archived posts
10
Posts by staff, officers and moderators
1
Authority score
74 / 100
Historical score
33 / 100
Story score
32 / 100
Engagement score
54 / 100

Mentioned in this thread

MrsMojoMofo [376991] ×1 MOJOMOFO [627688] ×1 FloydPinkus [970212] ×1 Jammed [1531835] ×1

Mauk [1494436]

The API is pretty inconsistent right now. Come on, numbers should be numbers, not strings:
{ "server_time": "1448649354", "chain": 0, "happy": { "current": 4871, "maximum": "5025", "increment": 5, "interval": 900, "ticktime": 546, "fulltime": 27546 }, "life": { "current": "2271", "maximum": "2271", "increment": 227, "interval": 300, "ticktime": 246, "fulltime": 0 }, "energy": { "current": 55, "maximum": "150", "increment": 5, "interval": 600, "ticktime": 246, "fulltime": 11046 }, "nerve": { "current": 29, "maximum": "50", "increment": 1, "interval": 300, "ticktime": 246, "fulltime": 6246 }, "notifications": { "messages": "0", "events": "0", "awards": "0", "newspaper": "0", "competition": "0" }}Can we get a fix? While it's easy to ignore this in languages like Javascript and PHP, it isn't as pleasant in more strict languages.
McNeo [864688]

I ran into this as well, but converting string to integer data type is no biggy. I've written in this check because, even if it is fixed, who knows if it will crop again. Error handling, woooo!
LouBaker [1162207]

I strip all the quotes and commas out making it all string

{
server_time : 1448922843
happy : {
current : 4442
maximum : 4500
increment : 5
interval : 900
ticktime : 657
fulltime : 10557
}
life : {
current : 4218
maximum : 4218
increment : 421
interval : 300
ticktime : 57
fulltime : 0
}

each line is split at the colon(:) and save in a Array(KeyName, Result)

a routine is then called to read the KeyNames and return the Result

Result = api_GetKeyName(server_time)
Result = 1448922843

the routine handles the diffent sections of KeyNames

Result = api_GetKeyName(happy.current )
Result = 4218

the Result can be handled how ever you want
McNeo [864688]

I'm doing almost the same thing in my VB .NET app. Then I query my own matrix when I need data and the background queries the API when new data is needed.
LouBaker [1162207]


I'm using a system of Array()s to store the fetched data

the 6 APITYPE
  1. user
  2. property
  3. faction
  4. company
  5. market
  6. torn
and up to 27 SELECTIONS in the APITYPE

I'm using these numbers to form a

STRING_ARRAY$(APITYPE = 6, SELECTIONS = 27 ) = Downloaded API Data


these STRING_ARRAY$(6, 27) is the storeage string$ for the API Download Data

these can be re-read or redownload if needed with an other part to the

STRING_ARRAY$(APITYPE, SELECTIONS, REFRESH =True/False)

examples:

api.torn.com/user/?selections=networth&key=<yourApiKey>

This is stored as STRING_ARRAY$(user = 1, selections = 1, refresh)

and api.torn.com/faction/?selections=attacks&key=<yourApiKey>

is stored as STRING_ARRAY$(faction = 3, selections = 19, refresh)


The numbers in the Array can be read as a single number, like an number ID: 319

user.networth = ID: 11
Faction.attacks = ID: 319

using the ID:number instead of full text fashion.. faction.armorynews can be replace with ID:314

example: CallTornAPI(314)


there more to come on this. working on extentions like: user.profile.life.current = ID:12217

arn't the colors pretty

:)

Edit: Torn Editor Sucks
Edit: again, twice now
Edit: 3, why is this so small this edit box
Edit: omg
Edit: almost finished
Edit: the Preview Edit tells lies
Edit: Finally :)

McNeo [864688]

Little different in VB .NET but same idea.

I have a sub which I pass a category, selection, and ID to. I then query "https://api.torn.com/" & sCategory & "/" & sUseID & "?selections=" & sSelections & "&key=" & sAPIKey

From there I parse the data into a matrix, one array is the field and the second is the value. For the array with the field names I use the category and ID from the API to sort it.

For example, in the first array, the field for the user's faction name is stored under "user864688factionfaction_name". Incorporating the ID in this is important because I may be looking up other users as well, so the data would become duplicated.

When I want to retrieve data, I have a function that returns the value, the only thing I pass the function is the field name as described above.

When new data is read form the API, it first checks the matrix to see if the field already exists and overwrites it, if not, it's appended to the end. This way I can look up any data at any time, and make different API requests at different intervals to only update the appropriate information when it's needed.
LouBaker [1162207]

Using Strings to store then simple APIs is easy, and writing the routine wasn't a bother reading

"level": "65",
"gender": "Male",
"status": "Civilian",
"player_id": "1162207",
"name": "LouBaker",

My routine sorted out the quotes and endoflines to give the above which is put in there Arrays() as i said above

But i came a bit unstuck when i tried Faction mainnews

"news": "<a href = "http://www.torn.com/profiles.php?XID=970212" class="h">FloydPinkus</a>,

"news": "The faction successfully initiated a planned robbery! [<a href = "http://www.torn.com/organisedcrimes.php?step=log&ID=4734327">Details</a>]""news": "<a href=http://www.torn.com/profiles.php?XID=376991>MrsMojoMofo</a> sent an application to join the Faction.""news": "<a href = "http://www.torn.com/profiles.php?XID=627688" class="h">MOJOMOFO</a>, <a href = "http://www.torn.com/profiles.php?XID=1531835" class="h">...... ect ect


So I'v had to do a lot of Jiggling about with another String Routine.
removing or replacing parts so the data can be used in the main Routine

Kinda sucks when your trying to keep every thing compacked.
and there probably a lot more i havnt seen yet

anyone having trouble with this

Remember I am using Visual Basic and dont have the comfort zone JSON gives.


Edit:
the Text Above is not the same as i put in, because the editor removed a load of stuff
I not going to rewrite it all, i guess you know what im saying tho

Edit:
Text Wrap doesn't seem to be working in the editor either


Mentions: FloydPinkus [970212] · Jammed [1531835] · MOJOMOFO [627688] · MrsMojoMofo [376991]

archimede [1565089]

Having strings instead of numbers can be annoying if, for example, you want to sort a collection (eg. sort faction members by days_in_faction). And I suppose this is true for any programming language.

I agree it should be fixed: R+.