/
people_search.rb
60 lines (55 loc) · 1.87 KB
/
people_search.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require_relative 'api'
require 'uri'
module Jammed #:nodoc:
# Provides methods for calling API endpoint /person.json?by=
class PeopleSearch < API
# Calls API for a search by username
#
# ==== Attributes
#
# * +name+ - Username to search by
# * +api_key+ - The key to use with the API call
#
# ==== Examples
#
# Jammed::PeopleSearch.search_name('IFTFOM', '08972935872035')
def self.search_name(name, api_key, https=false)
response = request(:get, "/search/person.json", {:https => https,
:query => {:by => 'name', :q => "#{name.split.join('+')}", :key => api_key}})
JSON.parse(response.body)['people']
end
# Calls API for a search by artist
#
# ==== Attributes
#
# * +artist+ - Artist to search by
# * +api_key+ - The key to use with the API call
#
# ==== Examples
#
# Jammed::PeopleSearch.search_artist('beach boys', '08972935872035')
def self.search_artist(artist, api_key, https=false)
response = request(:get, "/search/person.json", {:https => https,
:query => {:by => 'artist', :q => "#{artist.split.join('+')}", :key => api_key}})
JSON.parse(response.body)['people']
end
# Calls API for a search by track
#
# ==== Attributes
#
# * +artist+ - Artist to search by
# * +track+ - Track to search by
# * +api_key+ - The key to use with the API call
#
# ==== Examples
#
# Jammed::PeopleSearch.search_track('beach boys', 'good vibrations', '08972935872035')
def self.search_track(artist, track, api_key, https=false)
response = request(:get, "/search/person.json", {:https => https,
:query => {:by => 'track',
:q => "#{artist.split.join('+')}|#{track.split.join('+')}",
:key => api_key}})
JSON.parse(response.body)['people']
end
end
end