summaryrefslogtreecommitdiff
path: root/lib/nickserver/adapters
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-06-15 14:22:08 +0200
committerGitHub <noreply@github.com>2016-06-15 14:22:08 +0200
commit3c6dc3d7b902b46b82a3d8cd38bd3fa896024beb (patch)
tree559b3998465248138b6f24a76b6b3e55e60f3986 /lib/nickserver/adapters
parent5cad637a4a2a3de6b95ff1204fc29174e18b3124 (diff)
parent93258bd6fe6247e7af67f423243eba9808e920ee (diff)
Merge pull request #3 from azul/refactor/transport-adapters
Refactor em specifics into http adapter
Diffstat (limited to 'lib/nickserver/adapters')
-rw-r--r--lib/nickserver/adapters/em_http.rb24
-rw-r--r--lib/nickserver/adapters/local.rb8
-rw-r--r--lib/nickserver/adapters/remote.rb4
3 files changed, 36 insertions, 0 deletions
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
diff --git a/lib/nickserver/adapters/local.rb b/lib/nickserver/adapters/local.rb
new file mode 100644
index 0000000..d6210c3
--- /dev/null
+++ b/lib/nickserver/adapters/local.rb
@@ -0,0 +1,8 @@
+require 'nickserver/adapters'
+
+class Nickserver::Adapters::Local
+
+ def query(nick)
+ end
+
+end
diff --git a/lib/nickserver/adapters/remote.rb b/lib/nickserver/adapters/remote.rb
new file mode 100644
index 0000000..e12bd26
--- /dev/null
+++ b/lib/nickserver/adapters/remote.rb
@@ -0,0 +1,4 @@
+require 'nickserver/adapters'
+
+class Nickserver::Adapters::Remote
+end