syfyfancam 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b3401c8d59e3c07b98bf20efc736934a519558e
4
+ data.tar.gz: 3e53a63af942a8292da76f8d267abe5ff9cf2740
5
+ SHA512:
6
+ metadata.gz: 4d87a3d0f5d66ab5576b948daf79bed46cc91ed1de889ee77ca2ca55b676e3ba10399ef54b003da97794f2625c4ce739355c5f0f04ebfa7142d542935938c3f5
7
+ data.tar.gz: 5f35637957ad7b709d04315406e55d100d5e67ed6784d10deee294f509372393622368dc86e619f37144969800bab27092d735ada01a0df38b2bddeb08a247ee
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jonathan Hernández
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Syfyfancam
2
+
3
+ [![Build Status](https://travis-ci.org/jbilbo/syfyfancam.svg?branch=master)](https://travis-ci.org/jbilbo/syfyfancam) [![Code Climate](https://codeclimate.com/github/jbilbo/syfyfancam/badges/gpa.svg)](https://codeclimate.com/github/jbilbo/syfyfancam) [![Test Coverage](https://codeclimate.com/github/jbilbo/syfyfancam/badges/coverage.svg)](https://codeclimate.com/github/jbilbo/syfyfancam/coverage)
4
+
5
+ Ruby library to obtain the list of images associated to an online Syfyfancam video. See: http://www.syfyfancam.com/view-all-fancam-videos/
6
+
7
+ ## Installation
8
+
9
+ ### Command line
10
+
11
+ ```
12
+ $ gem install syfyfancam
13
+ ```
14
+
15
+ ### Gemfile
16
+
17
+ Add:
18
+ ```ruby
19
+ gem 'syfyfancam', '~> 0.1'
20
+ ```
21
+
22
+ and then execute:
23
+ ```
24
+ $ bundle
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ require 'syfyfancam'
31
+
32
+ syfyfancam = Syfyfancam::URL.new('http://www.syfyfancam.com/videos/ojt1nd5bnbog/')
33
+ syfyfancam.images
34
+ # => ["http://d1fmy74dfqc2hp.cloudfront.net/resources/footage/vE/oJt1Nd5BnboG/001.jpg", "http://d1fmy74dfqc2hp.cloudfront.net/resources/footage/vE/oJt1Nd5BnboG/002.jpg", ... , ]
35
+ syfyfancam.personal_hash
36
+ # => "ojt1nd5bnbog"
37
+ ```
38
+
39
+ ## License
40
+
41
+ Copyright © 2015 Jonathan Hernández
42
+
43
+ Distributed under the MIT License.
@@ -0,0 +1,38 @@
1
+ require 'nokogiri'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module Syfyfancam
6
+ class URL
7
+ attr_reader :uri
8
+
9
+ def initialize(url)
10
+ @uri = URI.parse(url)
11
+ fail ArgumentError, ERROR_URL unless personal_hash?
12
+ rescue URI::InvalidURIError => e
13
+ raise e, ERROR_URL
14
+ end
15
+
16
+ def images
17
+ build_urls.map { |url| URI.parse(url).to_s }
18
+ end
19
+
20
+ def personal_hash
21
+ uri.to_s.split('/').last
22
+ end
23
+
24
+ private
25
+
26
+ def personal_hash?
27
+ personal_hash && personal_hash.size == 12
28
+ end
29
+
30
+ def build_urls
31
+ (1..100).map { |i| "#{base_url}#{format('%03d', i)}.jpg" }
32
+ end
33
+
34
+ def base_url
35
+ @base_url ||= Nokogiri::HTML(Net::HTTP.get(uri)).at('meta[property="og:image"]')['content'][0..-8]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Syfyfancam
2
+ VERSION = '0.1.0'
3
+ end
data/lib/syfyfancam.rb ADDED
@@ -0,0 +1,8 @@
1
+ require_relative 'syfyfancam/url'
2
+
3
+ module Syfyfancam
4
+ ERROR_URL = <<-MSG
5
+ The URL is not recognised as a valid Syfyfancam URL.
6
+ A valid example is: http://www.syfyfancam.com/videos/ojt1nd5bnbog/
7
+ MSG
8
+ end
@@ -0,0 +1,23 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require_relative '../lib/syfyfancam'
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run :focus
8
+ config.run_all_when_everything_filtered = true
9
+ config.disable_monkey_patching!
10
+ config.warnings = true
11
+ config.order = :random
12
+ Kernel.srand config.seed
13
+
14
+ config.default_formatter = 'doc' if config.files_to_run.one?
15
+
16
+ config.expect_with :rspec do |expectations|
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ config.mock_with :rspec do |mocks|
21
+ mocks.verify_partial_doubles = true
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ require_relative '../../lib/syfyfancam/url'
2
+
3
+ RSpec.describe Syfyfancam::URL do
4
+ context 'valid URL' do
5
+ let(:url) { 'http://www.syfyfancam.com/videos/ojt1nd5bnbog/' }
6
+ let(:html) do
7
+ <<-EOS
8
+ <html><head><title></title>
9
+ <meta property="og:image" content="http://d1fmy74dfqc2hp.cf.net/resources/footage/vE/oJt1Nd5BnboG/024.jpg" />
10
+ </head><body></body></html>
11
+ EOS
12
+ end
13
+
14
+ subject(:syfyfancam) { described_class.new(url) }
15
+
16
+ before do
17
+ allow(Net::HTTP).to receive(:get).with(URI.parse(url)).and_return(html)
18
+ end
19
+
20
+ describe '#images' do
21
+ it 'returns an array of 100 URLs' do
22
+ allow(syfyfancam).to receive(:base_url).and_return('http://a.com/')
23
+
24
+ images = syfyfancam.images
25
+
26
+ expect(images.size).to eq(100)
27
+ expect(images[0]).to eq('http://a.com/001.jpg')
28
+ expect(images[1]).to eq('http://a.com/002.jpg')
29
+ expect(images[35]).to eq('http://a.com/036.jpg')
30
+ expect(images[99]).to eq('http://a.com/100.jpg')
31
+ end
32
+ end
33
+
34
+ describe '#personal_hash' do
35
+ it 'return the hash in the URL' do
36
+ expect(syfyfancam.personal_hash).to eq('ojt1nd5bnbog')
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'Wrong URL' do
42
+ let(:url) { 'http://www.nintendo.co.jp/' }
43
+
44
+ describe '#initialize' do
45
+ it 'fails to create an instance' do
46
+ expect { described_class.new(url) }.to raise_error(ArgumentError, Syfyfancam::ERROR_URL)
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'Not valid URL' do
52
+ let(:url) { '|cat /etc/passwd' }
53
+
54
+ describe '#initialize' do
55
+ it 'fails to create an instance' do
56
+ expect { described_class.new(url) }.to raise_error(URI::InvalidURIError, Syfyfancam::ERROR_URL)
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syfyfancam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Hernández
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.3'
41
+ description: |2
42
+ Videos from syfyfancam.com are composed by a bunch of individual images,
43
+ this library gives you an API to return the link to the images given the
44
+ URL of the video.
45
+ email: jbilbo@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - LICENSE
51
+ - README.md
52
+ - lib/syfyfancam.rb
53
+ - lib/syfyfancam/url.rb
54
+ - lib/syfyfancam/version.rb
55
+ - spec/spec_helper.rb
56
+ - spec/syfyfancam/url_spec.rb
57
+ homepage: https://github.com/jbilbo/syfyfancam
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Library to access syfyfancam.com videos
81
+ test_files:
82
+ - spec/spec_helper.rb
83
+ - spec/syfyfancam/url_spec.rb