Skip to content

Commit edbf464

Browse files
author
claudiofullscreen
authored
Merge pull request #91 from Fullscreen/rescue-invalid-uri
Rescue invalid URI when fetching a page
2 parents a748697 + 888519f commit edbf464

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ For more information about changelogs, check
66
[Keep a Changelog](http://keepachangelog.com) and
77
[Vandamme](http://tech-angels.github.io/vandamme).
88

9+
## 0.2.26 - 2017/06/06
10+
11+
* [ENHANCEMENT] Raise ContentNotFound if Page#find is called with an invalid URI
12+
913
## 0.2.25 - 2017/05/16
1014

1115
* [FEATURE] Retry up to 5 times if Facebook responds with error

lib/funky/connections/api.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def self.fetch_data_with_paging_token(uri)
2626
def self.fetch(path_query, is_array: false)
2727
uri = URI "https://#{host}/v2.8/#{path_query}&limit=100&access_token=#{app_id}%7C#{app_secret}"
2828
is_array ? fetch_multiple_pages(uri).uniq : json_for(uri)
29+
rescue URI::InvalidURIError
30+
raise Funky::ContentNotFound, "Invalid URL"
2931
end
3032

3133
def self.fetch_multiple_pages(uri)

lib/funky/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Funky
2-
VERSION = "0.2.25"
2+
VERSION = "0.2.26"
33
end

spec/pages/find_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
it { expect { page }.to raise_error(Funky::ContentNotFound) }
2626
end
2727

28+
context 'given an invalid URI was passed' do
29+
let(:page_id) { ' some invalid URL ' }
30+
31+
it { expect { page }.to raise_error(Funky::ContentNotFound) }
32+
end
33+
2834
context 'given a website url was passed' do
2935
let(:page_id) { website_url }
3036

spec/pages/videos_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
let(:page_id) { nextflix_page_id }
3939

4040
# NOTE: This test fails if we only strictly followed the Facebook
41-
# documentation of fetching pages with timestmap-based pagination.
41+
# documentation of fetching pages with timestamp-based pagination.
4242
specify 'includes the oldest video of the page' do
4343
expect(videos.map {|v| v.id}).to include '68196585394'
4444
end
@@ -48,7 +48,7 @@
4848
let(:page_id) { nbc_page_id }
4949

5050
# NOTE: This test fails if we only strictly followed the Facebook
51-
# documentation of fetching pages with timestmap-based pagination.
51+
# documentation of fetching pages with timestamp-based pagination.
5252
specify 'includes the oldest video of the page' do
5353
expect(videos.map {|v| v.id}).to include '10152197716420746'
5454
end

0 commit comments

Comments
 (0)