Class: Yandex::Client
- Inherits:
-
Object
- Object
- Yandex::Client
- Defined in:
- lib/yandex_metric.rb
Class Method Summary collapse
- .client(args = {}) ⇒ Object
- .default_args ⇒ Object
- .delete(args = {}) ⇒ Object
- .encode_params(prms) ⇒ Object
- .get(args = {}) ⇒ Object
- .post(args = {}) ⇒ Object
- .put(args = {}) ⇒ Object
- .result(res) ⇒ Object
Class Method Details
.client(args = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/yandex_metric.rb', line 23 def self.client args = {} args = default_args.merge args cli = Net::HTTP.new args[:host], args[:port] cli.use_ssl = args[:ssl] #Not enough percise timeout but will not block execution cli.read_timeout = cli.open_timeout = cli.ssl_timeout = args[:timeout] cli end |
.default_args ⇒ Object
17 18 19 20 21 |
# File 'lib/yandex_metric.rb', line 17 def self.default_args {:port => SSL_PORT, :ssl => true, :timeout => TIMEOUT} end |
.delete(args = {}) ⇒ Object
50 51 52 |
# File 'lib/yandex_metric.rb', line 50 def self.delete args = {} '{"error" : "not implemented yet"}' end |
.encode_params(prms) ⇒ Object
11 12 13 14 15 |
# File 'lib/yandex_metric.rb', line 11 def self.encode_params prms prms.inject ('') { |acc, (k, v)| acc + CGI::escape(k) + '=' + CGI::escape(v.to_s) + '&' } end |
.get(args = {}) ⇒ Object
37 38 39 40 |
# File 'lib/yandex_metric.rb', line 37 def self.get args = {} qpath = args[:path] + '?' + encode_params(args[:params]) result(client(args).get2 qpath, args[:headers]) end |
.post(args = {}) ⇒ Object
42 43 44 |
# File 'lib/yandex_metric.rb', line 42 def self.post args = {} result(client(args).post2 args[:path], encode_params(args[:params])) end |
.put(args = {}) ⇒ Object
46 47 48 |
# File 'lib/yandex_metric.rb', line 46 def self.put args = {} '{"error" : "not implemented yet"}' end |
.result(res) ⇒ Object
32 33 34 35 |
# File 'lib/yandex_metric.rb', line 32 def self.result res raise res.value unless res.instance_of? Net::HTTPOK res.body end |