shoutcast-api-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +4 -1
- data/CHANGELOG.md +8 -1
- data/README.md +103 -8
- data/lib/shoutcast/api.rb +1 -0
- data/lib/shoutcast/api/client.rb +67 -8
- data/lib/shoutcast/api/url.rb +41 -0
- data/lib/shoutcast/api/version.rb +1 -1
- data/shoutcast-api-client.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5976988c6aa0bc0b1d82bc453876140b4a4fa398
|
4
|
+
data.tar.gz: bc73d51e243f914efed4651c89b98992df3c3f64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d7dfa5035e2e1403c5285a792d78825d4607d0d3a9b1bbcabff3134828c6f147987a920bdb934805a25946421235de5e4a55531d252e3e95a48df9b68d549f
|
7
|
+
data.tar.gz: 00436bb636759e7c64b1191ea170c9dae2220122a6c198b586952b932cf2c5103d7dfe03897fd7e2d399aebfaafceb91d99d52e240642009d4bc612b524a9a06
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Unreleased ([Changelog](https://github.com/
|
1
|
+
Unreleased ([Changelog](https://github.com/marcferna/shoutcast-api-client/compare/v0.0.2...master))
|
2
2
|
==========
|
3
3
|
## Features
|
4
4
|
|
@@ -6,6 +6,13 @@ Unreleased ([Changelog](https://github.com/colszowka/simplecov/compare/v0.0.1...
|
|
6
6
|
|
7
7
|
## Bugfixes
|
8
8
|
|
9
|
+
0.0.2 ([Changelog](https://github.com/marcferna/shoutcast-api-client/compare/v0.0.1...v0.0.2))
|
10
|
+
=================
|
11
|
+
## Features
|
12
|
+
|
13
|
+
* Added Search API interface.
|
14
|
+
* Added Searcy by genre API interface.
|
15
|
+
|
9
16
|
0.0.1 ([Changelog](https://github.com/marcferna/shoutcast-api-client/compare/25b8f34...v0.0.1))
|
10
17
|
=================
|
11
18
|
## Features
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# SHOUTcast API Client
|
2
|
-
[![Build Status](https://travis-ci.org/marcferna/shoutcast-api-client.svg?branch=master)](https://travis-ci.org/marcferna/shoutcast-api-client) [![Code Climate](https://codeclimate.com/github/marcferna/shoutcast-api-client/badges/gpa.svg)](https://codeclimate.com/github/marcferna/shoutcast-api-client) [![Test Coverage](https://codeclimate.com/github/marcferna/shoutcast-api-client/badges/coverage.svg)](https://codeclimate.com/github/marcferna/shoutcast-api-client/coverage) [![Dependency Status](https://gemnasium.com/badges/github.com/marcferna/shoutcast-api-client.svg)](https://gemnasium.com/github.com/marcferna/shoutcast-api-client)
|
2
|
+
[![Build Status](https://travis-ci.org/marcferna/shoutcast-api-client.svg?branch=master)](https://travis-ci.org/marcferna/shoutcast-api-client) [![Code Climate](https://codeclimate.com/github/marcferna/shoutcast-api-client/badges/gpa.svg)](https://codeclimate.com/github/marcferna/shoutcast-api-client) [![Test Coverage](https://codeclimate.com/github/marcferna/shoutcast-api-client/badges/coverage.svg)](https://codeclimate.com/github/marcferna/shoutcast-api-client/coverage) [![Dependency Status](https://gemnasium.com/badges/github.com/marcferna/shoutcast-api-client.svg)](https://gemnasium.com/github.com/marcferna/shoutcast-api-client) [![Gem Version](https://badge.fury.io/rb/shoutcast-api-client.svg)](https://badge.fury.io/rb/shoutcast-api-client)
|
3
3
|
|
4
4
|
:exclamation:**Important - You will need a SHOUTcast API key for this gem to work. You can request one from their [developer website](https://www.shoutcast.com/Developer)**
|
5
5
|
|
@@ -16,8 +16,8 @@ progress description you can check the [CHANGELOG.md](CHANGELOG.md)
|
|
16
16
|
### Stations
|
17
17
|
|
18
18
|
- [x] Top 500 (Passing parameters not implemented yet)
|
19
|
-
- [
|
20
|
-
- [
|
19
|
+
- [x] Keyword Search
|
20
|
+
- [x] Stations by Genre
|
21
21
|
- [ ] Stations by Now Playing Info
|
22
22
|
- [ ] Stations by Bitrate or Codec Type or Genre ID
|
23
23
|
- [ ] Random Stations
|
@@ -39,16 +39,111 @@ gem 'shoutcast-api-client'
|
|
39
39
|
```
|
40
40
|
|
41
41
|
And then execute:
|
42
|
+
```ruby
|
43
|
+
$ bundle
|
44
|
+
```
|
45
|
+
Or install it yourself as:
|
46
|
+
```
|
47
|
+
$ gem install shoutcast-api-client
|
48
|
+
```
|
49
|
+
## Usage
|
42
50
|
|
43
|
-
|
51
|
+
### Initialization
|
44
52
|
|
45
|
-
|
53
|
+
First need to initialize the client with your SHOUTcast API key
|
46
54
|
|
47
|
-
|
55
|
+
```ruby
|
56
|
+
client = Shoutcast::Api::Client.new(key: 'YOUR_API_KEY_GOES_HERE')
|
57
|
+
```
|
48
58
|
|
49
|
-
|
59
|
+
### Top 500
|
60
|
+
Get top 500 stations on SHOUTcast Radio directory.
|
61
|
+
```ruby
|
62
|
+
client.top_500
|
63
|
+
```
|
64
|
+
|
65
|
+
Returns an array of [Stations](lib/shoutcast/api/station.rb):
|
66
|
+
```ruby
|
67
|
+
[
|
68
|
+
<Shoutcast::Api::Station:0x007fb3c40361d0 @id="9907", @name=".977 The Hitz Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Pop Rock Top 40"], @ct="The Fray - You Found Me", @lc="4670", @logo=nil>,
|
69
|
+
<Shoutcast::Api::Station:0x007fb3c5840b68 @id="120149", @name="HOT FM - Lebih Hangat Daripada Biasa : HOT fm-[SHOUTcast.com]", @mt="audio/mpeg", @br="24", @genres=["Malaysia Malay"], @ct="LELAKI IDAMAN MELLY_GOESLOW ", @lc="3961", @logo=nil>,
|
70
|
+
<Shoutcast::Api::Station:0x007fb3c583bf50 @id="1264", @name="S K Y . F M - Absolutely Smooth Jazz - the world's smoothest jazz 24 hours a day-[SHOUTcast.com]", @mt="audio/mpeg", @br="96", @genres=["Soft Smooth Jazz"], @ct="Oli Silk - De-stress Signal", @lc="3507", @logo=nil>,
|
71
|
+
<Shoutcast::Api::Station:0x007fb3c583b6b8 @id="6687", @name="Groove Salad: a nicely chilled plate of ambient beats and grooves. [SomaFM]-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Ambient Chill"], @ct="Verbrilli Sound - Descender", @lc="2680", @logo=nil>,
|
72
|
+
<Shoutcast::Api::Station:0x007fb3c583ae70 @id="6803", @name=".977 The 80s Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["80s Pop Rock"], @ct="Starship - Nothing`s gonna stop us now (1987)", @lc="2192", @logo=nil>,
|
73
|
+
<Shoutcast::Api::Station:0x007fb3c583a588 @id="5516", @name="The Alex Jones Show-[SHOUTcast.com]", @mt="audio/mpeg", @br="32", @genres=["Talk"], @ct="Refeed: Hour 1 (Listen by phone 512-646-5000)", @lc="1987", @logo=nil>
|
74
|
+
]
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
### Station Search
|
79
|
+
Get stations which match the keyword searched on SHOUTcast Radio Directory.
|
80
|
+
```ruby
|
81
|
+
client.search(
|
82
|
+
keyword: 'SEARCH_KEYWORD',
|
83
|
+
limit: PAGE_COUNT_LIMIT,
|
84
|
+
offset: PAGE_OFFSET,
|
85
|
+
bitrate: STATION_BITRATE,
|
86
|
+
media_type: 'STATION_MEDIA_TYPE'
|
87
|
+
)
|
88
|
+
```
|
50
89
|
|
51
|
-
|
90
|
+
#### Parameters
|
91
|
+
`keyword`: The keyword to search stations for. Matches on Station Name, Now Playing info and Genre.
|
92
|
+
|
93
|
+
`limit`: The number of results to be returned by page.
|
94
|
+
|
95
|
+
`offset`: Specifies the number of the first station to return in the results.
|
96
|
+
|
97
|
+
`bitrate`: Station bitrate to search for. Ex: "128", "96".
|
98
|
+
|
99
|
+
`media_type`: The media type to search for. Ex: "audio/mpeg" or "audio/aacp"
|
100
|
+
|
101
|
+
Returns an array of [Stations](lib/shoutcast/api/station.rb):
|
102
|
+
```ruby
|
103
|
+
[
|
104
|
+
<Shoutcast::Api::Station:0x007fb3c40361d0 @id="9907", @name=".977 The Hitz Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Pop Rock Top 40"], @ct="The Fray - You Found Me", @lc="4670", @logo=nil>,
|
105
|
+
<Shoutcast::Api::Station:0x007fb3c5840b68 @id="120149", @name="HOT FM - Lebih Hangat Daripada Biasa : HOT fm-[SHOUTcast.com]", @mt="audio/mpeg", @br="24", @genres=["Malaysia Malay"], @ct="LELAKI IDAMAN MELLY_GOESLOW ", @lc="3961", @logo=nil>,
|
106
|
+
<Shoutcast::Api::Station:0x007fb3c583bf50 @id="1264", @name="S K Y . F M - Absolutely Smooth Jazz - the world's smoothest jazz 24 hours a day-[SHOUTcast.com]", @mt="audio/mpeg", @br="96", @genres=["Soft Smooth Jazz"], @ct="Oli Silk - De-stress Signal", @lc="3507", @logo=nil>,
|
107
|
+
<Shoutcast::Api::Station:0x007fb3c583b6b8 @id="6687", @name="Groove Salad: a nicely chilled plate of ambient beats and grooves. [SomaFM]-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Ambient Chill"], @ct="Verbrilli Sound - Descender", @lc="2680", @logo=nil>,
|
108
|
+
<Shoutcast::Api::Station:0x007fb3c583ae70 @id="6803", @name=".977 The 80s Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["80s Pop Rock"], @ct="Starship - Nothing`s gonna stop us now (1987)", @lc="2192", @logo=nil>,
|
109
|
+
<Shoutcast::Api::Station:0x007fb3c583a588 @id="5516", @name="The Alex Jones Show-[SHOUTcast.com]", @mt="audio/mpeg", @br="32", @genres=["Talk"], @ct="Refeed: Hour 1 (Listen by phone 512-646-5000)", @lc="1987", @logo=nil>
|
110
|
+
]
|
111
|
+
```
|
112
|
+
|
113
|
+
### Station Search By Genre
|
114
|
+
Get stations which match the genre specified as query.
|
115
|
+
```ruby
|
116
|
+
client.search(
|
117
|
+
genre: 'GENRE_TO_SEARCH',
|
118
|
+
limit: PAGE_COUNT_LIMIT,
|
119
|
+
offset: PAGE_OFFSET,
|
120
|
+
bitrate: STATION_BITRATE,
|
121
|
+
media_type: 'STATION_MEDIA_TYPE'
|
122
|
+
)
|
123
|
+
```
|
124
|
+
|
125
|
+
#### Parameters
|
126
|
+
`genre`: The genre to search stations for.
|
127
|
+
|
128
|
+
`limit`: The number of results to be returned by page.
|
129
|
+
|
130
|
+
`offset`: Specifies the number of the first station to return in the results.
|
131
|
+
|
132
|
+
`bitrate`: Station bitrate to search for. Ex: "128", "96".
|
133
|
+
|
134
|
+
`media_type`: The media type to search for. Ex: "audio/mpeg" or "audio/aacp"
|
135
|
+
|
136
|
+
Returns an array of [Stations](lib/shoutcast/api/station.rb):
|
137
|
+
```ruby
|
138
|
+
[
|
139
|
+
<Shoutcast::Api::Station:0x007fb3c40361d0 @id="9907", @name=".977 The Hitz Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Pop Rock Top 40"], @ct="The Fray - You Found Me", @lc="4670", @logo=nil>,
|
140
|
+
<Shoutcast::Api::Station:0x007fb3c5840b68 @id="120149", @name="HOT FM - Lebih Hangat Daripada Biasa : HOT fm-[SHOUTcast.com]", @mt="audio/mpeg", @br="24", @genres=["Malaysia Malay"], @ct="LELAKI IDAMAN MELLY_GOESLOW ", @lc="3961", @logo=nil>,
|
141
|
+
<Shoutcast::Api::Station:0x007fb3c583bf50 @id="1264", @name="S K Y . F M - Absolutely Smooth Jazz - the world's smoothest jazz 24 hours a day-[SHOUTcast.com]", @mt="audio/mpeg", @br="96", @genres=["Soft Smooth Jazz"], @ct="Oli Silk - De-stress Signal", @lc="3507", @logo=nil>,
|
142
|
+
<Shoutcast::Api::Station:0x007fb3c583b6b8 @id="6687", @name="Groove Salad: a nicely chilled plate of ambient beats and grooves. [SomaFM]-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["Ambient Chill"], @ct="Verbrilli Sound - Descender", @lc="2680", @logo=nil>,
|
143
|
+
<Shoutcast::Api::Station:0x007fb3c583ae70 @id="6803", @name=".977 The 80s Channel-[SHOUTcast.com]", @mt="audio/mpeg", @br="128", @genres=["80s Pop Rock"], @ct="Starship - Nothing`s gonna stop us now (1987)", @lc="2192", @logo=nil>,
|
144
|
+
<Shoutcast::Api::Station:0x007fb3c583a588 @id="5516", @name="The Alex Jones Show-[SHOUTcast.com]", @mt="audio/mpeg", @br="32", @genres=["Talk"], @ct="Refeed: Hour 1 (Listen by phone 512-646-5000)", @lc="1987", @logo=nil>
|
145
|
+
]
|
146
|
+
```
|
52
147
|
|
53
148
|
## Contributing
|
54
149
|
|
data/lib/shoutcast/api.rb
CHANGED
data/lib/shoutcast/api/client.rb
CHANGED
@@ -9,22 +9,81 @@ module Shoutcast
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def top_500
|
12
|
-
response = RestClient.get
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
response = RestClient.get(
|
13
|
+
url(path: '/legacy/Top500')
|
14
|
+
)
|
15
|
+
parse_stations(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def search(
|
19
|
+
keyword:,
|
20
|
+
limit: nil,
|
21
|
+
offset: nil,
|
22
|
+
bitrate: nil,
|
23
|
+
media_type: nil
|
24
|
+
)
|
25
|
+
response = RestClient.get(
|
26
|
+
url(
|
27
|
+
path: '/legacy/stationsearch',
|
28
|
+
parameters: {
|
29
|
+
search: keyword,
|
30
|
+
limit: build_limit_parameter(limit: limit, offset: offset),
|
31
|
+
br: bitrate,
|
32
|
+
mt: media_type
|
33
|
+
}
|
34
|
+
)
|
35
|
+
)
|
36
|
+
parse_stations(response)
|
37
|
+
end
|
38
|
+
|
39
|
+
def genre_search(
|
40
|
+
genre:,
|
41
|
+
limit: nil,
|
42
|
+
offset: nil,
|
43
|
+
bitrate: nil,
|
44
|
+
media_type: nil
|
45
|
+
)
|
46
|
+
response = RestClient.get(
|
47
|
+
url(
|
48
|
+
path: '/legacy/genresearch',
|
49
|
+
parameters: {
|
50
|
+
genre: genre,
|
51
|
+
limit: build_limit_parameter(limit: limit, offset: offset),
|
52
|
+
br: bitrate,
|
53
|
+
mt: media_type
|
54
|
+
}
|
55
|
+
)
|
56
|
+
)
|
57
|
+
parse_stations(response)
|
16
58
|
end
|
17
59
|
|
18
60
|
private
|
19
61
|
|
20
62
|
attr_accessor :key
|
21
63
|
|
22
|
-
def
|
23
|
-
|
64
|
+
def url(path:, parameters: {})
|
65
|
+
Shoutcast::Api::Url.new(
|
66
|
+
path: path,
|
67
|
+
key: key,
|
68
|
+
parameters: parameters
|
69
|
+
).to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_stations(response)
|
73
|
+
return [] if response.nil?
|
74
|
+
parsed_response = Nori.new.parse(response)
|
75
|
+
return [] if parsed_response['stationlist'].nil?
|
76
|
+
return [] if parsed_response['stationlist']['station'].nil?
|
77
|
+
Nori.new.parse(response)['stationlist']['station'].map do |attributes|
|
78
|
+
Shoutcast::Api::Station.parse(attributes)
|
79
|
+
end
|
24
80
|
end
|
25
81
|
|
26
|
-
def
|
27
|
-
|
82
|
+
def build_limit_parameter(limit: nil, offset: nil)
|
83
|
+
return nil if limit.nil?
|
84
|
+
parameter = limit.to_s
|
85
|
+
parameter += ",#{offset}" unless offset.nil?
|
86
|
+
parameter
|
28
87
|
end
|
29
88
|
end
|
30
89
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Shoutcast
|
2
|
+
module Api
|
3
|
+
class Url
|
4
|
+
def initialize(path:, key:, parameters: {})
|
5
|
+
@path = path
|
6
|
+
@parameters = { k: key }
|
7
|
+
@parameters.merge!(parameters) unless parameters.nil?
|
8
|
+
@parameters.delete_if { |_, value| value.nil? }
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
URI::HTTP.build(
|
13
|
+
host: base_uri.host,
|
14
|
+
path: base_uri.path,
|
15
|
+
query: parameters_query
|
16
|
+
).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
attr_accessor :path, :parameters
|
22
|
+
|
23
|
+
def scheme
|
24
|
+
'http'
|
25
|
+
end
|
26
|
+
|
27
|
+
def host
|
28
|
+
'api.shoutcast.com'
|
29
|
+
end
|
30
|
+
|
31
|
+
def base_uri
|
32
|
+
@base_uri ||= URI.join("#{scheme}://#{host}", path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def parameters_query
|
36
|
+
return '' if parameters.empty?
|
37
|
+
URI.encode_www_form(parameters)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
# 'allowed_push_host' to allow pushing to a single host or delete this section
|
19
19
|
# to allow pushing to any host.
|
20
20
|
if spec.respond_to?(:metadata)
|
21
|
-
spec.metadata['allowed_push_host'] =
|
21
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
22
22
|
else
|
23
23
|
raise 'RubyGems 2.0 or newer is required to protect against public gem '\
|
24
24
|
'pushes.'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoutcast-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/shoutcast/api.rb
|
173
173
|
- lib/shoutcast/api/client.rb
|
174
174
|
- lib/shoutcast/api/station.rb
|
175
|
+
- lib/shoutcast/api/url.rb
|
175
176
|
- lib/shoutcast/api/version.rb
|
176
177
|
- shoutcast-api-client.gemspec
|
177
178
|
homepage: https://github.com/marcferna/shoutcast-api-client
|