Sorrow.7384:

Hey guys,

I wrote a PHP SDK. Would appreciate some help adding more functionality to it once Arenanet improves the API (like adding straight up server incomes and Objective values etc..)

https://github.com/defunctl/Gw2-SDK

You can see a little example I whipped up to see whakitten ’s capable of:

http://sdk.teamriot.org/

omniomi.7351:

I used the SDK to create a simple Joomla module.

mod_wvwscores.php

<?php
/**
* WvW Scores Modules
*
* @version              $Id: mod_wvwscores.php 172 2013-05-23 01:44:00Z omniomi $
* @license              GNU/GPL - http://www.gnu.org/copyleft/gpl.html
*/

// No direct access
defined('_JEXEC') or die;

// Required
require (dirname(__FILE__).'/src/vesu/SDK/Gw2/Gw2SDK.php');
require (dirname(__FILE__) .'/src/vesu/SDK/Gw2/Gw2Exception.php');
use \vesu\SDK\Gw2\Gw2SDK;
use \vesu\SDK\Gw2\TwitchException;

$gw2 = new Gw2SDK(dirname(__FILE__).'/cache');

$matches = $gw2->getMatchByWorldId(1019);

foreach($matches as $match):
    // This grabs just the scores from the match details
    $scores = $gw2->getScoresByMatchId($match->wvw_match_id);

?>

<div class="wvw_match">
    <div class="server red" style="color: #b80202;font-weight: bold;"><?php echo $gw2->parseWorldName($match->red_world_id) ?>: <span style="color: #fff;font-weight: normal;"><?php echo number_format($scores[0]); ?></span></div>
    <div class="server blue" style="color: #3d63d1;font-weight: bold;"><?php echo $gw2->parseWorldName($match->blue_world_id) ?>: <span style="color: #fff;font-weight: normal;"><?php echo number_format($scores[1]); ?></span></div>
    <div class="server green" style="color: green;font-weight: bold;"><?php echo $gw2->parseWorldName($match->green_world_id) ?>: <span style="color: #fff;font-weight: normal;"><?php echo number_format($scores[2]); ?></span></div>
</div>

<?php
endforeach;

// END

?>

mod_wvwscores.xml

<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.0.0">
   <!-- Name of the Module -->
        <name>WvW Scores</name>

    <!-- Name of the Author -->
        <author>omniomi with SDK by Sorrow.7384</author>

    <!-- Version Date of the Module -->
        <creationDate>2013-05-23</creationDate>

    <!-- Copyright information -->
        <copyright>None</copyright>

    <!-- License Information -->
        <license>GPL 2.0</license>

    <!-- Author's email address -->
        <authorEmail>REDACTED</authorEmail>

    <!-- Author's website -->
        <authorUrl>http://www.REDACTED.com</authorUrl>

    <!-- Module version number -->
        <version>1.0.0</version>

    <!-- Description of what the module does -->
        <description>Provides WvW Scores</description>

    <!-- Listing of all files that should be installed for the module to function -->
        <files>
        <!-- The "module" attribute signifies that this is the main controller file -->
                <folder>src</folder>
                <folder>cache</folder>
                <filename module="mod_wvwscores">mod_wvwscores.php</filename>
                <filename>index.htm</filename>
        </files>

    <!-- Optional parameters -->
        <params />
</install>

The src file from the git repo is included in the mod_wvwscores folder and the structure is untouched. The only change I made was the cache time down to 10 minutes.

When I have a bit more time I will integrate joomla caching and make the server ID an option on the module page; for now it’s hard coded in mod_wvwscores.php.

omniomi.7351:

Here’s a screenshot of the module.

Sorrow.7384:

You shouldn’t need to modify the SDK to change the cache, you can do it right in your joomla module

$scores = $gw2->getScoresByMatchId($match->wvw_match_id, 600); // cache for 600 seconds

omniomi.7351:

Fair point, I am going to completely rip out the caching though and use the caching built into Joomla/JAT3. That way I can add a LifeTime variable to the module config page which if unset will use the Joomla global lifetime and so that if necessary people can disable caching on the fly.

Once I’m done people should be able to install the tar-ball and do all the config from Extensions -> Modules.

Sorrow.7384:

Nice!

You can disable caching by not including a caching dir.

e.g. $gw2 = new Gw2SDK();

If caching is enabled, each call has its own cache time so you could just pass your global lifetime to them. Some of them are cached for a day (like matches, world list etc…) because they rarely update.

Hopefully they add income right into the Match Details, or at the very least fix their Objectives to include their weight so we can add the +300 to the scores. I know people have provided their own json files for this, but I want this SDK to only represent what the actual API has to offer.

Glad someone found some use for it!

Valento.9852:

This is so awesome, thank you!

Sorrow.7384:

You’re welcome! Patches are also welcome if any of you guys are PHP devs.

Eolh.5436:

Hi guys, sorry for my bad english, but i really need help. I want to create a simple module for joomla 2.5 like omniomi one. I put in the zip archive: the src folder, the php and xml files. Now, when i install the module, joomla gives me this error:
JInstaller: :Install: file dosent exist /var/www/vhosts/nameofmydomain/httpdocs/tmp/install_51e000884c590/com_WvW/cache

You can help me please?

Hardist.3104:

Sorry for the bump, but better that than creating a whole new topic since my question is mostly relevant for this. Small question about this. I used that small code what omniomi wrote in combination with the PHP SDK. The only thing I want is to show the “Points Per Tick” aswell on my website, for my server. Any “fix” for this yet, seeing as how with the above information it wasn’t possible yet?

smiley.1438:

You might want to have a look at this:

https://github.com/codemasher/gw2-wvwstats/blob/master/classes/gw2api.class.php#L181

Hardist.3104:

Thanks a lot, will play around with that! Thank you!

ljubo.8793:

Hello and thanks for this great post,
I would like if someone can make .zip module for Joomla 2.5/3.0 with this WWW stats, and second one with Dragon timer.