Module: Catapult::CatapultMethods

Included in:
Campaign, Subscription
Defined in:
lib/catapult/catapult_methods.rb

Instance Method Summary collapse

Instance Method Details

#build_request(url, method = "GET") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/catapult/catapult_methods.rb', line 4

def build_request(url, method = "GET")
  uri = URI.parse(BaseUrl+ url)
  http = Net::HTTP.new(uri.host, uri.port)
  c_type = {'Content-Type' =>'application/xml'}

  request = case method
    when "GET"
      Net::HTTP::Get.new(uri.request_uri, c_type)
    when "POST"
      Net::HTTP::Post.new(uri.request_uri, c_type)
    when "DELETE"
      Net::HTTP::Delete.new(uri.request_uri, c_type)
    when "PUT"
      Net::HTTP::Put.new(uri.request_uri, c_type)
  end
  request.basic_auth(Catapult.username, Catapult.password)
  return http, request
end

#handle_response(response) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/catapult/catapult_methods.rb', line 23

def handle_response(response)
  if response.code.to_i == 200 && response.body.blank?
    return true
  else
    return Hash.from_xml(response.body)
  end
end