Module: Kojn::Net
- Defined in:
- lib/kojn/net.rb,
lib/kojn/net_old.rb
Class Method Summary collapse
- .base_host ⇒ Object
- .delete(uri, options = {}) ⇒ Object
- .get(uri, options = {}) ⇒ Object
- .http ⇒ Object
- .patch(uri, options = {}) ⇒ Object
- .post(uri, options = {}) ⇒ Object
- .request(verb, path, options = {}) ⇒ Object
Class Method Details
.base_host ⇒ Object
3 4 5 |
# File 'lib/kojn/net.rb', line 3 def self.base_host return "http#{Kojn.ssl ? "s" : ""}://#{Kojn.host}:#{Kojn.port}" end |
.delete(uri, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/kojn/net.rb', line 38 def self.delete(path, ={}) request = self.request(:DELETE, path, ) return request end |
.get(uri, options = {}) ⇒ Object
20 21 22 23 24 |
# File 'lib/kojn/net.rb', line 20 def self.get(path, ={}) request = self.request(:GET, path, ) 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
32 33 34 35 36 |
# File 'lib/kojn/net.rb', line 32 def self.patch(path, ={}) request = self.request(:PATCH, path, ) return request end |
.post(uri, options = {}) ⇒ Object
26 27 28 29 30 |
# File 'lib/kojn/net.rb', line 26 def self.post(path, ={}) request = self.request(:POST, path, ) return request end |
.request(verb, path, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/kojn/net.rb', line 7 def self.request(verb, path, ={}) conn = Faraday.new(:url => self.base_host) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end conn.basic_auth(Kojn.api_key, '') response = conn.send(verb.to_s.downcase, path, ) return response end |