Module: Median::Aleph::Utils

Included in:
Median::Aleph
Defined in:
lib/median/aleph/utils.rb

Instance Method Summary collapse

Instance Method Details

#delete_url(url, data = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/median/aleph/utils.rb', line 35

def delete_url(url, data = {})
  begin
    uri       = get_uri(url)
    uri.query = URI.encode_www_form(data)
    http      = get_http_connection(uri)

    request = Net::HTTP::Delete.new(uri.request_uri)
    request.set_form_data(data)

    response = http.request(request)
    Nokogiri::XML(response.body)
  rescue Exception => e
    raise Median::ConnectionError.new(e)
  end
end

#get_url(url, data = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/median/aleph/utils.rb', line 4

def get_url(url, data = {})
  begin
    uri       = get_uri(url)
    uri.query = URI.encode_www_form(data)
    http      = get_http_connection(uri)

    request = Net::HTTP::Get.new(uri.request_uri)
    request.set_form_data(data)

    response = http.request(request)
    Nokogiri::XML(response.body)
  rescue Exception => e
    raise Median::ConnectionError.new(e)
  end
end

#post_url(url, data = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/median/aleph/utils.rb', line 20

def post_url(url, data = {})
  begin
    uri  = get_uri(url)
    http = get_http_connection(uri)

    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data(data)

    response = http.request(request)
    Nokogiri::XML(response.body)
  rescue Exception => e
    raise Median::ConnectionError.new(e)
  end
end

#put_url(url, data = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/median/aleph/utils.rb', line 51

def put_url(url, data = {})
  begin
    uri       = get_uri(url)
    uri.query = URI.encode_www_form(data)
    http      = get_http_connection(uri)

    request = Net::HTTP::Put.new(uri.request_uri)
    request.set_form_data(data)

    response = http.request(request)
    Nokogiri::XML(response.body)
  rescue Exception => e
    raise Median::ConnectionError.new(e)
  end
end