Module: Kojn::Net

Defined in:
lib/kojn/net.rb,
lib/kojn/net_old.rb

Class Method Summary collapse

Class Method Details

.base_hostObject



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, options={})
  request = self.request(:DELETE, path, options)

  return request
end

.get(uri, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/kojn/net.rb', line 20

def self.get(path, options={})
  request = self.request(:GET, path, options)

  return request
end

.httpObject



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, options={})
  request = self.request(:PATCH, path, options)

  return request
end

.post(uri, options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/kojn/net.rb', line 26

def self.post(path, options={})
  request = self.request(:POST, path, options)

  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, options={})
  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, options)

  return response
end