Class: Thm::DataServices::External

Inherits:
Object
  • Object
show all
Defined in:
lib/thm/dataservices/external.rb

Direct Known Subclasses

Safebrowsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExternal

Returns a new instance of External.



21
22
23
# File 'lib/thm/dataservices/external.rb', line 21

def initialize
  @debug = false
end

Instance Attribute Details

#debug=(value) ⇒ Object (writeonly)

Sets the attribute debug

Parameters:

  • value

    the value to set the attribute debug to.



19
20
21
# File 'lib/thm/dataservices/external.rb', line 19

def debug=(value)
  @debug = value
end

Instance Method Details

#apidelete(url) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/thm/dataservices/external.rb', line 56

def apidelete(url)
  uri = URI.parse("#{url}")
  http = Net::HTTP.new(uri.host, uri.port)
  begin
    response = http.request(Net::HTTP::Delete.new(uri.request_uri))
  rescue
    puts "Error posting data"
  end
end

#apiget(url) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/thm/dataservices/external.rb', line 25

def apiget(url)
  uri = URI.parse("#{url}")
  puts "Request URI: #{url}" unless @debug == false
  http = Net::HTTP.new(uri.host, uri.port)
  if url =~ %r=^https:=
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end      
  begin
    response = http.request(Net::HTTP::Get.new(uri.request_uri))
    puts response.body unless @debug == false
    return response 
  rescue
    puts "Error retrieving data"
  end
end

#apipost(url, body = "") ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/thm/dataservices/external.rb', line 42

def apipost(url, body="")
  uri = URI.parse("#{url}")
  puts "Request URI: #{url}" unless @debug == false
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_content_type("application/json")
  begin
    request.body = body unless body.empty?
    response = http.request(request)
  rescue
    puts "Error posting data"
  end
end