FreedomPop API

Thanks tonywagner for posting a link to this project in the FP thread:

Not that I'm volunteering (I'm not), but this could be the basis for "fun" FreedomPop Android or iOS project. Anyone interested? Discuss here!

Here's a repost of the source code from the repo (as of Feb 17, 2017), for discussion:

fpopclient/api.py

import urllib, urllib2, json, base64, datetime
from pprint import pprint

class FreedomPop:
    refreshToken = None
    token = None
    tokenExpireTimestamp = None
    accessToken = None

    _apiUsername = "3726328870"
    _apiPassword = "pNp6TIgVm4viVadoyoUdxbsrfmiBwudN"
    endPoint = "https://api.freedompop.com"
    
    def __init__(self, username, password):
        self.username = username
        self.password = password

    def _updateToken(self, url):
        req = urllib2.Request(url, data = "")
        req.add_header("Authorization", "Basic %s" % base64.encodestring("%s:%s" % (self._apiUsername, self._apiPassword)).replace("\n", ""))
        try:
            resp = urllib2.urlopen(req)
            data = json.loads(resp.read())
            self.accessToken = data["access_token"]
            self.refreshToken = data["refresh_token"]
            self.tokenExpireTimestamp = datetime.datetime.now() + datetime.timedelta(seconds = data["expires_in"])
        except urllib2.HTTPError, e:
            print "HTTP Error:", e.code
            print e.read()
            return False

        return True

    def _getAccessToken(self):
        params = urllib.urlencode(dict(username = self.username, password = self.password, grant_type = "password"))
        url = "%s/auth/token?%s" % (self.endPoint, params)
        return self._updateToken(url)

    def _refreshAccessToken(self):
        params = urllib.urlencode(dict(refresh_token = self.refreshToken, grant_type = "refresh_token"))
        url = "%s/auth/token?%s" % (self.endPoint, params)
        return self._updateToken(url)

    def initToken(self):
        if self.refreshToken is None:
            return self._getAccessToken()
        elif self.tokenExpireTimestamp < datetime.datetime.now():
            return self._refreshAccessToken()
        return True

    def _getBasic(self, command):
        if not self.initToken():
            return {}
        params = urllib.urlencode(dict(accessToken = self.accessToken))
        url = "%s/%s?%s" % (self.endPoint, command, params)
        try:
            buffer = urllib2.urlopen(url).read()
            return json.loads(buffer)
        except urllib2.HTTPError, e:
            print "HTTP Error:", e.code
            print e.read()
            return False

    def getUsage(self):
        return self._getBasic("user/usage")

    def getInfo(self):
        return self._getBasic("user/info")

    def getPlan(self, planId = None):
        if planId is None:
            return self._getBasic("plan")
        else:
            return self._getBasic("plan/%s" % planId)

    def getPlans(self):
        return self._getBasic("plans")

    def getService(self, serviceId = None):
        if serviceId is None:
            return self._getBasic("service")
        else:
            return self._getBasic("service/%s" % serviceId)

    def getServices(self):
        return self._getBasic("services")

    def getContacts(self):
        return self._getBasic("contacts")

    def getFriends(self):
        return self._getBasic("friends")

    def printMyInfo(self):
        usage = self.getUsage()
        inMB = 1024 * 1024
        endTime = datetime.datetime.fromtimestamp(usage["endTime"] / 1000) 
        delta = endTime - datetime.datetime.now()
        print "Data used: %0.2f%% (%0.2f MB of %0.2f MB) Time until quota reset: %d days %d hours (%s)" % (usage["percentUsed"] * 100, usage["planLimitUsed"] / inMB, usage["totalLimit"] / inMB, delta.days, delta.seconds / 3600, endTime )


def run(username, password):
    fp = FreedomPop(username, password)
    fp.printMyInfo()
    """
    Full list of methods:
    fp.getUsage()       # get the data usage, begin/end quota period, quota MB bonuses.
    fp.getPlan()        # get current plan
    fp.getPlans()       # list of available plans
    fp.getService()     # get current subscribed service
    fp.getServices()    # list of available services
    fp.getInfo()        # get the account's first/last name, last login time, email address
    fp.getFriends()     # list of people friended this account
    fp.Contacts()       # I'm not sure what this for
    # there are some other API that can update/write to your account that I reluctant to expose it here...
    
    """

if __name__ == "__main__":
    import sys
    if len(sys.argv) < 3:
        print "Usage: python api.py <username> <password>"
        sys.exit()

    run(sys.argv[1], sys.argv[2]) 

Usage

$ python api.py yourfreedompop@email.com thepassword Data used: 19% (204.00 MB of 1100.00 MB) Time until quota reset: 23 days 19 hours (2013-09-27 20:00:00)

License

The MIT License (MIT)

Copyright (c) 2013 Dody Suria Wijaya

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

So, apparently, there's an undocumented FreedomPop API that exposes the following endpoints, which can be used by client apps:

https://api.freedompop.com/user/usage
https://api.freedompop.com/user/info
https://api.freedompop.com/plan
https://api.freedompop.com/plan/{PlanID}
https://api.freedompop.com/plans
https://api.freedompop.com/service
https://api.freedompop.com/service/{ServiceID}
https://api.freedompop.com/services
https://api.freedompop.com/contacts
https://api.freedompop.com/friends

Obviously, since this unofficial and unsupported, this could be shutdown at any time without notice. Considering that FP actually sells usage alerts as part of their "premium" services (up-sells), I wouldn't be surprised if FP did indeed shut this down if an independent developer actually built an app that took advantage of these APIs. Basically, use at your own risk!

@hungryhost
Not that I'm volunteering (I'm not), but this could be the basis for "fun" FreedomPop Android or iOS project.

C'mon you know you can do it, we know you can do it, and it will be "fun" for you. Hope it's legal, though.