bbc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Oliver Nightingale
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # BBC
2
+
3
+ Simple ruby library for interacting with the BBC apis
4
+
5
+ This is incredibly alpha at the moment and should definitely not be used!
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'restclient'
4
+
5
+ require 'bbc/radio1'
6
+
7
+ require 'bbc/extensions/array'
8
+
9
+ module BBC
10
+ VERSION = '0.0.1'
11
+ API_HOST = 'http://www.bbc.co.uk'
12
+ end
@@ -0,0 +1,11 @@
1
+ class Array
2
+ def self.wrap(object)
3
+ if object.nil?
4
+ []
5
+ elsif object.respond_to?(:to_ary)
6
+ object.to_ary
7
+ else
8
+ [object]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'bbc/radio1/song'
2
+ require 'bbc/radio1/artist'
3
+ require 'bbc/radio1/release'
4
+ require 'bbc/radio1/link'
5
+ require 'bbc/radio1/review'
6
+
7
+ module Radio1
8
+ end
@@ -0,0 +1,40 @@
1
+ module BBC
2
+ module Radio1
3
+ class Artist
4
+
5
+ attr_reader :name, :id, :releases, :links, :reviews, :image_url, :related_artists
6
+
7
+ def self.find(id)
8
+ RestClient.get("http://www.bbc.co.uk/music/artists/#{id}.json") do |r|
9
+ response = JSON.parse(r)
10
+ new(response['artist'])
11
+ end
12
+ end
13
+
14
+ def initialize(params)
15
+ populate_from params
16
+ end
17
+
18
+ def get_details
19
+ unless @details_retreived
20
+ RestClient.get("http://www.bbc.co.uk/music/artists/#{id}.json") do |r|
21
+ response = JSON.parse(r)
22
+ populate_from response['artist']
23
+ @details_retreived = true
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def populate_from(params)
31
+ @name = params['name']
32
+ @id = params['gid']
33
+ @releases = Array.wrap(params['releases']).map { |release| BBC::Radio1::Release.new(release) }
34
+ @links = Array.wrap(params['links']).map { |link| BBC::Radio1::Link.new(link) }
35
+ @related_artists = Array.wrap(params['related_artists']).map { |artist| BBC::Radio1::Artist.new(artist['artist'])}
36
+ @image_url = params['image'] ? params['image']['src'] : nil
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ module BBC
2
+ module Radio1
3
+ class Link
4
+
5
+ attr_reader :name, :url, :type
6
+
7
+ def initialize(params)
8
+ @name = params['name']
9
+ @url = params['url']
10
+ @type = params['type']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module BBC
2
+ module Radio1
3
+ class Release
4
+
5
+ attr_reader :name, :year, :type, :status
6
+
7
+ def initialize(params)
8
+ @name = params['name']
9
+ @year = params['release_year']
10
+ @type = params['release_type']
11
+ @status = params['official']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module BBC
2
+ module Radio1
3
+ class Review
4
+ def initialize(params)
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module BBC
2
+ module Radio1
3
+ class Song
4
+
5
+ NOW_PLAYING_API = "http://www.bbc.co.uk/radio1/nowplaying/latest.json"
6
+
7
+ attr_reader :artist_gid, :artist, :title
8
+
9
+ def self.playing_now
10
+ RestClient.get(NOW_PLAYING_API) do |response|
11
+ new(JSON.parse(response)['nowplaying'].first)
12
+ end
13
+ end
14
+
15
+ def self.played_recently
16
+ RestClient.get(NOW_PLAYING_API) do |response|
17
+ JSON.parse(response)['nowplaying'].slice(1, 6).map { |song| new(song) }
18
+ end
19
+ end
20
+
21
+ def initialize(params)
22
+ @artist_gid = params['artist_gid']
23
+ @artist = params['artist']
24
+ @title = params['title']
25
+ end
26
+
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Oliver Nightingale
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-11 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: json
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: shoulda
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :development
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id004
68
+ description:
69
+ email:
70
+ - oliver.n@new-bamboo.co.uk
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - lib/bbc/extensions/array.rb
79
+ - lib/bbc/radio1/artist.rb
80
+ - lib/bbc/radio1/link.rb
81
+ - lib/bbc/radio1/release.rb
82
+ - lib/bbc/radio1/review.rb
83
+ - lib/bbc/radio1/song.rb
84
+ - lib/bbc/radio1.rb
85
+ - lib/bbc.rb
86
+ - LICENSE
87
+ - README.md
88
+ has_rdoc: true
89
+ homepage: http://github.com/olivernn/bbc
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 1
110
+ - 3
111
+ - 6
112
+ version: 1.3.6
113
+ requirements: []
114
+
115
+ rubyforge_project:
116
+ rubygems_version: 1.3.6
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Ruby Library to interact with the BBC APIs
120
+ test_files: []
121
+