Class: HttpHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/HttpHelper.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, access_token) ⇒ HttpHelper

Returns a new instance of HttpHelper.



16
17
18
19
# File 'lib/HttpHelper.rb', line 16

def initialize(api_key, access_token)
  @api_key = api_key
  @access_token = access_token
end

Instance Method Details

#delete(endpoint_path, query_params, headers = nil) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/HttpHelper.rb', line 68

def delete(endpoint_path, query_params, headers = nil)

  uri = get_uri(endpoint_path)
  if !query_params.nil?
    uri.query = URI.encode_www_form query_params
  end  
  req = Net::HTTP::Delete.new uri.request_uri
  return send uri, req, @api_key, @access_token, headers

end

#get(endpoint_path, query_params, headers = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/HttpHelper.rb', line 25

def get(endpoint_path, query_params, headers = nil)
  
  uri = get_uri(endpoint_path)
  #puts uri    
  if !query_params.nil?
    uri.query = URI.encode_www_form query_params
  end
  #puts "REQUEST URI: #{uri.request_uri}" 
  req = Net::HTTP::Get.new uri.request_uri
  return send uri, req, @api_key, @access_token, headers

end

#get_uri(path) ⇒ Object



21
22
23
# File 'lib/HttpHelper.rb', line 21

def get_uri(path)
  return URI.parse "#{Api_Host::API_BASE_URL}#{path}"
end

#post(endpoint_path, query_params, body, headers = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/HttpHelper.rb', line 38

def post(endpoint_path, query_params, body, headers = nil)

  uri = get_uri(endpoint_path)
  if !query_params.nil?
    uri.query = URI.encode_www_form query_params
  end  
  req = Net::HTTP::Post.new uri.request_uri
  if !body.nil?
    req["Content-Type"] = "application/json"
    req.body = body.to_json
  end
  return send uri, req, @api_key, @access_token, headers

end

#put(endpoint_path, query_params, body, headers = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/HttpHelper.rb', line 53

def put(endpoint_path, query_params, body, headers = nil)

  uri = get_uri(endpoint_path)
  if !query_params.nil?
    uri.query = URI.encode_www_form query_params
  end  
  req = Net::HTTP::Put.new uri.request_uri
  if !body.nil?
    req["Content-Type"] = "application/json"
    req.body = body.to_json
  end
  return send uri, req, @api_key, @access_token, headers

end