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
# 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
  resp = Net::HTTP.start(uri.host, uri.port) { |http| 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.



19
20
21
# File 'lib/api_pi/request.rb', line 19

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