Skip to content

Commit

Permalink
Add safe navigation for user_interaction_count (#226)
Browse files Browse the repository at this point in the history
* Add safe navigation for user_interaction_count

* Add new VCR cassettes

* Update VCR cassettes

* Remove unwanted cassettes

* Fix API cassette

* Fix tests
  • Loading branch information
Spone authored Oct 27, 2023
1 parent 2a94d69 commit 52ac0a7
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/video_info/providers/vimeo_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def stats
private

def user_interaction_count(interaction_type:)
interaction_statistic.find do |stat|
interaction_statistic&.find do |stat|
stat["interactionType"] == "http://schema.org/#{interaction_type}"
end["userInteractionCount"]
end&.public_send(:[], "userInteractionCount")
end

def interaction_statistic
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions spec/lib/video_info/providers/vimeo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,23 @@
its(:view_count) { should be nil }
end
end

context "with video 7848846" do
subject { VideoInfo.new("https://vimeo.com/7848846") }

its(:stats) {
if api_key
should eq({
"plays" => nil,
})
else
should eq({
"plays" => nil,
"likes" => nil,
"comments" => nil
})
end
}
end
end
end

0 comments on commit 52ac0a7

Please sign in to comment.