funky 0.2.16 → 0.2.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/funky/connections/api.rb +15 -0
- data/lib/funky/connections/base.rb +9 -0
- data/lib/funky/page.rb +31 -0
- data/lib/funky/version.rb +1 -1
- data/lib/funky/video.rb +21 -0
- data/lib/funky.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da54bfb41c5753645c1a7c563b097bea1e95485a
|
4
|
+
data.tar.gz: 92fcb13e252a300a1d06b65bc776ae1b6edbd70e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f966f16d954f34554c4adbe39edae84683d259e9d59ea66e8c891d0747c00b4b77f4837716cefc7e04f4e7eded27d9bb7a2051b87180a43d4407e54ddaed14a3
|
7
|
+
data.tar.gz: 10e4b65adc153b6c884611ca281fe30e4a82bba35d3f9d8ceba9649549df8d813242e134b9db1f59203a2d8b190b175ecf8eab158eddfe2ad09c799b296c0081
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ For more information about changelogs, check
|
|
6
6
|
[Keep a Changelog](http://keepachangelog.com) and
|
7
7
|
[Vandamme](http://tech-angels.github.io/vandamme).
|
8
8
|
|
9
|
+
## 0.2.17 - 2017/04/17
|
10
|
+
|
11
|
+
* [FEATURE] Add `Funky::Page.find` class method to find a page by its page ID.
|
12
|
+
* [FEATURE] Add `Funky::Page#videos` instance method to list all videos under a page fetched by API call.
|
13
|
+
|
9
14
|
## 0.2.16 - 2017/04/02
|
10
15
|
|
11
16
|
* [ENHANCEMENT] Video.where(id: [..ids..]) now works even with more than 50 ids.
|
@@ -5,6 +5,21 @@ module Funky
|
|
5
5
|
# @api private
|
6
6
|
module Connection
|
7
7
|
class API < Base
|
8
|
+
def self.fetch(path_query, is_array: false)
|
9
|
+
uri = URI "https://#{host}/v2.8/#{path_query}&limit=100&access_token=#{app_id}%7C#{app_secret}"
|
10
|
+
is_array ? fetch_multiple_pages(uri) : json_for(uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.fetch_multiple_pages(uri)
|
14
|
+
json = json_for(uri)
|
15
|
+
if json[:paging][:next]
|
16
|
+
next_paging_uri = URI json[:paging][:next]
|
17
|
+
json[:data] + fetch_multiple_pages(next_paging_uri)
|
18
|
+
else
|
19
|
+
json[:data]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
8
23
|
def self.request(id:, fields:)
|
9
24
|
uri = URI::HTTPS.build host: host,
|
10
25
|
path: "/v2.8/#{id}",
|
@@ -17,6 +17,15 @@ module Funky
|
|
17
17
|
rescue SocketError => e
|
18
18
|
raise ConnectionError, e.message
|
19
19
|
end
|
20
|
+
|
21
|
+
def self.json_for(uri)
|
22
|
+
response = response_for(get_http_request(uri), uri)
|
23
|
+
if response.code == '200'
|
24
|
+
JSON.parse(response.body, symbolize_names: true)
|
25
|
+
else
|
26
|
+
raise ContentNotFound, "Error #{response.code}: #{response.body}"
|
27
|
+
end
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
data/lib/funky/page.rb
CHANGED
@@ -1,6 +1,37 @@
|
|
1
1
|
module Funky
|
2
2
|
class Page < GraphRootNode
|
3
3
|
|
4
|
+
# Fetches the data from Facebook Graph API and returns a Funky::Page object.
|
5
|
+
# It accepts a page ID.
|
6
|
+
#
|
7
|
+
# @example Getting a page object
|
8
|
+
# Funky::Page.find 'FullscreenInc' # or
|
9
|
+
# Funky::Page.find '221406534569729'
|
10
|
+
# # => #<Funky::Page @data={:name=>"Fullscreen", :id=>"221406534569729"}>
|
11
|
+
#
|
12
|
+
# @return [Funky::Page] containing the data fetched by Facebook Graph API.
|
13
|
+
def self.find(page_id)
|
14
|
+
page = Funky::Connection::API.fetch("#{page_id}?fields=name,username,location")
|
15
|
+
new(page)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Fetches data from Facebook Graph API and returns an array of Funky::Video
|
19
|
+
# objects belong to the caller page.
|
20
|
+
#
|
21
|
+
# @example Getting videos under a page
|
22
|
+
# page = Funky::Page.find 'FullscreenInc'
|
23
|
+
# page.videos
|
24
|
+
# # => [#<Funky::Video @data={...}>, #<Funky::Video @data={...}>]
|
25
|
+
#
|
26
|
+
# @return [Array<Funky::Video>] multiple Funky::Video objects containing data
|
27
|
+
# fetched by Facebook Graph API.
|
28
|
+
def videos
|
29
|
+
videos = Funky::Connection::API.fetch(
|
30
|
+
"#{id}/videos?fields=id,title,description,created_time,length,comments.limit(0).summary(true),likes.limit(0).summary(true),reactions.limit(0).summary(true)",
|
31
|
+
is_array: true)
|
32
|
+
videos.map {|video| Video.new(video) }
|
33
|
+
end
|
34
|
+
|
4
35
|
# @note
|
5
36
|
# For example, for www.facebook.com/platform the username is 'platform'.
|
6
37
|
# @see https://developers.facebook.com/docs/graph-api/reference/page/
|
data/lib/funky/version.rb
CHANGED
data/lib/funky/video.rb
CHANGED
@@ -26,6 +26,27 @@ module Funky
|
|
26
26
|
data[:length]
|
27
27
|
end
|
28
28
|
|
29
|
+
# @return [String] the title of the video.
|
30
|
+
def title
|
31
|
+
data[:title].to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
# see https://developers.facebook.com/docs/graph-api/reference/video/
|
35
|
+
# @return [Integer] the total number of likes for the video.
|
36
|
+
def count_likes
|
37
|
+
data[:likes][:summary][:total_count]
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Integer] the total number of comments for the video.
|
41
|
+
def count_comments
|
42
|
+
data[:comments][:summary][:total_count]
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Integer] the total number of reactions for the video.
|
46
|
+
def count_reactions
|
47
|
+
data[:reactions][:summary][:total_count]
|
48
|
+
end
|
49
|
+
|
29
50
|
# @return [String] the picture URL of the video.
|
30
51
|
def picture
|
31
52
|
data[:picture]
|
data/lib/funky.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philip Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|