Module: Kojn::Net

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

Class Method Summary collapse

Class Method Details

.curl(verb, path, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kojn/net.rb', line 7

def self.curl(verb, path, options={})
  verb = verb.upcase.to_sym

  c = Curl::Easy.new(self.to_uri(path))
  c.ssl_verify_host = false
  c.http(verb)

  if verb != :GET
    c.post_body = options.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



49
50
51
52
53
54
55
# File 'lib/kojn/net.rb', line 49

def self.delete(path, options={})
  request = self.curl(:DELETE, path, options)

  request.perform

  return request
end

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



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

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

  request.perform

  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



41
42
43
44
45
46
47
# File 'lib/kojn/net.rb', line 41

def self.patch(path, options={})
  request = self.curl(:PATCH, path, options)

  request.perform

  return request
end

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



33
34
35
36
37
38
39
# File 'lib/kojn/net.rb', line 33

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

  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