Skip to content

Commit

Permalink
Merge pull request #64 from claudiofullscreen/follow-redirects
Browse files Browse the repository at this point in the history
Follow redirects when Facebook responds with 302
  • Loading branch information
claudiofullscreen committed Jan 19, 2017
2 parents 3d2ab24 + 8cd1b3a commit 66a0263
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,14 +6,19 @@ For more information about changelogs, check
[Keep a Changelog](http://keepachangelog.com) and
[Vandamme](http://tech-angels.github.io/vandamme).

## 0.2.11 - 2017/01/19

* [ENHANCEMENT] Follow redirects when Facebook responds with 302
* [ENHANCEMENT] Parse new format of view count in Facebook HTML

## 0.2.10 - 2016/12/20

* [ENHANCEMENT] Add a facebook page ID as a part of the Funky::Video API
* [ENHANCEMENT] Add a facebook page URL as a part of the Funky::Video API

## 0.2.9 - 2016/12/13

* [BUGFIX] Allow a video ID to be parsed out of facebook video URLs with
* [BUGFIX] Allow a video ID to be parsed out of facebook video URLs with
trailing slashes.

## 0.2.8 - 2016/12/12
Expand Down
9 changes: 8 additions & 1 deletion lib/funky/html/page.rb
Expand Up @@ -16,9 +16,16 @@ def get(video_id:)
def response_for(video_id)
uri = uri_for video_id
request = Net::HTTP::Get.new(uri.request_uri)
Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
response = Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
http.request request
end
if response.is_a? Net::HTTPRedirection
request = Net::HTTP::Get.new URI.parse(response.header['location'])
response = Net::HTTP.start(uri.host, 443, use_ssl: true) do |http|
http.request request
end
end
response
rescue *server_errors => e
raise ConnectionError, e.message
end
Expand Down
1 change: 1 addition & 0 deletions lib/funky/html/parser.rb
Expand Up @@ -19,6 +19,7 @@ def extract_shares_from(html)
def extract_views_from(html)
html.match(/<div><\/div><span class="fcg">\D*([\d,.]+)/)
html.match %r{([\d,.]*?) views from this post} if $1.nil?
html.match /<div class=\"_1vx9\"><span>([\d,.]*?) Views<\/span><\/div>/ if $1.nil?
matched_count $1
end

Expand Down
2 changes: 1 addition & 1 deletion lib/funky/version.rb
@@ -1,3 +1,3 @@
module Funky
VERSION = "0.2.10"
VERSION = "0.2.11"
end

1 comment on commit 66a0263

@himberjack
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like only the views are being fetched...

Please sign in to comment.