diff --git a/README.md b/README.md index 7db80e4..63fed49 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,7 @@ -# README +asbo: +an aggregator of a few London-based internet radio stations - using Nokogiri to scrape the html where needed, caching the resulting objects in a local db -This README would normally document whatever steps are necessary to get the -application up and running. +backend is in rails, front-end is in react/redux -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... +to start the backend api and the client, use the following command: +$ foreman start diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index f572a65..4c83248 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -47,6 +47,7 @@ def delete_episodes begin platform_from_nickname_param @platform.episodes.delete_all + @platform.update(last_page: 0) render json: { :success => :true, :platform => platform_with_episodes diff --git a/app/javascripts/__mocks__/api.js b/app/javascripts/__mocks__/api.js index 289c4a0..6f997ac 100644 --- a/app/javascripts/__mocks__/api.js +++ b/app/javascripts/__mocks__/api.js @@ -14,8 +14,9 @@ const MockAPI = class { } getPlatform({nickname}){ - // console.log(`mockAPI.fetch /platforms/${nickname}`) - const platform = platforms.find(p => p.nickname == nickname) + console.log(`mockAPI.fetch /platforms/${nickname}`) + let platform = platforms.find(p => p.nickname == nickname) + return new Promise((resolve,reject) => { if(!!platform) { setTimeout(resolve, 0, { @@ -38,7 +39,7 @@ const MockAPI = class { // in the real api, filter is passed to backend so repsonse contains a sub-set of total items.. // in the mock api, the filter is just post-processing in the callback refreshPlatform({nickname,filter,page}){ - console.log(`mockAPI.fetch /platforms/${nickname}/refresh ${JSON.stringify({filter,page})}`); + // console.log(`mockAPI.fetch /platforms/${nickname}/refresh ${JSON.stringify({filter,page})}`); const platform = platforms.find(p => p.nickname == nickname) return new Promise((resolve,reject) => { if(!platform) { @@ -51,7 +52,9 @@ const MockAPI = class { //console.log(totalEps.map(ep => ep.name)) const matches = totalEps.filter(e => this.isMatchingEpisode(e, filter)) setTimeout(resolve, 0, { - ...platform, episodes: matches + ...platform, + last_page: (platform.last_page + 1), + episodes: matches }) } }) diff --git a/app/javascripts/__mocks__/platforms.js b/app/javascripts/__mocks__/platforms.js index e876f6e..09ad2af 100644 --- a/app/javascripts/__mocks__/platforms.js +++ b/app/javascripts/__mocks__/platforms.js @@ -27,7 +27,8 @@ export default [{ "100x100", "800x800" ] - }] + }], + "last_page" : 0 }, { "id": 2, @@ -51,7 +52,8 @@ export default [{ "nickname": "rinse", "use_relative_images": false, "default_image": "https://etc.levels.io/rinse-fm/logo.png", - "post_processing_rules": null + "post_processing_rules": null, + "last_page" : 3 }, { "id": 3, "name": "radar radio", @@ -75,5 +77,6 @@ export default [{ "nickname": "radar", "use_relative_images": true, "default_image": null, - "post_processing_rules": null + "post_processing_rules": null, + "last_page" : 2 }] \ No newline at end of file diff --git a/app/javascripts/components/PlatformDetails.js b/app/javascripts/components/PlatformDetails.js index aebadba..7e1a83a 100644 --- a/app/javascripts/components/PlatformDetails.js +++ b/app/javascripts/components/PlatformDetails.js @@ -19,6 +19,7 @@ class PlatformDetails extends Component { pagination, refreshPlatform, episodes, + last_page, currentPage } = this.props @@ -53,7 +54,8 @@ class PlatformDetails extends Component { Edit Platform

- Episodes{' '}{this.refreshButton()}{' '}{this.deleteEpisodesButton()} + Episodes{' '}{this.refreshButton()}{' '}{this.deleteEpisodesButton()}
+ Last page fetched: {last_page}

{this.episodeGrid()} diff --git a/app/javascripts/components/PlatformForm.js b/app/javascripts/components/PlatformForm.js index 7a189cb..01fe50f 100644 --- a/app/javascripts/components/PlatformForm.js +++ b/app/javascripts/components/PlatformForm.js @@ -11,7 +11,7 @@ class PlatformForm extends Component { render() { const {initialValues, handleSubmit, pristine, reset, submitting, loading, isNew } = this.props const {nickname} = initialValues || {} - + console.log(initialValues) return (

@@ -29,6 +29,7 @@ class PlatformForm extends Component { parent='pagination' attrs='param,url,itemsPerPage' /> +

TRACKLIST

- - +
+
+
Murlo 18.07.18 Radio Episode +
+ Play +
+
18.07.18LDN +
Murlo
+
+ +
Tracklist +
_BREAK_
diff --git a/db/schema.rb b/db/schema.rb index eeff194..90a5876 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180330142948) do +ActiveRecord::Schema.define(version: 20180906153751) do create_table "episodes", force: :cascade do |t| t.string "name" @@ -36,6 +36,7 @@ t.boolean "use_relative_images" t.string "default_image" t.text "post_processing_rules" + t.integer "last_page" end end diff --git a/features/episodes/dates.feature b/features/episodes/dates.feature index 02c899c..bde33e0 100644 --- a/features/episodes/dates.feature +++ b/features/episodes/dates.feature @@ -14,8 +14,8 @@ Feature: Handle Dates @date @ordinal @radar Scenario: Parse dates for Radar Given this date '23rd Feb' - And this implicit year '2018' + And this implicit year '2019' And this date format '%e %b' When I set the date_str for the episode - Then episode.date.to_s will be '2018-02-23' + Then episode.date.to_s will be '2019-02-23' \ No newline at end of file diff --git a/features/episodes/image_paths.feature b/features/episodes/image_paths.feature index 6691e65..41cf925 100644 --- a/features/episodes/image_paths.feature +++ b/features/episodes/image_paths.feature @@ -9,11 +9,17 @@ I want to prefix relative paths with the platform's base path And the platform has relative_image_paths='false' And html for an episode """ - +
+
+
Mija MGMT w/ San Cha +
+
+
""" When I parse the html - Then the platform will contain an episode with this image 'https://media.ntslive.co.uk/resize/800x800/8daa0f85-a541-47a1-88cf-26c18ebf342f_1444643834.jpg' + Then the platform will contain an episode with this image 'https://media2.ntslive.co.uk/resize/800x800/58dab62a-db5d-4bc9-9c2c-9708a6b846c8_1571097600.jpeg' @episode @images Scenario: image is absolute diff --git a/features/episodes/media_embed.feature b/features/episodes/media_embed.feature index f20ee29..c753e62 100644 --- a/features/episodes/media_embed.feature +++ b/features/episodes/media_embed.feature @@ -13,7 +13,7 @@ Scenario: fetch a soundcloud embed When I post the attributes to the media endpoint Then I will get this embed back """ - + """ @media @soundcloud @embed @error diff --git a/features/episodes/media_type.feature b/features/episodes/media_type.feature index 5871cc0..6d2a314 100644 --- a/features/episodes/media_type.feature +++ b/features/episodes/media_type.feature @@ -8,12 +8,13 @@ Scenario: nts x mixcloud Given the platform nickname=nts And html for an episode """ - + """ When I parse the html Then the platform will contain an episode with this media property |type|url| - |mixcloud|https://www.mixcloud.com/NTSRadio/grandmixxer-22nd-february-2018/| + |mixcloud|https://www.mixcloud.com/NTSRadio/hit-a-lick-14th-october-2019/| @media @soundcloud diff --git a/features/episodes/post_processing.feature b/features/episodes/post_processing.feature index af3f967..c2e388f 100644 --- a/features/episodes/post_processing.feature +++ b/features/episodes/post_processing.feature @@ -8,9 +8,9 @@ I want to perform post-processing on the episode after it is created Given the platform nickname=nts And html for an episode """ - + """ When I parse the html - Then the platform will contain an episode with this image 'https://media2.ntslive.co.uk/resize/800x800/f0cf5a5b-ea8b-4123-ae58-2b72662c6ac8_1522281600.jpeg' + Then the platform will contain an episode with this image 'https://media2.ntslive.co.uk/resize/800x800/2fa12bb5-b8a3-4984-9d79-d5f102ae3005_1571097600.png' diff --git a/features/episodes/step_definitions/image_steps.rb b/features/episodes/step_definitions/image_steps.rb index 4aff23b..2850894 100644 --- a/features/episodes/step_definitions/image_steps.rb +++ b/features/episodes/step_definitions/image_steps.rb @@ -10,6 +10,7 @@ Then("the platform will contain an episode with this image {string}") do |src| @ep = @platform.episodes.find do |ep| + puts ep.image ep.image == src end expect(@ep).to be_truthy diff --git a/features/episodes/step_definitions/media_steps.rb b/features/episodes/step_definitions/media_steps.rb index fa10c05..bee2777 100644 --- a/features/episodes/step_definitions/media_steps.rb +++ b/features/episodes/step_definitions/media_steps.rb @@ -10,12 +10,14 @@ @media = { media: JSON.parse(attrs) } + puts @media end When("I post the attributes to the media endpoint") do post "/media", @media @response = last_response.body @json = JSON.parse(@response) + puts @json end Then("I will get this embed back") do |html| diff --git a/features/platforms/attributes.feature b/features/platforms/attributes.feature index 33819a6..4f48825 100644 --- a/features/platforms/attributes.feature +++ b/features/platforms/attributes.feature @@ -3,17 +3,17 @@ Feature: Store scraping rules in platform I want to abstract the rules into an attribute map And share the implementation across different platforms - @attr + @attr @nts @platform Scenario: Parse NTS.live When I call create_episodes_from_html on platform 1 Then I should get an episode with these attributes """ { "platform_id" : 1, - "name":"Murlo 31.01.18 Radio Episode", - "media":{"type":"mixcloud", "url":"https://www.mixcloud.com/NTSRadio/murlo-31st-february-2018/"}, - "image":"https://media.ntslive.co.uk/resize/800x800/24463c4a-6d6d-48d7-9026-62c9af3b996f_1456963200.jpeg", - "date": "2018-01-31" + "name":"Murlo 18.07.18 Radio Episode", + "media":{"type":"mixcloud", "url":"https://www.mixcloud.com/NTSRadio/murlo-18th-july-2018/", "path":"/NTSRadio/murlo-18th-july-2018/"}, + "image":"https://media.ntslive.co.uk/resize/400x400/24463c4a-6d6d-48d7-9026-62c9af3b996f_1456963200.jpeg", + "date": "2018-07-18" } """ @@ -25,7 +25,7 @@ Feature: Store scraping rules in platform { "platform_id":2, "name":"Swamp 81 with Loefah \u0026 Piezo", - "media":{"type":"soundcloud", "url":"https://soundcloud.com/rinsefm/horsemeatdisco040218swamp81"}, + "media":{"type":"soundcloud", "url":"https://soundcloud.com/rinsefm/horsemeatdisco040218swamp81", "path":"/rinsefm/horsemeatdisco040218swamp81"}, "image":"http://rinse.fm/wp-content/uploads/2012/09/133_loefah_chunky_2.png", "date":"2018-02-04" } diff --git a/features/platforms/refresh.feature b/features/platforms/refresh.feature index 6d0ff6f..d6a169a 100644 --- a/features/platforms/refresh.feature +++ b/features/platforms/refresh.feature @@ -7,7 +7,7 @@ Feature: Refresh Platform Background: Given the platform nickname=nts - @http + @http @empty Scenario: Refresh a platform without any episodes When I refresh the Platform Then the episodes list should contain some episodes @@ -16,6 +16,7 @@ Feature: Refresh Platform Scenario: Refresh a platform that already has some episodes Given this html for multiple entries """ +
@@ -374,3 +375,9 @@ Feature: Refresh Platform |Ted Draws - 1997 Special 13.02.18 Radio Episode|13.02.18| |Obongjayar 13.02.18 Radio Episode|13.02.18| |Nabihah Iqbal 13.02.18 Radio Episode|13.02.18| + + @http @nts @pagination + Scenario: Remember the last page captured in refresh + Given the platform's last_page is 2 + When I refresh the Platform + Then the platform's last_page is incremented to 3 \ No newline at end of file diff --git a/features/platforms/step_definitions/attributes_steps.rb b/features/platforms/step_definitions/attributes_steps.rb index 2795739..21f5878 100644 --- a/features/platforms/step_definitions/attributes_steps.rb +++ b/features/platforms/step_definitions/attributes_steps.rb @@ -17,8 +17,14 @@ @platform = @platform || @platforms.find {|p|p.id == attrs['platform_id']} @episode = @platform.episodes.first # iterate over attributes so we can specify date format for comparison + # puts @episode.attributes @ep_attrs = @episode.attributes.merge({ "date" => @episode.attributes['date'].to_s }) + # @episode.attributes.each do |pair| + # key = pair.first + # val = pair.last + # puts "#{key} => #{val} == #{@attrs[key]} ?" + # end expect(@ep_attrs).to include(@attrs) end diff --git a/features/platforms/step_definitions/refresh_steps.rb b/features/platforms/step_definitions/refresh_steps.rb index 3326df4..cdf6583 100644 --- a/features/platforms/step_definitions/refresh_steps.rb +++ b/features/platforms/step_definitions/refresh_steps.rb @@ -27,4 +27,12 @@ expect(slice).to match_array(uniques.hashes) end +Given("the platform's last_page is {int}") do |p| + @platform.last_page = p +end + + +Then("the platform's last_page is incremented to {int}") do |p| + expect(@platform.last_page).to eq(p) +end