diff options
author | Azul <azul@riseup.net> | 2016-06-08 12:44:38 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-06-08 12:54:23 +0200 |
commit | a89e2ba55399e6bddd9e052cf2064ed0056c958a (patch) | |
tree | c28ec332f9763f395a88db991defcae59fa46806 /lib/nickserver/adapters | |
parent | 712c1d062c08a58ca8772aafcdc39d0281959b4a (diff) |
refactor: use new couch_db classes from fetch_key
This moves all the em_http related stuff into a single adapter.
We're also not using callback and errback inside fetch_key or
server for couch requests anymore.
Changing the interface for hkp to do the same will follow.
Diffstat (limited to 'lib/nickserver/adapters')
-rw-r--r-- | lib/nickserver/adapters/couch_db.rb | 12 | ||||
-rw-r--r-- | lib/nickserver/adapters/em_http.rb | 24 |
2 files changed, 24 insertions, 12 deletions
diff --git a/lib/nickserver/adapters/couch_db.rb b/lib/nickserver/adapters/couch_db.rb deleted file mode 100644 index e8a23ad..0000000 --- a/lib/nickserver/adapters/couch_db.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'nickserver/adapters' - -class Nickserver::Adapters::CouchDB - - - protected - - def query_couch(nick) - yield 404, "{}" - end - -end diff --git a/lib/nickserver/adapters/em_http.rb b/lib/nickserver/adapters/em_http.rb new file mode 100644 index 0000000..16db5ae --- /dev/null +++ b/lib/nickserver/adapters/em_http.rb @@ -0,0 +1,24 @@ +require 'nickserver/adapters' +require 'em-http' + +module Nickserver::Adapters + class EmHttp + + def initialize + @timeout = 5 + end + + def get(url, options = {}) + get_request(url, options).callback {|http| + yield http.response_header.status, http.response + }.errback {|http| + yield 0, http.error + } + end + + def get_request(url, options = {}) + @request = EventMachine::HttpRequest.new(url) + @request.get timeout: @timeout, query: options[:query] + end + end +end |