Skip to content

famhq/fam-sdk

Repository files navigation

Starfi.re SDK

The goal with Starfire is to build an open community for mobile gamers, starting with Clash Royale. Read the manifesto for more info.

A big part of that involves empowering other developers to take advantage of the amount of users on Starfire and build cool tools. Developers keep 100% of ad revenue in their tools.

If you're looking for inspiration, see IDEAS.md.

Install

Add to the top of <body>
Replace xxxx-xxxx-xxxx-xxxx with your appId.

<script>
(function(S,t,a,r,f,i,re){S[f]=S[f]||function(){
(S[f].q=S[f].q||[]).push(arguments)},S[f].l=1*new Date();i=t.createElement(a),
re=t.getElementsByTagName(a)[0];i.async=1;i.src=r;re.parentNode.insertBefore(i,re)
})(window,document,'script','//cdn.wtf/sdk/v1/starfire_sdk.js','Starfire');

Starfire('init', {appId: 'xxxx-xxxx-xxxx-xxxx'})
</script>

For these calls to work, the SDK needs to be framed within Starfire. You can test this with https://starfi.re/addon?testUrl=https://yoursite.com. I've considered making a REST API for use outside of Starfire, but I'm holding off on it since Supercell announced they are working on an official API.

Getting an appId

Email me (austin@clay.io) and I'll get you setup.

Demo addon

You can find a demo addon here. Feel free to improve on that if you want it to make it into Starfire :)

SDK Usage

Init

Starfire('init', {appId: 'xxxx-xxxx-xxxx-xxxx'})

Player

client.clashRoyale.player.getMe

Gets information about the current logged in user

// client.clashRoyale.player.getMe
// @param {Function} callback
Starfire('client.clashRoyale.player.getMe', function (err, me) {
  console.log(me)
})

/*
example response:
{
  "tag": "#PCV8",
  "name": "MOLT_YouTube",
  "expLevel": 13,
  "trophies": 5056,
  "bestTrophies": 5911,
  "wins": 8667,
  "losses": 5997,
  "battleCount": 16327,
  "threeCrownWins": 1937,
  "challengeCardsWon": 54302,
  "challengeMaxWins": 14,
  "tournamentCardsWon": 330,
  "tournamentBattleCount": 99,
  "role": "leader",
  "donations": 0,
  "donationsReceived": 0,
  "totalDonations": 12117,
  "clan": {
    "tag": "#YU2RQG9",
    "name": "PandaScheme",
    "badgeId": 16000139
  },
  "arena": {
    "id": 54000015,
    "name": "League 4"
  },
  "leagueStatistics": {
    "currentSeason": {
      "trophies": 5056
    },
    "bestSeason": {
      "id": "2017-07",
      "rank": 1613,
      "trophies": 5622
    }
  },
  "achievements": [
    {
      "name": "Team Player",
      "stars": 3,
      "value": 31,
      "target": 1,
      "info": "Join a Clan"
    },
    ...
  ],
  "cards": [
    {
      "name": "Dark Prince",
      "level": 8,
      "maxLevel": 7
    },
    ...
  ],
  "currentFavouriteCard": {
    "name": "Goblin Gang"
  }
}
*/
client.clashRoyale.player.getByTag

Gets information about a given user

// client.clashRoyale.player.getByTag
// @param {Object} params
// @param {String} params.tag
// @param {Function} callback
Starfire('client.clashRoyale.player.getByTag', {tag: 'PCV8'}, function (err, player) {
  console.log(player);
})

/*
example response:
{
  "tag": "#PCV8",
  "name": "MOLT_YouTube",
  "expLevel": 13,
  "trophies": 5056,
  "bestTrophies": 5911,
  "wins": 8667,
  "losses": 5997,
  "battleCount": 16327,
  "threeCrownWins": 1937,
  "challengeCardsWon": 54302,
  "challengeMaxWins": 14,
  "tournamentCardsWon": 330,
  "tournamentBattleCount": 99,
  "role": "leader",
  "donations": 0,
  "donationsReceived": 0,
  "totalDonations": 12117,
  "clan": {
    "tag": "#YU2RQG9",
    "name": "PandaScheme",
    "badgeId": 16000139
  },
  "arena": {
    "id": 54000015,
    "name": "League 4"
  },
  "leagueStatistics": {
    "currentSeason": {
      "trophies": 5056
    },
    "bestSeason": {
      "id": "2017-07",
      "rank": 1613,
      "trophies": 5622
    }
  },
  "achievements": [
    {
      "name": "Team Player",
      "stars": 3,
      "value": 31,
      "target": 1,
      "info": "Join a Clan"
    },
    ...
  ],
  "cards": [
    {
      "name": "Dark Prince",
      "level": 8,
      "maxLevel": 7
    },
    ...
  ],
  "currentFavouriteCard": {
    "name": "Goblin Gang"
  }
}
*/

Matches (battles)

client.clashRoyale.match.getAllByTag

Gets last 10 matches for a given tag

// client.clashRoyale.match.getAllByTag
// @param {Object} params
// @param {String} params.tag
// @param {Function} callback
Starfire('client.clashRoyale.match.getAllByTag', {tag: 'PCV8'}, function (err, matches) {
  console.log(matches);
})

/*
example response:
[
  {
    "type": "PvP",
    "battleTime": "20170902T201535.000Z",
    "deckSelection": "collection",
    "team": [
      {
        "tag": "#YL2QC0C",
        "name": "Aмiя ん",
        "startingTrophies": 5110,
        "trophyChange": 27,
        "crowns": 2,
        "clan": {
          "tag": "#Q8YRPV",
          "name": "Persian.gulf",
          "badgeId": 16000068
        },
        "cards": [
          {
            "name": "Fire Spirits",
            "level": 12,
            "maxLevel": 12
          },
          ...
        ]
      }
    ],
    "opponent": [
      {
        "tag": "#PCV8",
        "name": "MOLT_YouTube",
        "startingTrophies": 5083,
        "trophyChange": -27,
        "crowns": 1,
        "clan": {
          "tag": "#YU2RQG9",
          "name": "PandaScheme",
          "badgeId": 16000139
        },
        "cards": [
          {
            "name": "Bowler",
            "level": 7,
            "maxLevel": 7
          },
          ...
        ]
      }
    ]
  }
  ]
*/

Decks

client.clashRoyale.deck.getAllByTag

Gets last 10 decks for a given tag

// client.clashRoyale.deck.getAllByTag
// @param {Object} params
// @param {String} params.tag
// @param {Function} callback
Starfire('client.clashRoyale.deck.getAllByTag', {tag: 'PCV8'}, function (err, decks) {
  console.log(decks);
})

/*
example response:
[
  {
    "id": "751cd95c-20c0-418d-a221-f9b5b577b202",
    "deckId": "arrows|baby_dragon|cannon|fireball|goblin_gang|golem|mega_minion|skeleton_army",
    "deck": {
      "cardIds": [
        "5da558a9-b546-48d3-ac8e-5dc30ee5ff34",
        ...
      ],
      "averageElixirCost": 3.9,
      "wins": 2541,
      "losses": 2698,
      "draws": 587,
      "addTime": "2017-04-25T00:09:50.936Z"
    },
    "name": null,
    "wins": 24,
    "losses": 16,
    "draws": 6,
    "addTime": "2017-04-25T01:55:56.988Z"
  },
  {
    "id": "d62b42c2-b3fe-4ae7-82c4-452aecdb8685",
    "deckId": "battle_ram|fireball|freeze|ice_wizard|mega_minion|mini_pekka|the_log|valkyrie",
    "deck": {
      "cardIds": [
        "03d12926-3a09-46dc-b41d-33ba97ee0f8e",
        ...
      ],
      "averageElixirCost": 3.5,
      "wins": 929,
      "losses": 1317,
      "draws": 271,
      "addTime": "2017-08-01T01:30:28.424Z"
    },
    "name": null,
    "wins": 20,
    "losses": 9,
    "draws": 3,
    "addTime": "2017-08-01T01:30:28.424Z"
  }
]
*/

Version

Starfire('version', function (err, version) {
  console.log(version);
})

Coming soon

  • client.clashRoyale.user.getAllByTag
  • user info (verified and others sorted by lastActiveTime) in player.getByTag
  • client.clashRoyale.userRecord.getAllByTag
  • client.clashRoyale.clanRecord.getAllByClanTag
  • route to profile (or just route in general to a path)
  • client.forum.share
  • client.chat.share

SDK UI Usage (coming soon)

SDK UI calls may return an SDK UI element, which has a DOM node ($el) that may be appended to the DOM. E.g. miniProfile.$el

Contributing

Install pre-commit hook

ln -s ../../pre-commit.sh .git/hooks/pre-commit

npm install
npm run dev