Class: Https

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/http_client.rb

Instance Attribute Summary

Attributes included from Client

#protocol, #url_base

Instance Method Summary collapse

Constructor Details

#initialize(url_base) ⇒ Https

Returns a new instance of Https.



77
78
79
# File 'lib/http_client.rb', line 77

def initialize(url_base)
  @url_base = url_base
end

Instance Method Details

#delete(method, params = nil, body = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/http_client.rb', line 122

def delete(method,params=nil,body=nil)
  url = URI(@url_base+"/"+method)
  Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
    request = Net::HTTP::Delete.new(url)
    if params
      params.each do |key, value|
        request[key] = value
      end
    end
    request.body = body.to_json if body
    return http.request(request)
  end
end

#get(method, params = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/http_client.rb', line 81

def get(method,params=nil)
  url = URI(@url_base+"/"+method)
  Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
    request = Net::HTTP::Get.new(url)
    if params
      params.each do |key, value|
        request[key] = value
      end
    end
    return http.request(request)
  end
end

#post(method, params = nil, body = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/http_client.rb', line 94

def post(method,params=nil,body=nil)
  url = URI(@url_base+"/"+method)
  Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
    request = Net::HTTP::Post.new(url)
    if params
      params.each do |key, value|
        request[key] = value
      end
    end
    request.body = body.to_json if body
    return http.request(request)
  end
end

#put(method, params = nil, body = nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/http_client.rb', line 108

def put(method,params=nil,body=nil)
  url = URI(@url_base+"/"+method)
  Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
    request = Net::HTTP::Put.new(url)
    if params
      params.each do |key, value|
        request[key] = value
      end
    end
    request.body = body.to_json if body
    return http.request(request)
  end
end