Module: Kojn::Net
- Defined in:
- lib/kojn/net.rb,
lib/kojn/net_old.rb
Class Method Summary collapse
- .curl(verb, path, options = {}) ⇒ Object
- .delete(uri, options = {}) ⇒ Object
- .get(uri, options = {}) ⇒ Object
- .http ⇒ Object
- .patch(uri, options = {}) ⇒ Object
- .post(uri, options = {}) ⇒ Object
- .to_uri(path) ⇒ Object
Class Method Details
.curl(verb, path, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kojn/net.rb', line 7 def self.curl(verb, path, ={}) verb = verb.upcase.to_sym c = Curl::Easy.new(self.to_uri(path)) c.http(verb) if verb != :GET c.post_body = .to_json end c.headers['Content-Type'] = 'application/json' c.http_auth_types = :basic c.username = Kojn.api_key return c end |
.delete(uri, options = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/kojn/net.rb', line 48 def self.delete(path, ={}) request = self.curl(:DELETE, path, ) request.perform return request end |
.get(uri, options = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/kojn/net.rb', line 24 def self.get(path, ={}) request = self.curl(:GET, path, ) request.perform return request end |
.http ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/kojn/net_old.rb', line 3 def self.http if defined?(Rails) && Rails.env == 'development' http = ::Net::HTTP.new('localhost', 3000) else http = ::Net::HTTP.new('kojn.nl', 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end return http end |
.patch(uri, options = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/kojn/net.rb', line 40 def self.patch(path, ={}) request = self.curl(:PATCH, path, ) request.perform return request end |
.post(uri, options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/kojn/net.rb', line 32 def self.post(path, ={}) request = self.curl(:POST, path, ) request.perform return request end |
.to_uri(path) ⇒ Object
3 4 5 |
# File 'lib/kojn/net.rb', line 3 def self.to_uri(path) return "http#{Kojn.ssl ? "s" : ""}://#{Kojn.host}:#{Kojn.port}#{path}" end |