Module: Kernel

Defined in:
lib/api_pi/request.rb

Instance Method Summary collapse

Instance Method Details

#get(url, &block) ⇒ Object

Patch to add the ‘get` method. Create tests and assertions within.



8
9
10
11
12
13
14
15
16
17
# File 'lib/api_pi/request.rb', line 8

def get url, &block
  uri = URI.parse url
  get = Net::HTTP::Get.new(uri)
  req = Net::HTTPHeader.build_headers get
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = (uri.scheme == 'https')
  resp = http.request req
  json = net_parse resp
  ApiPi::Dsl.new(json).parse(url, block)
end

#set_header(key, value) ⇒ Object

Used to set headers for GET requests.



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

def set_header key, value
  ApiPi::HEADER.merge!( { key => value } )
end