From 2c3ba193e327a38558c4715956ddd80962192249 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Mon, 29 Sep 2014 16:38:44 +0800 Subject: [PATCH] add support for RubyGems --- README.rst | 7 +++++++ nvchecker/get_version.py | 2 +- nvchecker/source/gems.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 nvchecker/source/gems.py diff --git a/README.rst b/README.rst index ea9c204..a4ce302 100644 --- a/README.rst +++ b/README.rst @@ -122,6 +122,13 @@ Check `PyPI `_ for updates. pypi The name used on PyPI, e.g. ``PySide``. +Check RubyGems +-------------- +Check `RubyGems `_ for updates. + +gems + The name used on RubyGems, e.g. ``sass``. + Check Local Pacman Database --------------------------- This is used when you run ``nvchecker`` on an Arch Linux system and the program always keeps up with a package in your configured repositories for `Pacman `_. diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index 07bee45..93e0fb8 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -3,7 +3,7 @@ from importlib import import_module logger = logging.getLogger(__name__) handler_precedence = ( - 'github', 'aur', 'pypi', 'archpkg', 'pacman', + 'github', 'aur', 'pypi', 'archpkg', 'gems', 'pacman', 'cmd', 'gcode_hg', 'regex', 'manual', ) diff --git a/nvchecker/source/gems.py b/nvchecker/source/gems.py new file mode 100644 index 0000000..a0320a6 --- /dev/null +++ b/nvchecker/source/gems.py @@ -0,0 +1,17 @@ +import json +from functools import partial + +from tornado.httpclient import AsyncHTTPClient + +GEMS_URL = 'https://rubygems.org/api/v1/versions/%s.json' + +def get_version(name, conf, callback): + repo = conf.get('gems') or name + url = GEMS_URL % repo + AsyncHTTPClient().fetch(url, user_agent='lilydjwg/nvchecker', + callback=partial(_gems_done, name, callback)) + +def _gems_done(name, callback, res): + data = json.loads(res.body.decode('utf-8')) + version = data[0]['number'] + callback(name, version)