Clicky

Hello Gurus, Sages, and future Legends,
This is going to get very geeky so bear with me. I don't need specific examples but general advise is most welcome.

I made a fun map tool for use with the online game, Eve Online. It gets really useful though after I can plug into Eve Online's API to gather and verify character info, opening the possibility of tracking in-game characters, out-of-game.

To make this happen I was thinking about creating an "eve character data" content type. The user enters an API id and key, then hits save. After that, magic happens. Before the save is complete, an API request is made to gather and populate character portraits, names, etc., or return to the form with a validation error.

How do I make the magic happen? First guess is to create a custom module that makes use of Rules module to handle triggers and actions. I do need to make use of an external php class for this, so having a separate module seems ideal.

Any general thoughts on how to get started? I haven't made a ton of modules, so I'm still a bit disoriented on where to begin in regards to this unique endeavor. I'm creating this for Drupal 7 (another thing I'm catching up on).

Thanks a ton in advance. :D

asked 07/16/2011 08:46

Ultrus's gravatar image

Ultrus ♦♦


4 Answers:
The Drupal part is above my pay grade, but I can tell you that the other part - talking to the API - is pretty straightforward.  It appears that you may be able to use file_get_contents() with a URL and an argument string.  You may need to make POST requests instead of GET requests.  If that is the case you can use CURL to make the requests, and if the API appears to be unstable or slow, you may want to choose CURL over file_get_contents().

The API will return a data string in the browser output stream, so it's almost like reading a file.

The XML string that comes back from the API can be processed via SimpleXML.  The code snippet has an example from the "Full API Key" on this page:
http://wiki.eve-id.net/APIv2_Eve_CharacterInfo_XML

Note that PHP error_reporting(E_ALL) does not flag attempts to access an undefined property of a SimpleXML object.  Be mindful of that in your OOP programming.

Hope that's useful, ~Ray
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
<?php // RAY_temp_ultrus.php
error_reporting(E_ALL);

// SIMULATE THE STRING RETURNED BY THE API
$xml = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<eveapi version="2">
  <currentTime>2010-10-05 19:41:58</currentTime>
  <result>
    <characterID>1643072492</characterID>
    <characterName>Catari Taga</characterName>
    <race>Caldari</race>
    <bloodline>Achura</bloodline>
    <accountBalance>9999.29</accountBalance>
    <skillPoints>9999</skillPoints>
    <shipName>.</shipName>
    <shipTypeID>24694</shipTypeID>
    <shipTypeName>Maelstrom</shipTypeName>
    <corporationID>553239300</corporationID>
    <corporation>Centre Of Attention</corporation>
    <corporationDate>2009-02-03 13:06:00</corporationDate>
    <allianceID>1923227030</allianceID>
    <alliance>Middle of Nowhere</alliance>
    <alliancenDate>2009-02-03 13:06:00</alliancenDate>
    <lastKnownLocation>FD-MLJ VII - Moon 2 - Intaki Bank Investment Bank</lastKnownLocation>
    <securityStatus>0.0</securityStatus>
  </result>
  <cachedUntil>2010-10-05 20:41:58</cachedUntil>
</eveapi>
XML;

// MAKE AN OBJECT
$obj = SimpleXML_Load_String($xml);

// ACTIVATE THIS TO VISUALIZE THE OBJECT
// var_dump($obj);

// SHOW SOME OF THE PROPERTIES
$r = (string)$obj->result->race;
$b = (string)$obj->result->bloodline;
$s = (string)$obj->result->securityStatus;
echo "YOU ARE OF THE $b BLOODLINE OF THE $r RACE AND YOUR SECURITY STATUS IS $s <br/>";

// SHOW AN UNDEFINED PROPERTY
$x = $obj->foo;
var_dump($x);
link
Ray_Paseur's gravatar image

Ray_Paseur

Ray_Paseur,
Thanks for the feedback. If no one answers on the Drupal related items, I'll give you brownie points for the interesting string format. I haven't used it before and like it.

I'm not having issues with the API side and even have the API work being done for me using this script. The challenge is hooking it into Drupal to be triggered at node save time and acted upon it in a "Drupal friendly" way.

So far the following links are potentially helpful:

Creating Drupal 7.x modules
http://drupal.org/node/361112

Drupal custom Rules how to write your own events conditions, actions and custom object (+custom tokens)
http://dominiquedecooman.com/blog/drupal-custom-rules-how-write-your-own-events-conditions-actions-and-custom-object-custom-token

Migrating the Drupal way. Part I: creating a node.
http://acquia.com/blog/migrating-drupal-way-part-i-creating-node
link
Ultrus's gravatar image

Ultrus

Hi Ray,
I think I have it figured out. I'm going to use the rules module in combination with the web service client module as seen below in order to verify character info:
http://drupal.org/node/1114218

More about the character API here:
http://wiki.eve-id.net/API#Introduction

Since no one else has an answer, I'll give you the points as I like your string formatting tip.

Congrats on your overall points!! Over 2,000,000 in PHP! I've learned quite a bit from your posts and appreciate your feedback.

Best regards,

Chris
link
Ultrus's gravatar image

Ultrus

Thanks for the points, hope it's all headed in the right direction now, ~Ray
link
Ray_Paseur's gravatar image

Ray_Paseur

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×21
×1
×1
×36
×1
×1
×2
×18

Asked: 07/16/2011 08:46

Seen: 367 times

Last updated: 09/02/2011 02:45