Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 15 additions & 34 deletions foaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,7 @@ def html(self):


class Fuck(object):
actions = {
'awesome': 'awesome/{from}',
'ballmer': 'ballmer/{name}/{company}/{from}',
'because': 'because/{from}',
'bus': 'bus/{name}/{from}',
'bye': 'bye/{from}',
'caniuse': 'caniuse/{name}/{from}',
'chainsaw': 'chainsaw/{name}/{from}',
'cool': 'cool/{from}',
'diabetes': 'diabetes/{from}',
'donut': 'donut/{name}/{from}',
'everyone': 'everyone/{from}',
'everything': 'everything/{from}',
'fascinating': 'fascinating/{from}',
'field': 'field/{name}/{from}/{reference}',
'flying': 'flying/{from}',
'king': 'king/{name}/{from}',
'life': 'life/{from}',
'linus': 'linus/{name}/{from}',
'madison': 'madison/{name}/{from}',
'nugget': 'nugget/{name}/{from}',
'off': 'off/{name}/{from}',
'outside': 'outside/{name}/{from}',
'pink': 'pink/{from}',
'thanks': 'thanks/{from}',
'that': 'that/{from}',
'thing': '{thing}/{from}',
'this': 'this/{from}',
'shakespeare': 'shakespeare/{name}/{from}',
'what': 'what/{from}',
'xmas': 'xmas/{name}/{from}',
'yoda': 'yoda/{name}/{from}',
'you': 'you/{name}/{from}',
}
actions = {}

def __init__(self, secure=False, language=None):
self.secure = secure
Expand Down Expand Up @@ -115,6 +82,19 @@ def random(self, **kwargs):
choice = getattr(self, random.choice(applicable_actions))
return choice(**kwargs)

def load_actions(self):
"""
Get the current operations from foaas.com
"""
url = "https://foaas.com/operations"
fucks = requests.get(url)
for eachFuck in fucks.json():
action = eachFuck['url'].split("/")[1]
fields = ""
for eachField in eachFuck['fields']:
fields += "{{{}}}/".format(eachField['field'])
self.actions[action] = "{}/{}".format(action, fields)

def build_url(self, path, **kwargs):
# use from_ since from is a keyword. *grumble*
params = dict([(k.rstrip('_'), quote(v)) for k, v
Expand All @@ -126,6 +106,7 @@ def build_url(self, path, **kwargs):


fuck = Fuck()
fuck.load_actions()

if __name__ == '__main__':
parser = OptionParser()
Expand Down
6 changes: 3 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ def setUp(self):

def test_url(self):
url = self.fuck.off(name='Alice', from_='Bob').url
self.assertEqual('http://foaas.herokuapp.com/off/Alice/Bob', url)
self.assertEqual('http://foaas.herokuapp.com/off/Alice/Bob/', url)

def test_url_secure(self):
secure_fuck = Fuck(secure=True)
url = secure_fuck.everything(from_='Bob', secure=True).url
self.assertEqual('https://foaas.herokuapp.com/everything/Bob', url)
self.assertEqual('https://foaas.herokuapp.com/everything/Bob/', url)

def test_url_quoting(self):
url = self.fuck.donut(name='Alice!', from_='Bobby McGee').url
self.assertEqual('http://foaas.herokuapp.com/donut/Alice%21/Bobby%20McGee', url)
self.assertEqual('http://foaas.herokuapp.com/donut/Alice%21/Bobby%20McGee/', url)

def test_html(self):
html = self.fuck.thanks(from_='Bob').html
Expand Down