Class: Dirble::Station

Inherits:
Object
  • Object
show all
Extended by:
SimpleApiModel
Defined in:
lib/dirble/station.rb

Constant Summary collapse

REQUIRED_FIELDS =
[:name, :website, :directory]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SimpleApiModel

build_from_api_response, call_api_with_results, parsed_collection

Constructor Details

#initialize(options) ⇒ Station

Returns a new instance of Station.



13
14
15
16
17
18
19
20
21
# 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

Instance Attribute Details

#bitrateObject

Returns the value of attribute bitrate.



9
10
11
# File 'lib/dirble/station.rb', line 9

def bitrate
  @bitrate
end

#categoriesObject

Returns the value of attribute categories.



9
10
11
# File 'lib/dirble/station.rb', line 9

def categories
  @categories
end

#countryObject

Returns the value of attribute country.



9
10
11
# File 'lib/dirble/station.rb', line 9

def country
  @country
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/dirble/station.rb', line 9

def description
  @description
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/dirble/station.rb', line 9

def id
  @id
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/dirble/station.rb', line 9

def name
  @name
end

#song_historyObject

Returns the value of attribute song_history.



11
12
13
# File 'lib/dirble/station.rb', line 11

def song_history
  @song_history
end

#statusObject

Returns the value of attribute status.



9
10
11
# File 'lib/dirble/station.rb', line 9

def status
  @status
end

#stream_urlObject

Returns the value of attribute stream_url.



9
10
11
# File 'lib/dirble/station.rb', line 9

def stream_url
  @stream_url
end

#url_idObject

Returns the value of attribute url_id.



9
10
11
# File 'lib/dirble/station.rb', line 9

def url_id
  @url_id
end

#websiteObject

Returns the value of attribute website.



9
10
11
# File 'lib/dirble/station.rb', line 9

def website
  @website
end

Class Method Details

.by_continent(name) ⇒ Object



54
55
56
57
58
59
# 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) ⇒ Object



61
62
63
64
65
66
# 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) ⇒ Object



68
69
70
71
# 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

.countObject



73
74
75
76
77
78
79
# 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) ⇒ Object



31
32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
44
45
# 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

.search(keyword) ⇒ Object



47
48
49
50
51
52
# 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