Class: Zeebox::Client

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

Constant Summary collapse

EPG_URI =
"/epg/1/"

Class Method Summary collapse

Class Method Details

.get(url) ⇒ Object



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

def self.get(url)
  response = Curl.get(Zeebox.base_uri + EPG_URI + url) do |http|
    http.headers['zeebox-app-id'] = Zeebox.configuration.id
    http.headers['zeebox-app-key'] = Zeebox.configuration.key
    http.headers["Accept-Encoding"] = "gzip,deflate"
    http.follow_location = true
  end
  return "" if response.body_str.empty?
  gz = Zlib::GzipReader.new(StringIO.new(response.body_str))
  json = gz.read
  result = JSON.parse json
  if result.is_a? Array
    result.collect! { |x| x.is_a?(Hash) ? Hashie::Mash.new(x) : x }
  else
    result = Hashie::Mash.new(result)
  end
end