funky 0.2.16 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca9e59faa72e0eb097bef057e1b91e548cdc013d
4
- data.tar.gz: 24aa6cdd8306a6396205b844145dcd62b5027967
3
+ metadata.gz: da54bfb41c5753645c1a7c563b097bea1e95485a
4
+ data.tar.gz: 92fcb13e252a300a1d06b65bc776ae1b6edbd70e
5
5
  SHA512:
6
- metadata.gz: b2426dcb4df32fa10e0615c889b9d1f642c331b68280c0d5cc89ad83860adff97c361a85fbfbbdc7ee4578e0c2d17d8aacdea7385575e1351efb5739ee7ea815
7
- data.tar.gz: 7a0e74d6762a7bff04425b8a13c2dff867f54d58247ec848e7fa3e8dd97f504eb6dc1be61229e91bfd3dcfd5441eccdb92e4bd3826954c338fe3a6a21c540d5e
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
@@ -1,3 +1,3 @@
1
1
  module Funky
2
- VERSION = "0.2.16"
2
+ VERSION = "0.2.17"
3
3
  end
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
@@ -1,7 +1,8 @@
1
1
  require 'date'
2
+ require 'net/http'
3
+
2
4
  require "funky/version"
3
5
  require 'funky/errors'
4
- require 'net/http'
5
6
  require 'funky/connections/api'
6
7
  require 'funky/configuration'
7
8
  require "funky/graph_root_node"
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.16
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-02 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler