class Dirble::Station
Constants
- REQUIRED_FIELDS
Attributes
bitrate[RW]
categories[RW]
country[RW]
description[RW]
id[RW]
name[RW]
song_history[R]
status[RW]
stream_url[RW]
url_id[RW]
website[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/dirble/station.rb, line 13 def initialize(options) self.id = options[:id] self.name = options[:name] self.website = options[:website] self.country = options[:country] self.bitrate = options[:bitrate] self.status = options[:status] self.song_history = Array(options[:songhistory]) end
Private Class Methods
all_required_fields?(keys)
click to toggle source
# File lib/dirble/station.rb, line 89 def all_required_fields?(keys) REQUIRED_FIELDS.all? { |required_field| keys.include?(required_field) } end
by_continent(name)
click to toggle source
# File lib/dirble/station.rb, line 54 def by_continent(name) call_api_with_results( request_type: :get, query: "continent/apikey/{{api_key}}/continent/#{name.parameterize}" ) end
by_country(code)
click to toggle source
# File lib/dirble/station.rb, line 61 def by_country(code) call_api_with_results( request_type: :get, query: "country/apikey/{{api_key}}/country/#{code}" ) end
by_country_name(country_name)
click to toggle source
# File lib/dirble/station.rb, line 68 def by_country_name(country_name) code = IsoCountryCodes.search_by_name(country_name).first.alpha2 by_country(code) end
count()
click to toggle source
# File lib/dirble/station.rb, line 73 def count response = Dirble.connection.exec_query( request_type: :get, query: 'amountStation/apikey/{{api_key}}' ).body JSON.parse(response)['amount'] end
create(params)
click to toggle source
# File lib/dirble/station.rb, line 31 def create(params) guard_creation_of_station(params) call_api_with_results( request_type: :post, query: 'station/apikey/{{api_key}}', form_fields: params ).first end
find(station_id)
click to toggle source
# File lib/dirble/station.rb, line 40 def find(station_id) call_api_with_results( request_type: :get, query: "station/apikey/{{api_key}}/id/#{station_id}" ).first end
guard_creation_of_station(params)
click to toggle source
# File lib/dirble/station.rb, line 83 def guard_creation_of_station(params) unless all_required_fields?(params.keys) raise ArgumentError, 'You forgot about one of this keys: name, website, directory' end end
search(keyword)
click to toggle source
# File lib/dirble/station.rb, line 47 def search(keyword) call_api_with_results( request_type: :get, query: "search/apikey/{{api_key}}/search/#{keyword.parameterize}" ) end
Private Instance Methods
song_history=(list_of_songs)
click to toggle source
# File lib/dirble/station.rb, line 25 def song_history=(list_of_songs) @song_history ||= Dirble::Song.factory(list_of_songs) end