funky 0.2.13 → 0.2.14
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 +4 -4
- data/CHANGELOG.md +7 -7
- data/README.md +20 -0
- data/lib/funky.rb +2 -0
- data/lib/funky/graph_root_node.rb +47 -0
- data/lib/funky/page.rb +100 -0
- data/lib/funky/version.rb +1 -1
- data/lib/funky/video.rb +3 -42
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee32f9048854c9fb49890992ea93946e409f1ee
|
4
|
+
data.tar.gz: 737ab7795b544735f2d992adacdc5ca1241ab6f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e44f6f848b9beff059e7fb522a98fd42878e6b5c18389bd827481054428e492d537ee0cc60fce4571e7a5d78a30330ef1c2de7223b7da28be7a91e4fa9ffdb88
|
7
|
+
data.tar.gz: 58fd2f90d6e025818ed09f39d47062ce4011e72b7a131bd787041f4ccb66fd2fccca7c5bbabaf15aaacd3e8c0561aefc99f91828ac5e8faa7c44354a2bd4bf90
|
data/CHANGELOG.md
CHANGED
@@ -6,17 +6,17 @@ 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.
|
10
|
-
|
11
|
-
* [BUGFIX] When Facebook responds with a 302 redirect, sometimes an URL
|
12
|
-
with a space is returned (e.g., "https://www.facebook.com/KinoToPrzygoda /videos/322742591438587/") that is not URI encoded. This causes URI#parse to raise an InvalidURIError unless the URL is URL encoded.
|
9
|
+
## 0.2.14 - 2017/02/06
|
13
10
|
|
11
|
+
* [ENHANCEMENT] Add the Funky::Page API to fetch name, username,
|
12
|
+
location, city, state, zip, street, country, longitude,
|
13
|
+
and latitude fields from the Facebook Graph API given a page ID.
|
14
14
|
|
15
|
-
## 2017/01/
|
15
|
+
## 0.2.13 - 2017/01/25
|
16
16
|
|
17
|
+
* [BUGFIX] Correctly fetch data for videos that belong to a Facebook page with a username that contains URL-unsafe characters. For instance "https://www.facebook.com/KinoToPrzygoda /" (with a space) is a valid Facebook page URL.
|
17
18
|
* [ENHANCEMENT] Use 2.8 of Facebook Graph API (upgrade from 2.6).
|
18
|
-
- There were deprecations in v2.8 of the Facebook Graph API as well as
|
19
|
-
additions documented in [the changelog](https://developers.facebook.com/docs/apps/changelog).
|
19
|
+
- There were deprecations in v2.8 of the Facebook Graph API as well as additions documented in [the changelog](https://developers.facebook.com/docs/apps/changelog).
|
20
20
|
- The current API of Funky is not affected.
|
21
21
|
|
22
22
|
## 0.2.12 - 2017/01/19
|
data/README.md
CHANGED
@@ -47,6 +47,26 @@ There are two ways to configure Funky with your App ID and App Secret:
|
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
50
|
+
##API Overview
|
51
|
+
|
52
|
+
Funky consists of 2 different surface APIs - one to fetch video data
|
53
|
+
from Facebook and one to fetch page data from Facebook.
|
54
|
+
|
55
|
+
##Pages API
|
56
|
+
|
57
|
+
### Use #where clause to get an array of videos
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
ids = ['1487249874853741', '526533744142224']
|
61
|
+
pages = Funky::Page.where(id: ids)
|
62
|
+
pages.first.id # => '1487249874853741'
|
63
|
+
pages.first.name # => 'Sony Pictures'
|
64
|
+
pages.first.username # => 'SonyPicturesGlobal'
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
##Videos API
|
69
|
+
|
50
70
|
### Use #where clause to get an array of videos
|
51
71
|
|
52
72
|
```ruby
|
data/lib/funky.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
module Funky
|
2
|
+
class GraphRootNode
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
# @return [String] the object ID.
|
10
|
+
def id
|
11
|
+
data[:id]
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.fetch_and_parse_data(ids)
|
17
|
+
if ids.is_a?(Array) && ids.size > 1
|
18
|
+
response = Connection::API.batch_request(ids: ids, fields: fields)
|
19
|
+
else
|
20
|
+
id = ids.is_a?(Array) ? ids.first : ids
|
21
|
+
response = Connection::API.request(id: id, fields: fields)
|
22
|
+
end
|
23
|
+
parse response
|
24
|
+
rescue ContentNotFound
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.parse(response)
|
29
|
+
if response.code == '200'
|
30
|
+
body = JSON.parse response.body, symbolize_names: true
|
31
|
+
if body.is_a? Array
|
32
|
+
body.select{|item| item[:code] == 200}.collect do |item|
|
33
|
+
JSON.parse(item[:body], symbolize_names: true)
|
34
|
+
end.compact
|
35
|
+
else
|
36
|
+
[body]
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise ContentNotFound, "Error #{response.code}: #{response.body}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.instantiate_collection(items)
|
44
|
+
items.collect { |item| new item }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/funky/page.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module Funky
|
2
|
+
class Page < GraphRootNode
|
3
|
+
|
4
|
+
# @note
|
5
|
+
# For example, for www.facebook.com/platform the username is 'platform'.
|
6
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/page/
|
7
|
+
# @return [String] the alias of the Facebook Page.
|
8
|
+
def username
|
9
|
+
data[:username]
|
10
|
+
end
|
11
|
+
|
12
|
+
# @note
|
13
|
+
# For example, for www.facebook.com/platform the name is
|
14
|
+
# 'Facebook For Developers'.
|
15
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/page/
|
16
|
+
# @return [String] the name of the Facebook Page.
|
17
|
+
def name
|
18
|
+
data[:name]
|
19
|
+
end
|
20
|
+
|
21
|
+
# @note
|
22
|
+
# location is a Hash that contains more specific properties such as city,
|
23
|
+
# state, zip, etc.
|
24
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/page/
|
25
|
+
# @return [Hash] the location of the Facebook Page if it is present
|
26
|
+
def location
|
27
|
+
data.fetch(:location, {})
|
28
|
+
end
|
29
|
+
|
30
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
31
|
+
# @return [String, nil] the city of the Facebook Page if it is present
|
32
|
+
def city
|
33
|
+
location[:city]
|
34
|
+
end
|
35
|
+
|
36
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
37
|
+
# @return [String, nil] the street of the Facebook Page if it is present
|
38
|
+
def street
|
39
|
+
location[:street]
|
40
|
+
end
|
41
|
+
|
42
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
43
|
+
# @return [String, nil] the state of the Facebook Page if it is present
|
44
|
+
def state
|
45
|
+
location[:state]
|
46
|
+
end
|
47
|
+
|
48
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
49
|
+
# @return [String, nil] the country of the Facebook Page if it is present
|
50
|
+
def country
|
51
|
+
location[:country]
|
52
|
+
end
|
53
|
+
|
54
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
55
|
+
# @return [String] the zip code of the Facebook Page if it is present
|
56
|
+
def zip
|
57
|
+
location[:zip]
|
58
|
+
end
|
59
|
+
|
60
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
61
|
+
# @return [Fixnum, nil] the latitude of the Facebook Page if it is present
|
62
|
+
def latitude
|
63
|
+
location[:latitude]
|
64
|
+
end
|
65
|
+
|
66
|
+
# @see https://developers.facebook.com/docs/graph-api/reference/location/
|
67
|
+
# @return [Fixnum, nil] the longitude of the Facebook Page if it is present
|
68
|
+
def longitude
|
69
|
+
location[:longitude]
|
70
|
+
end
|
71
|
+
|
72
|
+
# Fetches the data from Facebook's APIs and instantiates the data
|
73
|
+
# into an Array of Funky::Page objects. It can accept one page ID or an
|
74
|
+
# array of multiple page IDs.
|
75
|
+
#
|
76
|
+
# @example Getting one page
|
77
|
+
# id = '10153834590672139'
|
78
|
+
# Funky::Page.where(id: id) # => [#<Funky::Page>]
|
79
|
+
# @example Getting multiple videos
|
80
|
+
# ids = ['10154439119663508', '10153834590672139']
|
81
|
+
# Funky::Page.where(id: ids) # => [#<Funky::Page>, #<Funky::Page>]
|
82
|
+
#
|
83
|
+
# @return [Array<Funky::Page>] multiple instances of Funky::Page objects
|
84
|
+
# containing data obtained by Facebook's APIs.
|
85
|
+
def self.where(id:)
|
86
|
+
return nil unless id
|
87
|
+
instantiate_collection(fetch_and_parse_data Array(id))
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def self.fields
|
93
|
+
[
|
94
|
+
'name',
|
95
|
+
'username',
|
96
|
+
'location'
|
97
|
+
]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/funky/version.rb
CHANGED
data/lib/funky/video.rb
CHANGED
@@ -3,22 +3,13 @@ require 'funky/html/parser'
|
|
3
3
|
require 'funky/url'
|
4
4
|
|
5
5
|
module Funky
|
6
|
-
class Video
|
7
|
-
|
6
|
+
class Video < GraphRootNode
|
7
|
+
|
8
8
|
attr_accessor :counters
|
9
9
|
|
10
10
|
@@html_page = HTML::Page.new
|
11
11
|
@@html_parser = HTML::Parser.new
|
12
12
|
|
13
|
-
def initialize(data)
|
14
|
-
@data = data
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [String] the video ID.
|
18
|
-
def id
|
19
|
-
data[:id]
|
20
|
-
end
|
21
|
-
|
22
13
|
# @return [DateTime] the created time of the video.
|
23
14
|
def created_time
|
24
15
|
datetime = data[:created_time]
|
@@ -50,6 +41,7 @@ module Funky
|
|
50
41
|
data.fetch(:from)[:id]
|
51
42
|
end
|
52
43
|
|
44
|
+
# @return [String] the url of Facebook page for the video.
|
53
45
|
def page_url
|
54
46
|
"https://www.facebook.com/#{page_id}"
|
55
47
|
end
|
@@ -122,37 +114,6 @@ module Funky
|
|
122
114
|
|
123
115
|
private
|
124
116
|
|
125
|
-
def self.fetch_and_parse_data(ids)
|
126
|
-
if ids.is_a?(Array) && ids.size > 1
|
127
|
-
response = Connection::API.batch_request(ids: ids, fields: fields)
|
128
|
-
else
|
129
|
-
id = ids.is_a?(Array) ? ids.first : ids
|
130
|
-
response = Connection::API.request(id: id, fields: fields)
|
131
|
-
end
|
132
|
-
parse response
|
133
|
-
rescue ContentNotFound
|
134
|
-
[]
|
135
|
-
end
|
136
|
-
|
137
|
-
def self.parse(response)
|
138
|
-
if response.code == '200'
|
139
|
-
body = JSON.parse response.body, symbolize_names: true
|
140
|
-
if body.is_a? Array
|
141
|
-
body.select{|item| item[:code] == 200}.collect do |item|
|
142
|
-
JSON.parse(item[:body], symbolize_names: true)
|
143
|
-
end.compact
|
144
|
-
else
|
145
|
-
[body]
|
146
|
-
end
|
147
|
-
else
|
148
|
-
raise ContentNotFound, "Error #{response.code}: #{response.body}"
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def self.instantiate_collection(items)
|
153
|
-
items.collect { |item| new item }
|
154
|
-
end
|
155
|
-
|
156
117
|
def self.fields
|
157
118
|
[
|
158
119
|
'created_time',
|
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.14
|
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-
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -121,8 +121,10 @@ files:
|
|
121
121
|
- lib/funky/connections/api.rb
|
122
122
|
- lib/funky/connections/base.rb
|
123
123
|
- lib/funky/errors.rb
|
124
|
+
- lib/funky/graph_root_node.rb
|
124
125
|
- lib/funky/html/page.rb
|
125
126
|
- lib/funky/html/parser.rb
|
127
|
+
- lib/funky/page.rb
|
126
128
|
- lib/funky/url.rb
|
127
129
|
- lib/funky/version.rb
|
128
130
|
- lib/funky/video.rb
|