billboard_api 0.1.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/billboard_api.rb +75 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9b1093d880e57bbf546ef10d533baeb89b1de15179bb5f1139a8e204e3a2e567
4
+ data.tar.gz: df4109750191432ae5d5a9778924bebed5c64bf2f2818a3335b022d4750bfcd6
5
+ SHA512:
6
+ metadata.gz: c1b7580d2d1be293960ded9f3569969195f7d9a32606cd8a13cb74da63cdbcf2f849817269af6506860e35952ca57a11aac0b957947df4e9c785dfa3c8c9b0f4
7
+ data.tar.gz: 2e9b8ee032234d3f2d4de354d327be4077eb0fdfa8bde2f1b20b6f8d3d36df2c039ef69299f7d4102813f5931a74899d142226b3df951f686dcd4248b9db53ae
@@ -0,0 +1,75 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ ARTIST_100_URL = "https://www.billboard.com/charts/artist-100"
5
+ HOT_100_URL = "https://www.billboard.com/charts/hot-100"
6
+ BILLBOARD_200_URL = "https://www.billboard.com/charts/billboard-200"
7
+
8
+ class BillboardAPI
9
+ def self.artist_100
10
+ document = Nokogiri::HTML.parse(open(ARTIST_100_URL))
11
+ artists = document.css(".chart-list-item")
12
+ artists.map do |artist|
13
+ new_artist = create_artist_object(
14
+ artist.attribute("data-title").value,
15
+ if artist.css(".chart-list-item__image-wrapper").css("img").length > 1
16
+ if artist.css(".chart-list-item__image-wrapper").css("img")[1].attributes.has_key?("data-src")
17
+ artist.css(".chart-list-item__image-wrapper").css("img")[1].attribute("data-src").value
18
+ else
19
+ artist.css(".chart-list-item__image-wrapper").css("img")[1].attribute("src").value
20
+ end
21
+ else
22
+ artist.css(".chart-list-item__image-wrapper").css("img").attribute("data-src").value
23
+ end
24
+ )
25
+
26
+ end
27
+ end
28
+
29
+ def self.hot_100
30
+ document = Nokogiri::HTML.parse(open(HOT_100_URL))
31
+ songs = document.css(".chart-list__element")
32
+ songs.map do |song|
33
+ new_song = create_song_object(
34
+ song.css(".chart-element__information__song").text,
35
+ song.css(".chart-element__information__artist").text,
36
+ if song.css(".chart-element__image").attribute("style").value == "" #Empty style attribute catch
37
+ ""
38
+ else
39
+ song.css(".chart-element__image").attribute("style").value.split("('")[1].split("')")[0]
40
+ end
41
+ )
42
+ end
43
+ end
44
+
45
+ def self.billboard_200
46
+ document = Nokogiri::HTML.parse(open(BILLBOARD_200_URL))
47
+ songs = document.css(".chart-list__element")
48
+ songs.map do |song|
49
+ new_song = create_song_object(
50
+ song.css(".chart-element__information__song").text,
51
+ song.css(".chart-element__information__artist").text,
52
+ if song.css(".chart-element__image").attribute("style").value == "" #Empty style attribute catch
53
+ ""
54
+ else
55
+ song.css(".chart-element__image").attribute("style").value.split("('")[1].split("')")[0]
56
+ end
57
+ )
58
+ end
59
+ end
60
+
61
+ def self.create_artist_object(name, img_url)
62
+ {
63
+ name: name,
64
+ img_url: img_url
65
+ }
66
+ end
67
+
68
+ def self.create_song_object(name, artist, img_url)
69
+ {
70
+ name: name,
71
+ artist: artist,
72
+ img_url: img_url
73
+ }
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: billboard_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stephen McBride
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem to access Billboard data
14
+ email: stevemcbride3@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/billboard_api.rb
20
+ homepage: https://github.com/smcbride1/billboard_api
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.1
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: ''
43
+ test_files: []