swr3-nowplaying 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9783529068579b670131facc8f4f5eb4d79975a9
4
+ data.tar.gz: f15788d6e83983c2b80092c0ede6f3177ca4b47c
5
+ SHA512:
6
+ metadata.gz: f1c36be7f2e19235e23dcfb20e90d4c17cd43ffcb7fb02a66a521971a11894df8263625fdd0d870b33806856499035877c2bcb41722fa9036f33440d6c967b97
7
+ data.tar.gz: 08abfd03f50519d514ece4dfe89b2281939d54e79d84dbd6241836a92a41cf1bbc99485e64469b980cd24462dfc176510fe6b0f3e8838aa915ee2a4bd6f897ab
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,170 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Include:
4
+ - '**/Gemfile'
5
+ - '**/Guardfile'
6
+ - '**/*.gemspec'
7
+ - '**/Rakefile'
8
+ - 'exe/*'
9
+ Exclude:
10
+ - vendor/**/*
11
+ - db/migrations/**/*
12
+
13
+ DisplayCopNames:
14
+ Enabled: true
15
+
16
+ DisplayStyleGuide:
17
+ Enabled: true
18
+
19
+ Lint/AmbiguousRegexpLiteral:
20
+ Enabled: false
21
+
22
+ Lint/HandleExceptions:
23
+ Enabled: true
24
+
25
+ Lint/UnusedBlockArgument:
26
+ Enabled: false
27
+
28
+ Lint/UnusedMethodArgument:
29
+ Enabled: false
30
+
31
+ Metrics/AbcSize:
32
+ Enabled: false
33
+
34
+ Metrics/ClassLength:
35
+ Enabled: false
36
+
37
+ Metrics/CyclomaticComplexity:
38
+ Max: 12
39
+
40
+ Metrics/LineLength:
41
+ Max: 180
42
+
43
+ Metrics/MethodLength:
44
+ Max: 60
45
+
46
+ Metrics/ModuleLength:
47
+ Enabled: false
48
+
49
+ Metrics/ParameterLists:
50
+ Enabled: false
51
+
52
+ Metrics/PerceivedComplexity:
53
+ Enabled: false
54
+
55
+ Performance/Casecmp:
56
+ Enabled: false
57
+
58
+ Performance/Sample:
59
+ Enabled: false
60
+
61
+ Style/Alias:
62
+ EnforcedStyle: prefer_alias_method
63
+
64
+ Style/AlignParameters:
65
+ Enabled: false
66
+
67
+ Style/AsciiComments:
68
+ Enabled: false
69
+
70
+ Style/BlockDelimiters:
71
+ Enabled: false
72
+
73
+ Style/BracesAroundHashParameters:
74
+ Enabled: false
75
+
76
+ Style/ClassAndModuleChildren:
77
+ Enabled: false
78
+
79
+ Style/ClosingParenthesisIndentation:
80
+ Enabled: false
81
+
82
+ Style/Documentation:
83
+ Enabled: false
84
+
85
+ Style/DotPosition:
86
+ EnforcedStyle: trailing
87
+
88
+ Style/DoubleNegation:
89
+ Enabled: false
90
+
91
+ Style/EachWithObject:
92
+ Enabled: false
93
+
94
+ Style/FormatString:
95
+ EnforcedStyle: sprintf
96
+
97
+ Style/GuardClause:
98
+ Enabled: false
99
+
100
+ Style/IfUnlessModifier:
101
+ Enabled: false
102
+
103
+ Style/IndentArray:
104
+ EnforcedStyle: consistent
105
+
106
+ Style/IndentHash:
107
+ Enabled: false
108
+
109
+ Style/Lambda:
110
+ Enabled: false
111
+
112
+ Style/MultilineBlockChain:
113
+ Enabled: false
114
+
115
+ Style/MultilineBlockLayout:
116
+ Enabled: false
117
+
118
+ Style/MultilineOperationIndentation:
119
+ Enabled: false
120
+
121
+ Style/NegatedIf:
122
+ Enabled: false
123
+
124
+ Style/Next:
125
+ Enabled: false
126
+
127
+ Style/NumericLiterals:
128
+ Enabled: false
129
+
130
+ Style/PredicateName:
131
+ Enabled: false
132
+
133
+ Style/RaiseArgs:
134
+ EnforcedStyle: compact
135
+
136
+ Style/RedundantSelf:
137
+ Enabled: false
138
+
139
+ Style/RescueModifier:
140
+ Enabled: false
141
+
142
+ Style/SignalException:
143
+ Enabled: false
144
+
145
+ Style/SingleLineBlockParams:
146
+ Enabled: false
147
+
148
+ Style/SpaceAroundEqualsInParameterDefault:
149
+ EnforcedStyle: no_space
150
+
151
+ Style/StructInheritance:
152
+ Enabled: false
153
+
154
+ Style/TrailingCommaInArguments:
155
+ Enabled: false
156
+
157
+ Style/TrailingCommaInLiteral:
158
+ Enabled: false
159
+
160
+ Style/TrailingUnderscoreVariable:
161
+ Enabled: false
162
+
163
+ Style/TrivialAccessors:
164
+ Enabled: false
165
+
166
+ Style/WordArray:
167
+ Enabled: false
168
+
169
+ Style/ZeroLengthPredicate:
170
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.3
4
+ - 2.4.0
5
+ bundler_args: --without production
6
+ script: bundle exec rake test:ci
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in swr3-nowplaying.gemspec
5
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ guard 'bundler' do
3
+ watch('Gemfile')
4
+ watch(/^.*\.gemspec/)
5
+ end
6
+
7
+ guard 'minitest' do
8
+ watch(%r{^test/unit/test_(.*)\.rb})
9
+ watch(%r{^lib/*\.rb}) { 'test' }
10
+ watch(%r{^lib/.*/([^/]+)\.rb$}) { |m| "test/unit/test_#{m[1]}.rb" }
11
+ watch(%r{^test/helper\.rb}) { 'test' }
12
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nicholas E. Rabenau
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # `swr3-nowplaying` - Provides the track that is currently playing in SWR3
2
+
3
+ [![Build Status](https://travis-ci.org/nerab/swr3-nowplaying.svg?branch=master)](https://travis-ci.org/nerab/swr3-nowplaying)
4
+
5
+ The German radio station "SWR3" provides details about the currently playing song. This gem parses their JSON feed and provides the details as Ruby object.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ $ swr3-nowplaying
11
+ 2016-12-31 14:14:04 +0100 - Lost Frequencies: What is love 2016
12
+ ```
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'swr3_nowplaying'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install swr3-nowplaying
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rubocop/rake_task'
4
+ require 'rake/testtask'
5
+
6
+ namespace :test do
7
+ desc 'Run all specs'
8
+ task all: ['rubocop:auto_correct', :unit, :integration]
9
+
10
+ desc 'Run ci'
11
+ task ci: [:rubocop, :unit, :integration]
12
+
13
+ Rake::TestTask.new('unit') do |test|
14
+ test.libs << 'lib' << 'test' << 'test/unit'
15
+ test.pattern = 'test/unit/test_*.rb'
16
+ end
17
+
18
+ Rake::TestTask.new('integration') do |test|
19
+ test.libs << 'lib' << 'test'
20
+ test.pattern = 'test/integration/test_*.rb'
21
+ end
22
+ end
23
+
24
+ RuboCop::RakeTask.new
25
+
26
+ task default: 'test:all'
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'swr3_now_playing/loader'
8
+ require 'swr3_now_playing/mapper'
9
+
10
+ json = SWR3::NowPlaying::Loader.load
11
+
12
+ begin
13
+ song = SWR3::NowPlaying::Mapper.map(json)
14
+ puts "#{Time.new} - #{song}"
15
+ rescue JSON::ParserError => e
16
+ warn "Error parsing JSON response: #{e.message}"
17
+ warn 'Offending document is: '
18
+ warn json
19
+
20
+ exit 1
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'open-uri'
3
+
4
+ module SWR3
5
+ module NowPlaying
6
+ class Loader
7
+ class << self
8
+ def load(url='http://www.swr3.de/export/json/-/id=202234/gp1=1/wi3aps/index.json')
9
+ open(url)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+ require 'swr3_now_playing/song'
4
+
5
+ module SWR3
6
+ module NowPlaying
7
+ class MissingNullFixer
8
+ def fix(stream)
9
+ stream.gsub(/{ "detail": ,/, '{ "detail": {},')
10
+ end
11
+ end
12
+
13
+ class Mapper
14
+ class << self
15
+ def map(json)
16
+ fixers = [MissingNullFixer.new]
17
+ stream = json.read
18
+
19
+ begin
20
+ j = JSON.parse(stream)
21
+ rescue JSON::ParserError
22
+ if fixers.empty?
23
+ raise
24
+ else
25
+ stream = fixers.pop.fix(stream)
26
+ retry
27
+ end
28
+ end
29
+
30
+ artist = j['frontmod'].first['artist']['name']
31
+ title = j['frontmod'].first['title']
32
+
33
+ Song.new(artist, title)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module SWR3
3
+ module NowPlaying
4
+ class Song
5
+ attr_reader :artist, :title
6
+
7
+ def initialize(artist, title)
8
+ @artist = artist
9
+ @title = title
10
+ end
11
+
12
+ def ==(other)
13
+ return false if other.nil?
14
+ self.artist == other.artist && self.title == other.title
15
+ end
16
+
17
+ def to_s
18
+ "#{@artist}: #{@title}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module SWR3
3
+ module NowPlaying
4
+ VERSION = '0.0.2'
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SWR3
4
+ module NowPlaying
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'English'
6
+ require 'swr3_now_playing/version'
7
+
8
+ # rubocop:disable Metrics/BlockLength
9
+ Gem::Specification.new do |gem|
10
+ gem.name = 'swr3-nowplaying'
11
+ gem.version = SWR3::NowPlaying::VERSION
12
+ gem.authors = ['Nicholas E. Rabenau']
13
+ gem.email = ['nerab@gmx.net']
14
+ gem.description = 'The German radio station "SWR3" provides details about the currently playing song. This gem parses the feed and provides the details as Ruby object.'
15
+ gem.summary = 'Provides the track that is currently playing in SWR3'
16
+ gem.homepage = "http://github.com/nerab/#{gem.name}"
17
+
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ gem.bindir = 'exe'
20
+ gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.require_paths = ['lib']
23
+
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'minitest'
26
+ gem.add_development_dependency 'webmock'
27
+ gem.add_development_dependency 'vcr'
28
+ gem.add_development_dependency 'rubocop'
29
+ gem.add_development_dependency 'guard'
30
+ gem.add_development_dependency 'guard-minitest'
31
+ gem.add_development_dependency 'guard-bundler'
32
+ gem.add_development_dependency 'terminal-notifier'
33
+ gem.add_development_dependency 'terminal-notifier-guard'
34
+ gem.add_development_dependency 'rb-inotify'
35
+ gem.add_development_dependency 'libnotify'
36
+ gem.add_development_dependency 'rb-fsevent'
37
+ gem.add_development_dependency 'pry'
38
+ gem.add_development_dependency 'rb-readline'
39
+ gem.add_development_dependency 'pry-byebug'
40
+ end
@@ -0,0 +1,31 @@
1
+ { "detail": , "frontmod": [{ "title" : "Breathing underwater"
2
+ , "externalId" : "williams_title27448"
3
+ , "cover" : { "@id": "4244326",
4
+ "alt": "CD-Cover Sandé, Emeli - Breathing underwater",
5
+ "subline": "CD-Cover: Sandé, Emeli - Breathing underwater",
6
+ "copyright": "SWR3.de"
7
+ ,"detail": { "src": "http://www.swr3.de/-/id=4244326/property=detail/width=200/height=200/f69z8d/index.jpg",
8
+ "width": 200,
9
+ "height": 200}
10
+
11
+ ,"small": { "src": "http://www.swr3.de/-/id=4244326/property=small/width=100/height=100/122v5mf/index.jpg",
12
+ "width": 100,
13
+ "height": 100}
14
+
15
+ ,"thumbnail": { "src": "http://www.swr3.de/-/id=4244326/property=thumbnail/width=160/height=160/bv9ur/index.jpg",
16
+ "width": 160,
17
+ "height": 160}
18
+
19
+ ,"zoom": { "src": "http://www.swr3.de/-/id=4244326/property=zoom/width=500/height=500/1ugkxk9/index.jpg",
20
+ "width": 500,
21
+ "height": 500}
22
+
23
+
24
+ }
25
+ , "artist" : { "name" : "Sandé, Emeli"
26
+ , "link" : "http://www.swr3.de/musik/poplexikon/-/id=927882/did=1199388/cf24yn/index.html"
27
+ , "externalId" : "williams_artist8149"
28
+ },
29
+ "playDate" : 1483110825000
30
+ }
31
+ ]}
@@ -0,0 +1,38 @@
1
+ { "detail": {
2
+ "@id": "202234",
3
+ "leadText": null,
4
+ "text": null,
5
+ "topline": "SWR3 Musikrecherche",
6
+ "title": "Die letzten 13 Titel auf SWR3",
7
+ "detailImages": [
8
+ ]}, "frontmod": [{ "title" : "Breathing underwater"
9
+ , "externalId" : "williams_title27448"
10
+ , "cover" : { "@id": "4244326",
11
+ "alt": "CD-Cover Sandé, Emeli - Breathing underwater",
12
+ "subline": "CD-Cover: Sandé, Emeli - Breathing underwater",
13
+ "copyright": "SWR3.de"
14
+ ,"detail": { "src": "http://www.swr3.de/-/id=4244326/property=detail/width=200/height=200/f69z8d/index.jpg",
15
+ "width": 200,
16
+ "height": 200}
17
+
18
+ ,"small": { "src": "http://www.swr3.de/-/id=4244326/property=small/width=100/height=100/122v5mf/index.jpg",
19
+ "width": 100,
20
+ "height": 100}
21
+
22
+ ,"thumbnail": { "src": "http://www.swr3.de/-/id=4244326/property=thumbnail/width=160/height=160/bv9ur/index.jpg",
23
+ "width": 160,
24
+ "height": 160}
25
+
26
+ ,"zoom": { "src": "http://www.swr3.de/-/id=4244326/property=zoom/width=500/height=500/1ugkxk9/index.jpg",
27
+ "width": 500,
28
+ "height": 500}
29
+
30
+
31
+ }
32
+ , "artist" : { "name" : "Sandé, Emeli"
33
+ , "link" : "http://www.swr3.de/musik/poplexikon/-/id=927882/did=1199388/cf24yn/index.html"
34
+ , "externalId" : "williams_artist8149"
35
+ },
36
+ "playDate" : 1483110825000
37
+ }
38
+ ]}
@@ -0,0 +1,4 @@
1
+ { "detail": {}, "frontmod": [{ "title" : "Breathing underwater"
2
+ , "externalId" : "williams_title27448"
3
+ , "cover" : { "@id": "4244326",
4
+ THE INTERNET BROKE DOWN, ALL HOPE IS LOST.
@@ -0,0 +1,223 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.swr3.de/export/json/-/id=202234/gp1=1/wi3aps/index.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - Ruby
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - Apache-Coyote/1.1
21
+ Content-Type:
22
+ - application/json;charset=utf-8
23
+ Cache-Control:
24
+ - max-age=13
25
+ Expires:
26
+ - Sat, 02 Feb 2013 19:16:15 GMT
27
+ Date:
28
+ - Sat, 02 Feb 2013 19:16:02 GMT
29
+ Content-Length:
30
+ - '1584'
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: US-ASCII
35
+ string: "{ \"detail\": {\n \"@id\": \"202234\",\n \"leadText\": null,\n \"text\":
36
+ null,\n \"topline\": \"SWR3 Musikrecherche\",\n \"title\": \"Die letzten
37
+ 13 Titel auf SWR3\",\n \"detailImages\": [\n ]}, \"frontmod\": [{ \"title\"
38
+ : \"Red flag\"\n , \"externalId\" : \"williams_title13552\"\n ,
39
+ \"cover\" : { \"@id\": \"211180\",\n \"alt\": \"CD-Cover Billy Talent -
40
+ Red flag\",\n \"subline\": \"CD-Cover: Billy Talent - Red flag\",\n \"copyright\":
41
+ \"SWR3.de\"\n ,\"detail\": { \"src\": \"http://www.swr3.de/-/id=211180/property=detail/width=200/height=174/pubVersion=15/18p3xn3/index.jpg\",\n
42
+ \ \"width\": 200,\n \"height\": 174}\n
43
+ \ \n ,\"small\": { \"src\": \"http://www.swr3.de/-/id=211180/property=small/width=100/height=87/pubVersion=15/1mxtehu/index.jpg\",\n
44
+ \ \"width\": 100,\n \"height\": 87}\n \n
45
+ \ ,\"thumbnail\": { \"src\": \"http://www.swr3.de/-/id=211180/property=thumbnail/width=160/height=139/pubVersion=15/1p6camf/index.jpg\",\n
46
+ \ \"width\": 160,\n \"height\": 139}\n
47
+ \ \n ,\"zoom\": { \"src\": \"http://www.swr3.de/-/id=211180/property=zoom/width=500/height=435/pubVersion=15/n4isxq/index.jpg\",\n
48
+ \ \"width\": 500,\n \"height\": 435}\n
49
+ \ \n \n}\n , \"artist\" : { \"name\" : \"Billy Talent\"\n
50
+ \ , \"link\" : \"http://www.swr3.de/musik/poplexikon/Billy-Talent/-/id=927882/did=203054/14tqyuw/index.html\"\n
51
+ \ , \"externalId\" : \"williams_artist5897\" \n
52
+ \ },\n \"playDate\" : 1359832123000\n }\n ]}"
53
+ http_version:
54
+ recorded_at: Sat, 02 Feb 2013 19:16:10 GMT
55
+ - request:
56
+ method: get
57
+ uri: http://www.swr3.de/export/json/-/id=202234/gp1=1/wi3aps/index.json
58
+ body:
59
+ encoding: US-ASCII
60
+ string: ''
61
+ headers:
62
+ Accept-Encoding:
63
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
64
+ Accept:
65
+ - "*/*"
66
+ User-Agent:
67
+ - Ruby
68
+ response:
69
+ status:
70
+ code: 200
71
+ message: OK
72
+ headers:
73
+ Content-Type:
74
+ - application/json;charset=utf-8
75
+ Vary:
76
+ - Accept-Encoding
77
+ Expires:
78
+ - Fri, 30 Dec 2016 14:42:06 GMT
79
+ Cache-Control:
80
+ - max-age=0, no-cache, no-store
81
+ Pragma:
82
+ - no-cache
83
+ Date:
84
+ - Fri, 30 Dec 2016 14:42:06 GMT
85
+ Content-Length:
86
+ - '1519'
87
+ Connection:
88
+ - keep-alive
89
+ body:
90
+ encoding: UTF-8
91
+ string: "{ \"detail\": {\n \"@id\": \"202234\",\n \"leadText\": null,\n \"text\":
92
+ null,\n \"topline\": \"SWR3 Musikrecherche\",\n \"title\": \"Die letzten
93
+ 13 Titel auf SWR3\",\n \"detailImages\": [\n ]}, \"frontmod\": [{ \"title\"
94
+ : \"My way\"\n , \"externalId\" : \"williams_title27120\"\n ,
95
+ \"cover\" : { \"@id\": \"4153020\",\n \"alt\": \"CD-Cover Harris, Calvin
96
+ - My way\",\n \"subline\": \"CD-Cover: Harris, Calvin - My way\",\n \"copyright\":
97
+ \"SWR3.de\"\n ,\"detail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=detail/width=200/height=200/794y3g/index.jpg\",\n
98
+ \ \"width\": 200,\n \"height\": 200}\n
99
+ \ \n ,\"small\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=small/width=100/height=100/1iid4ll/index.jpg\",\n
100
+ \ \"width\": 100,\n \"height\": 100}\n
101
+ \ \n ,\"thumbnail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=thumbnail/width=160/height=160/953k3g/index.jpg\",\n
102
+ \ \"width\": 160,\n \"height\": 160}\n
103
+ \ \n ,\"zoom\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=zoom/width=500/height=500/5y0d55/index.jpg\",\n
104
+ \ \"width\": 500,\n \"height\": 500}\n
105
+ \ \n \n}\n , \"artist\" : { \"name\" : \"Harris, Calvin\"\n
106
+ \ , \"link\" : \"http://www.swr3.de/musik/poplexikon/-/id=927882/did=342722/1ejk03z/index.html\"\n
107
+ \ , \"externalId\" : \"williams_artist6503\" \n
108
+ \ },\n \"playDate\" : 1483108845000\n }\n ]}"
109
+ http_version:
110
+ recorded_at: Fri, 30 Dec 2016 14:42:06 GMT
111
+ - request:
112
+ method: get
113
+ uri: http://www.swr3.de/export/json/-/id=202234/gp1=1/wi3aps/index.json
114
+ body:
115
+ encoding: US-ASCII
116
+ string: ''
117
+ headers:
118
+ Accept-Encoding:
119
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
120
+ Accept:
121
+ - "*/*"
122
+ User-Agent:
123
+ - Ruby
124
+ response:
125
+ status:
126
+ code: 200
127
+ message: OK
128
+ headers:
129
+ Content-Type:
130
+ - application/json;charset=utf-8
131
+ Vary:
132
+ - Accept-Encoding
133
+ Expires:
134
+ - Fri, 30 Dec 2016 14:42:08 GMT
135
+ Cache-Control:
136
+ - max-age=0, no-cache, no-store
137
+ Pragma:
138
+ - no-cache
139
+ Date:
140
+ - Fri, 30 Dec 2016 14:42:08 GMT
141
+ Content-Length:
142
+ - '1519'
143
+ Connection:
144
+ - keep-alive
145
+ body:
146
+ encoding: UTF-8
147
+ string: "{ \"detail\": {\n \"@id\": \"202234\",\n \"leadText\": null,\n \"text\":
148
+ null,\n \"topline\": \"SWR3 Musikrecherche\",\n \"title\": \"Die letzten
149
+ 13 Titel auf SWR3\",\n \"detailImages\": [\n ]}, \"frontmod\": [{ \"title\"
150
+ : \"My way\"\n , \"externalId\" : \"williams_title27120\"\n ,
151
+ \"cover\" : { \"@id\": \"4153020\",\n \"alt\": \"CD-Cover Harris, Calvin
152
+ - My way\",\n \"subline\": \"CD-Cover: Harris, Calvin - My way\",\n \"copyright\":
153
+ \"SWR3.de\"\n ,\"detail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=detail/width=200/height=200/794y3g/index.jpg\",\n
154
+ \ \"width\": 200,\n \"height\": 200}\n
155
+ \ \n ,\"small\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=small/width=100/height=100/1iid4ll/index.jpg\",\n
156
+ \ \"width\": 100,\n \"height\": 100}\n
157
+ \ \n ,\"thumbnail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=thumbnail/width=160/height=160/953k3g/index.jpg\",\n
158
+ \ \"width\": 160,\n \"height\": 160}\n
159
+ \ \n ,\"zoom\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=zoom/width=500/height=500/5y0d55/index.jpg\",\n
160
+ \ \"width\": 500,\n \"height\": 500}\n
161
+ \ \n \n}\n , \"artist\" : { \"name\" : \"Harris, Calvin\"\n
162
+ \ , \"link\" : \"http://www.swr3.de/musik/poplexikon/-/id=927882/did=342722/1ejk03z/index.html\"\n
163
+ \ , \"externalId\" : \"williams_artist6503\" \n
164
+ \ },\n \"playDate\" : 1483108845000\n }\n ]}"
165
+ http_version:
166
+ recorded_at: Fri, 30 Dec 2016 14:42:08 GMT
167
+ - request:
168
+ method: get
169
+ uri: http://www.swr3.de/export/json/-/id=202234/gp1=1/wi3aps/index.json
170
+ body:
171
+ encoding: US-ASCII
172
+ string: ''
173
+ headers:
174
+ Accept-Encoding:
175
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
176
+ Accept:
177
+ - "*/*"
178
+ User-Agent:
179
+ - Ruby
180
+ response:
181
+ status:
182
+ code: 200
183
+ message: OK
184
+ headers:
185
+ Content-Type:
186
+ - application/json;charset=utf-8
187
+ Vary:
188
+ - Accept-Encoding
189
+ Expires:
190
+ - Fri, 30 Dec 2016 14:42:12 GMT
191
+ Cache-Control:
192
+ - max-age=0, no-cache, no-store
193
+ Pragma:
194
+ - no-cache
195
+ Date:
196
+ - Fri, 30 Dec 2016 14:42:12 GMT
197
+ Content-Length:
198
+ - '1519'
199
+ Connection:
200
+ - keep-alive
201
+ body:
202
+ encoding: UTF-8
203
+ string: "{ \"detail\": {\n \"@id\": \"202234\",\n \"leadText\": null,\n \"text\":
204
+ null,\n \"topline\": \"SWR3 Musikrecherche\",\n \"title\": \"Die letzten
205
+ 13 Titel auf SWR3\",\n \"detailImages\": [\n ]}, \"frontmod\": [{ \"title\"
206
+ : \"My way\"\n , \"externalId\" : \"williams_title27120\"\n ,
207
+ \"cover\" : { \"@id\": \"4153020\",\n \"alt\": \"CD-Cover Harris, Calvin
208
+ - My way\",\n \"subline\": \"CD-Cover: Harris, Calvin - My way\",\n \"copyright\":
209
+ \"SWR3.de\"\n ,\"detail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=detail/width=200/height=200/794y3g/index.jpg\",\n
210
+ \ \"width\": 200,\n \"height\": 200}\n
211
+ \ \n ,\"small\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=small/width=100/height=100/1iid4ll/index.jpg\",\n
212
+ \ \"width\": 100,\n \"height\": 100}\n
213
+ \ \n ,\"thumbnail\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=thumbnail/width=160/height=160/953k3g/index.jpg\",\n
214
+ \ \"width\": 160,\n \"height\": 160}\n
215
+ \ \n ,\"zoom\": { \"src\": \"http://www.swr3.de/-/id=4153020/property=zoom/width=500/height=500/5y0d55/index.jpg\",\n
216
+ \ \"width\": 500,\n \"height\": 500}\n
217
+ \ \n \n}\n , \"artist\" : { \"name\" : \"Harris, Calvin\"\n
218
+ \ , \"link\" : \"http://www.swr3.de/musik/poplexikon/-/id=927882/did=342722/1ejk03z/index.html\"\n
219
+ \ , \"externalId\" : \"williams_artist6503\" \n
220
+ \ },\n \"playDate\" : 1483108845000\n }\n ]}"
221
+ http_version:
222
+ recorded_at: Fri, 30 Dec 2016 14:42:12 GMT
223
+ recorded_with: VCR 3.0.3
data/test/helper.rb ADDED
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require 'minitest/autorun'
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # frozen_string_literal: true
3
+ require 'helper'
4
+
5
+ require 'vcr'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'test/fixtures/vcr'
9
+ c.hook_into :webmock
10
+ end
11
+
12
+ def mocked(cassette, &block)
13
+ VCR.use_cassette("#{self.class.name}_#{cassette}", record: :new_episodes) { yield }
14
+ end
15
+
16
+ require 'swr3_now_playing/mapper'
17
+ require 'swr3_now_playing/loader'
18
+
19
+ class IntegrationTest < MiniTest::Test
20
+ include SWR3::NowPlaying
21
+
22
+ def setup
23
+ @song = mocked('setup') do
24
+ Mapper.map(Loader.load)
25
+ end
26
+ end
27
+
28
+ def test_song
29
+ refute_nil(@song)
30
+ assert_equal('Billy Talent', @song.artist)
31
+ assert_equal('Red flag', @song.title)
32
+ assert_equal('Billy Talent: Red flag', @song.to_s)
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'helper'
3
+
4
+ require 'swr3_now_playing/loader'
5
+
6
+ class LoaderTest < MiniTest::Test
7
+ def test_good
8
+ stream = SWR3::NowPlaying::Loader.load('test/fixtures/good.json')
9
+ refute_nil(stream)
10
+ refute_empty(stream.read)
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'helper'
3
+
4
+ require 'swr3_now_playing/mapper'
5
+
6
+ class MapperTest < MiniTest::Test
7
+ def test_good
8
+ result = SWR3::NowPlaying::Mapper.map(File.new('test/fixtures/good.json'))
9
+ refute_nil(result)
10
+ end
11
+
12
+ def test_fixable
13
+ result = SWR3::NowPlaying::Mapper.map(File.new('test/fixtures/fixable.json'))
14
+ refute_nil(result)
15
+ end
16
+
17
+ def test_unfixable
18
+ assert_raises(JSON::ParserError) {
19
+ SWR3::NowPlaying::Mapper.map(File.new('test/fixtures/unfixable.json'))
20
+ }
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,301 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swr3-nowplaying
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas E. Rabenau
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: terminal-notifier
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: terminal-notifier-guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rb-inotify
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: libnotify
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rb-fsevent
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: rb-readline
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pry-byebug
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ description: The German radio station "SWR3" provides details about the currently
238
+ playing song. This gem parses the feed and provides the details as Ruby object.
239
+ email:
240
+ - nerab@gmx.net
241
+ executables:
242
+ - swr3-nowplaying
243
+ extensions: []
244
+ extra_rdoc_files: []
245
+ files:
246
+ - ".gitignore"
247
+ - ".rubocop.yml"
248
+ - ".travis.yml"
249
+ - Gemfile
250
+ - Guardfile
251
+ - LICENSE.txt
252
+ - README.md
253
+ - Rakefile
254
+ - exe/swr3-nowplaying
255
+ - lib/swr3_now_playing.rb
256
+ - lib/swr3_now_playing/loader.rb
257
+ - lib/swr3_now_playing/mapper.rb
258
+ - lib/swr3_now_playing/song.rb
259
+ - lib/swr3_now_playing/version.rb
260
+ - swr3-nowplaying.gemspec
261
+ - test/fixtures/fixable.json
262
+ - test/fixtures/good.json
263
+ - test/fixtures/unfixable.json
264
+ - test/fixtures/vcr/IntegrationTest_setup.yml
265
+ - test/helper.rb
266
+ - test/integration/test_all.rb
267
+ - test/unit/test_loader.rb
268
+ - test/unit/test_mapper.rb
269
+ homepage: http://github.com/nerab/swr3-nowplaying
270
+ licenses: []
271
+ metadata: {}
272
+ post_install_message:
273
+ rdoc_options: []
274
+ require_paths:
275
+ - lib
276
+ required_ruby_version: !ruby/object:Gem::Requirement
277
+ requirements:
278
+ - - ">="
279
+ - !ruby/object:Gem::Version
280
+ version: '0'
281
+ required_rubygems_version: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - ">="
284
+ - !ruby/object:Gem::Version
285
+ version: '0'
286
+ requirements: []
287
+ rubyforge_project:
288
+ rubygems_version: 2.5.1
289
+ signing_key:
290
+ specification_version: 4
291
+ summary: Provides the track that is currently playing in SWR3
292
+ test_files:
293
+ - test/fixtures/fixable.json
294
+ - test/fixtures/good.json
295
+ - test/fixtures/unfixable.json
296
+ - test/fixtures/vcr/IntegrationTest_setup.yml
297
+ - test/helper.rb
298
+ - test/integration/test_all.rb
299
+ - test/unit/test_loader.rb
300
+ - test/unit/test_mapper.rb
301
+ has_rdoc: