vid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca2e71c094dd3d7f44f7461b72828a13d28e6646
4
+ data.tar.gz: 9a1b601c251ea3b85dc3c9aae80d003bbb647b91
5
+ SHA512:
6
+ metadata.gz: 0169808d7ce0fb7ea970c8cb36bf65b6b08339e7cf931f592ef0cf26f9d66fcaccadd14c1e6ce4d8899345df524810f5d3e4d23a25787e5b53687476dbe229b5
7
+ data.tar.gz: 35a2f84f9bc46b21ddf898dd8e89f27a6d0248df247456dcd64873e0acf82b69c6324949393374d0269ce0593bd8d723a4dea684de4e905a30e376e53b051d79
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --fail-fast
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gem 'pry-nav'
3
+
4
+ # Specify your gem's dependencies in vid.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 claudiob
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Compared to ActiveResource
2
+
3
+ * Automated mapping => no, we want video-specific attributes.
4
+
5
+ * Endpoint => there can be multiple, and I need .select or .pluck
6
+
7
+ * collection_path is unique in AR but cannot be here (graph / scrape)
8
+
9
+ * same with connection
10
+
11
+ * I can skip create, delete, basic auth, proxy
12
+
13
+ For instance a Facebook::Video has two connections, with two collection_path
14
+
15
+ Which one I used is based on `.select` (by default, all of them)
16
+
17
+ YouTube::Video has one connection for data, one for analytics ???
18
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vid"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/vid ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'vid'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'vid'
8
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vid"
8
+ spec.version = Vid::VERSION
9
+ spec.authors = ["claudiob"]
10
+ spec.email = ["claudiob@gmail.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "http://example.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+
25
+ spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'coveralls', '~> 0.8.10'
27
+
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'vid/facebook/video'
2
+ require 'vid/youtube/video'
3
+
4
+ # By including Vid in the main namespace, we can use the shorter notations
5
+ # Facebook::Video and YouTube::Video, without the Vid:: prefix.
6
+ # Yes, we are polluting the namespace!
7
+ include Vid
@@ -0,0 +1,10 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module Vid
5
+ module Base
6
+ class Video
7
+ attr_reader :id, :published_at, :title, :comment_count, :like_count, :view_count
8
+ end
9
+ end
10
+ end
File without changes
File without changes
@@ -0,0 +1,67 @@
1
+ require 'vid/base/video'
2
+
3
+ module Vid
4
+ module Facebook
5
+ class Video < Base::Video
6
+ attr_reader :id, :published_at, :title, :comment_count, :like_count
7
+ def initialize(attributes = {})
8
+ @id = attributes['id']
9
+ @published_at = attributes['created_time']
10
+ @title = attributes['description']
11
+ @comment_count = attributes['comments']['summary']['total_count']
12
+ @like_count = attributes['likes']['summary']['total_count']
13
+ @view_count = attributes[:view_count]
14
+ end
15
+
16
+ def self.find(id)
17
+ uri = URI::HTTPS.build host: 'graph.facebook.com', path: "/v2.6/#{id}", query: "access_token=#{ENV['FB_APP_ID']}%7C#{ENV['FB_APP_SECRET']}&fields=id,permalink_url,created_time,description,title,from,comments.limit(0).summary(true),likes.limit(0).summary(true)"
18
+ http_request = Net::HTTP::Get.new(uri.request_uri)
19
+
20
+ net_http_options = [uri.host, uri.port, use_ssl: true]
21
+ response = Net::HTTP.start('graph.facebook.com', 443, use_ssl: true) do |http|
22
+ http.request http_request
23
+ end
24
+
25
+ attributes = JSON response.body
26
+
27
+ uri = URI::HTTPS.build host: 'www.facebook.com', path: "/video.php", query: "v=#{id}"
28
+ http_request = Net::HTTP::Get.new(uri.request_uri)
29
+
30
+ net_http_options = [uri.host, uri.port, use_ssl: true]
31
+ response = Net::HTTP.start('www.facebook.com', 443, use_ssl: true) do |http|
32
+ http.request http_request
33
+ end
34
+
35
+ view_count = %r{<div></div><span class="fcg">(?<views>.*) Views</span>}.match(response.body)[:views].tr(',','').to_i
36
+ new attributes.merge(view_count: view_count)
37
+ end
38
+
39
+ def self.where(clauses)
40
+ uri = URI::HTTPS.build host: 'graph.facebook.com', path: "/", query: "include_headers=false&access_token=#{ENV['FB_APP_ID']}%7C#{ENV['FB_APP_SECRET']}"
41
+ http_request = Net::HTTP::Post.new(uri.request_uri)
42
+ batch = clauses[:id].map do |id|
43
+ {"method":"GET", "relative_url": "/v2.6/#{id}?fields=id,permalink_url,created_time,description,title,from,comments.limit(0).summary(true),likes.limit(0).summary(true)"}
44
+ end
45
+ http_request.set_form_data batch: batch.to_json
46
+
47
+ net_http_options = [uri.host, uri.port, use_ssl: true]
48
+ response = Net::HTTP.start('graph.facebook.com', 443, use_ssl: true) do |http|
49
+ http.request http_request
50
+ end
51
+
52
+ JSON(response.body).map do |attributes|
53
+ uri = URI::HTTPS.build host: 'www.facebook.com', path: "/video.php", query: "v=#{JSON(attributes['body'])['id']}"
54
+ http_request = Net::HTTP::Get.new(uri.request_uri)
55
+
56
+ net_http_options = [uri.host, uri.port, use_ssl: true]
57
+ response = Net::HTTP.start('www.facebook.com', 443, use_ssl: true) do |http|
58
+ http.request http_request
59
+ end
60
+
61
+ view_count = %r{<div></div><span class="fcg">(?<views>.*) Views</span>}.match(response.body)[:views].tr(',','').to_i
62
+ new JSON(attributes['body']).merge(view_count: view_count)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Vid
2
+ VERSION = "0.1.0"
3
+ end
File without changes
@@ -0,0 +1,43 @@
1
+ require 'vid/base/video'
2
+
3
+ module Vid
4
+ module YouTube
5
+ class Video < Base::Video
6
+ def initialize(attributes = {})
7
+ @id = attributes['id']
8
+ @published_at = attributes['snippet']['publishedAt']
9
+ @title = attributes['snippet']['title']
10
+ @comment_count = attributes['statistics']['commentCount'].to_i
11
+ @like_count = attributes['statistics']['likeCount'].to_i
12
+ @view_count = attributes['statistics']['viewCount'].to_i
13
+ end
14
+
15
+ def self.find(id)
16
+ uri = URI::HTTPS.build host: 'www.googleapis.com', path: '/youtube/v3/videos', query: "id=#{id}&key=#{ENV['YT_TEST_SERVER_API_KEY']}&part=snippet,statistics"
17
+ http_request = Net::HTTP::Get.new(uri.request_uri)
18
+
19
+ net_http_options = [uri.host, uri.port, use_ssl: true]
20
+ response = Net::HTTP.start('www.googleapis.com', 443, use_ssl: true) do |http|
21
+ http.request http_request
22
+ end
23
+
24
+ attributes = JSON(response.body)['items'][0]
25
+ new attributes
26
+ end
27
+
28
+ def self.where(clauses)
29
+ uri = URI::HTTPS.build host: 'www.googleapis.com', path: '/youtube/v3/videos', query: "id=#{clauses[:id].join(',')}&key=#{ENV['YT_TEST_SERVER_API_KEY']}&part=snippet,statistics"
30
+ http_request = Net::HTTP::Get.new(uri.request_uri)
31
+
32
+ net_http_options = [uri.host, uri.port, use_ssl: true]
33
+ response = Net::HTTP.start('www.googleapis.com', 443, use_ssl: true) do |http|
34
+ http.request http_request
35
+ end
36
+
37
+ JSON(response.body)['items'].map do |attributes|
38
+ new attributes
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - claudiob
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.10
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.10
69
+ description: Write a longer description or delete this line.
70
+ email:
71
+ - claudiob@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - bin/vid
85
+ - diesis.gemspec
86
+ - lib/vid.rb
87
+ - lib/vid/base/video.rb
88
+ - lib/vid/facebook/api/graph.rb
89
+ - lib/vid/facebook/api/html.rb
90
+ - lib/vid/facebook/video.rb
91
+ - lib/vid/version.rb
92
+ - lib/vid/youtube/api/data.rb
93
+ - lib/vid/youtube/video.rb
94
+ homepage: http://example.com
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.6
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Write a short summary, because Rubygems requires one.
118
+ test_files: []