class GuitarParty::Client

Public Class Methods

new(api_key) click to toggle source
# File lib/guitarparty.rb, line 10
def initialize(api_key)
  @api_key = api_key
  @headers = {"Guitarparty-Api-Key" => @api_key}
end

Public Instance Methods

get_artist(artist_id) click to toggle source
# File lib/guitarparty.rb, line 23
def get_artist(artist_id)
  make_request("/artists/#{artist_id}/")
end
get_song(song_id) click to toggle source
# File lib/guitarparty.rb, line 15
def get_song(song_id)
  make_request("/songs/#{song_id}/")
end
get_song_chords(song_id) click to toggle source

def create_songbook(title, description, is_public = false)

data = Hash["title", title, "description", description, "is_public", is_public]
p data
songbook = make_request("/songbooks", "post", data)
songbook

end

# File lib/guitarparty.rb, line 45
def get_song_chords(song_id)
  song = JSON.parse((self.get_song(song_id).body))
  {"title" => song["title"], "artist" => song["authors"][0]["name"], "chords" => grab_chords(song)}
end
search_artists(query_string) click to toggle source
# File lib/guitarparty.rb, line 27
def search_artists(query_string)
  make_request("/artists/?query=#{URI::encode(query_string)}")
end
search_songs(query_string) click to toggle source
# File lib/guitarparty.rb, line 19
def search_songs(query_string)
  make_request("/songs/?query=#{URI::encode(query_string)}")
end

Private Instance Methods

grab_chords(song) click to toggle source
# File lib/guitarparty.rb, line 56
def grab_chords(song)
  chords = song["body"].scan(/\[\w{1}\]/)
  chords.each { |chord| chord.gsub!(/\[|\]/, "")}
end
make_request(uri) click to toggle source
# File lib/guitarparty.rb, line 52
def make_request(uri)
  self.class.get(uri, headers: @headers).parsed_response
end