Class: Zvent::Base

Inherits:
Object show all
Defined in:
lib/zvent/base.rb

Direct Known Subclasses

Category, Event, Performer, Session, Venue

Instance Method Summary collapse

Instance Method Details

#get_resources(url) ⇒ Object

Get Json and parse it



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/zvent/base.rb', line 23

def get_resources(url)
  url = URI.parse(url)
  
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.get(url.request_uri+"&format=json&key=#{@api_key}")
  }
  resources = JSON.parse(res.body)
  
  if resources['rsp']['status'] == 'error' 
    raise Zvent::ZventApiError.new(resources['rsp']['msg'])
  elsif resources['rsp']['status'] == 'failed'
    raise Zvent::ZventApiFailure.new(resources['rsp']['msg'])
  end
  
  return resources      
end