billboard_api 0.1.0 → 0.2.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 +4 -4
  2. data/lib/billboard_api.rb +30 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b1093d880e57bbf546ef10d533baeb89b1de15179bb5f1139a8e204e3a2e567
4
- data.tar.gz: df4109750191432ae5d5a9778924bebed5c64bf2f2818a3335b022d4750bfcd6
3
+ metadata.gz: 3c6381acf0d23222f10bbed0de80f13cd7ac1de8a0d0f62b945323af5b8c5d4f
4
+ data.tar.gz: 24d76fb7cf06382e154211e4e3395ba84994c040e37b2059a423cf8b068c05f1
5
5
  SHA512:
6
- metadata.gz: c1b7580d2d1be293960ded9f3569969195f7d9a32606cd8a13cb74da63cdbcf2f849817269af6506860e35952ca57a11aac0b957947df4e9c785dfa3c8c9b0f4
7
- data.tar.gz: 2e9b8ee032234d3f2d4de354d327be4077eb0fdfa8bde2f1b20b6f8d3d36df2c039ef69299f7d4102813f5931a74899d142226b3df951f686dcd4248b9db53ae
6
+ metadata.gz: 0c1990631d499ff22cc3f746769442668f0f36f91e01e554f36b91fc47b3f2917813cffb69c241eb7ead9ccf925a706a11fad08076472e69c4b7f3910d48c390
7
+ data.tar.gz: 59d63b319b439e9d5b0ec57a668f4b802d36dc6b43b96d60ede5bdff5a2393c4da97c96579e029e1e1f38b1bf820d1621118d2bc5543cc11af317df1f36b1c0b
@@ -6,10 +6,18 @@ HOT_100_URL = "https://www.billboard.com/charts/hot-100"
6
6
  BILLBOARD_200_URL = "https://www.billboard.com/charts/billboard-200"
7
7
 
8
8
  class BillboardAPI
9
- def self.artist_100
9
+ @@cache_frequency = 86400
10
+
11
+ @@artist_100_cache = {}
12
+ @@artist_100_cache_time = 0
13
+ def self.artist_100(cache=false)
14
+ if cache && !(Time.now.to_i > @@artist_100_cache_time + @@cache_frequency)
15
+ return @@artist_100_cache
16
+ end
17
+ @@artist_100_cache_time = Time.now.to_i
10
18
  document = Nokogiri::HTML.parse(open(ARTIST_100_URL))
11
19
  artists = document.css(".chart-list-item")
12
- artists.map do |artist|
20
+ @@artist_100_cache = artists.map do |artist|
13
21
  new_artist = create_artist_object(
14
22
  artist.attribute("data-title").value,
15
23
  if artist.css(".chart-list-item__image-wrapper").css("img").length > 1
@@ -26,7 +34,12 @@ class BillboardAPI
26
34
  end
27
35
  end
28
36
 
29
- def self.hot_100
37
+ @@hot_100_cache = {}
38
+ @@hot_100_cache_time = 0
39
+ def self.hot_100(cache=false)
40
+ if cache && !(Time.now.to_i > @@hot_100_cache_time + @@cache_frequency)
41
+ return @@hot_100_cache
42
+ end
30
43
  document = Nokogiri::HTML.parse(open(HOT_100_URL))
31
44
  songs = document.css(".chart-list__element")
32
45
  songs.map do |song|
@@ -42,7 +55,12 @@ class BillboardAPI
42
55
  end
43
56
  end
44
57
 
45
- def self.billboard_200
58
+ @@billboard_200_cache = {}
59
+ @@billboard_200_cache_time = 0
60
+ def self.billboard_200(cache=false)
61
+ if cache && !(Time.now.to_i > @@billboard_200_cache_time + @@cache_frequency)
62
+ return @@billboard_200_cache
63
+ end
46
64
  document = Nokogiri::HTML.parse(open(BILLBOARD_200_URL))
47
65
  songs = document.css(".chart-list__element")
48
66
  songs.map do |song|
@@ -72,4 +90,12 @@ class BillboardAPI
72
90
  img_url: img_url
73
91
  }
74
92
  end
93
+
94
+ def self.cache_frequency
95
+ @@cache_frequency
96
+ end
97
+
98
+ def self.cache_frequency=(cache_frequency)
99
+ @@cache_frequency = cache_frequency
100
+ end
75
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billboard_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen McBride