Class: Shin::Play::Apple

Inherits:
Object
  • Object
show all
Defined in:
lib/shin/play/apple.rb

Defined Under Namespace

Classes: HTTPError, MissingArgument, NotValid

Instance Method Summary collapse

Instance Method Details

#find(params = {}) ⇒ Object

Find

Raises:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shin/play/apple.rb', line 30

def find(params={})
  # Response
  response = Base.get('https://itunes.apple.com/lookup?' + URI.encode_www_form(params))
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Data
  data = Oj.load(response.body) rescue nil
  d2 = data['results'] rescue nil
  
  if d2 != nil
    d2.first.to_hashugar
  else
    raise NotValid, "Couldn't find any responses/results please check again."
  end
end

#newObject



7
8
9
# File 'lib/shin/play/apple.rb', line 7

def new
  self
end

#search(params = {}) ⇒ Object

Search

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/shin/play/apple.rb', line 12

def search(params={})
  # Response
  response = Base.get('https://itunes.apple.com/search?' + URI.encode_www_form(params))
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Data
  data = Oj.load(response.body) rescue nil
  d2 = data['results'] rescue nil
  
  if d2 != nil
    d2.to_hashugar
  else
    raise NotValid, "Couldn't find any responses/results please check again."
  end

end