yourub 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 20e4cb1067ac55c1c94c06900c07b9a40eb761d4
4
+ data.tar.gz: c9134af7d345afe870536912299e8b5a98cf387e
5
+ SHA512:
6
+ metadata.gz: 1ed49f6fe09060771ae9cc528e034c7c9b1105570254f6b2a4c8d9a21e7907313993affb88d321c174095bd55aa438030e0c23702ca4247be5291a5866ba32c1
7
+ data.tar.gz: 1af8d251bae55e3bfe6c3c623324c66098ad9d03418595e7dfdb3be6db98ed5140def111280f250f7b87f1e9ea2e1ada09146700a124e9112da8004216e4077b
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ lib/yourub/DEVELOPER_KEY
13
+ lib/yourub/cli.rb
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yourub.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "debugger"
8
+ gem "pry"
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ [![Code Climate](https://codeclimate.com/github/edap/yourub.png)](https://codeclimate.com/github/edap/yourub)
2
+
3
+ # Yourub
4
+
5
+ Yourub is a gem that finds the most recent videos from the Youtube API for the given nation, category and number of views. It's updated to the version 3 of the youtube api
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'yourub'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install yourub
20
+
21
+ ## Usage
22
+
23
+ Get a developer key as explained [here](http://www.youtube.com/watch?v=Im69kzhpR3I)
24
+ If you are using rails, create a app/config/yourub.yml file as follow:
25
+
26
+ yourub:
27
+ developer_key: 'yourdeveloperkey'
28
+ youtube_api_service_name: 'youtube'
29
+ youtube_api_version: 'v3'
30
+ application_name: "nameofyourapp"
31
+ application_version: "version_number_of_your_app"
32
+ log_level: WARN
33
+
34
+ As default beahviour, the Yourub gem retrieve 2 videos for each category for the default country, USA.
35
+
36
+ result = Yourub::Search.new()
37
+ result.categories
38
+ result.videos
39
+
40
+
41
+ Actually, is possible to select videos for a given country specifying the nation parameter (equivalent to the regionCode on the native youtube API) The parameter value is an [ISO 3166-1](http://www.iso.org/iso/country_codes/iso_3166_code_lists/country_names_and_code_elements.htm) alpha-2 country code.
42
+
43
+ Yourub::Search.new(nation: "IT")
44
+
45
+
46
+ for a given category
47
+
48
+ Yourub::Search.new(category: "Sports")
49
+
50
+
51
+ to filter out videos depending on the number of views that they have
52
+
53
+ filter = {'views' => ">= 1000"}
54
+ Yourub::Search.new(filter: filter)
55
+
56
+
57
+ to set the max number of videos for each nation/category request (max 50, default 2)
58
+
59
+ result = Yourub::Search.new(max_results: 25)
60
+
61
+ Or all the options together
62
+
63
+ filter = {'views' => "<= 200"}
64
+ Yourub::Search.new(nation: "FR", category: "Comedy", max_results: 25, filter: filter)
65
+
66
+ ##TODO
67
+
68
+ 1. filter by search term
69
+ 2. move nation, category and max result in the filter options
70
+ 3. adding a CLI
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/yourub ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yourub/cli'
3
+ Yourub::CLI.start
data/config/yourub.yml ADDED
@@ -0,0 +1,7 @@
1
+ yourub:
2
+ developer_key: 'YoUrDevEl0PerKey'
3
+ youtube_api_service_name: 'youtube'
4
+ youtube_api_version: 'v3'
5
+ application_name: "yourub"
6
+ application_version: "0.1"
7
+ log_level: WARN
data/lib/yourub/cli.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'thor'
2
+
3
+ module Yourub
4
+ class CLI < Thor
5
+ desc 'hello NAME', 'Display greeting with given NAME'
6
+ def hello(name)
7
+ puts "Hello #{name}"
8
+ end
9
+
10
+ desc 'nations', 'display available nations in youtube standard feed'
11
+ def nations
12
+ Yourub::Search::NATION
13
+ end
14
+
15
+ desc 'feed_types', 'display available types in youtube standard feed'
16
+ def feed_types
17
+ Yourub.types
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'forwardable'
4
+
5
+ module Yourub
6
+ module Config
7
+
8
+ class << self
9
+ extend Forwardable
10
+ attr_accessor :config
11
+
12
+ def_delegators :@config, :developer_key,:youtube_api_service_name, :log_level,
13
+ :youtube_api_version, :application_name, :application_version
14
+
15
+ def load!(file_path, environment)
16
+ @config = OpenStruct.new YAML.load_file(file_path)[environment]
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,45 @@
1
+ module Yourub
2
+ module CountFilter
3
+ class << self
4
+
5
+ attr_accessor :filter
6
+
7
+ VIEWS_COUNT_NUMBER = /\d*\z/
8
+ ARITHMETIC_OPERATOR = /\A<(?!=)|>(?!=)|<=|>=|==|!=/
9
+
10
+ def accept?(entry, filter)
11
+ @filter = filter
12
+ return true if @filter.nil?
13
+ validate_filter
14
+ apply_filter(entry)
15
+ end
16
+
17
+ def validate_filter
18
+ unless @filter.is_a?(Hash)
19
+ raise ArgumentError.new("The filter #{@filter} should be an Hash")
20
+ end
21
+ validate_count_filter
22
+ end
23
+
24
+ def validate_count_filter
25
+ count_number_invalid = (@filter['views'] =~ VIEWS_COUNT_NUMBER).nil?
26
+ operator_invalid = (@filter['views'] =~ ARITHMETIC_OPERATOR).nil?
27
+ raise ArgumentError.new("arithmetic operator not detected") if operator_invalid
28
+ raise ArgumentError.new("view count number not detected") if count_number_invalid
29
+ end
30
+
31
+ def apply_filter(video)
32
+ operator = @filter['views'].match(ARITHMETIC_OPERATOR).to_s
33
+ number_to_compare = @filter['views'].match(VIEWS_COUNT_NUMBER).to_s.to_i
34
+ number_founded = get_views_count(video)
35
+ return number_founded.send(operator, number_to_compare)
36
+ end
37
+
38
+ def get_views_count video
39
+ return 0 if video['statistics'].nil?
40
+ return video['statistics']["viewCount"].to_i
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,6 @@
1
+ Yourub::Config.load!(File.join("config", "yourub.yml"), 'yourub')
2
+
3
+ logger = Logger.new(STDOUT)
4
+ logger.level = Logger.const_get(Yourub::Config.log_level.upcase)
5
+
6
+ Yourub.logger = logger
@@ -0,0 +1,5 @@
1
+ module Yourub
2
+ class << self
3
+ attr_accessor :logger
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module Rails
2
+ module Yourub
3
+ class Railtie < Rails::Railtie
4
+
5
+ config.yourub = ::Yourub::Config
6
+
7
+ initializer "yourub.load-config" do
8
+ config_file = Rails.root.join("config", "yourub.yml")
9
+ if config_file.file?
10
+ ::Yourub::Config.load!(config_file, Rails.env)
11
+ end
12
+ end
13
+
14
+ initializer 'yourub.use-rails-logger' do
15
+ ::Yourub.logger = Rails.logger
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,158 @@
1
+ module Yourub
2
+ class Search
3
+
4
+ attr_reader :videos, :nations, :categories
5
+ attr_accessor :config
6
+
7
+ def initialize(nation: "US", category: 'all', max_results: 2, filter: nil)
8
+ local_variables.each do |k|
9
+ v = eval(k.to_s)
10
+ instance_variable_set("@#{k}", v) unless v.nil?
11
+ end
12
+
13
+ valid?
14
+
15
+ @categories, @videos = [], []
16
+ @options = default_search_video_options
17
+
18
+ retrieve_categories
19
+ retrieve_videos
20
+ end
21
+
22
+ def config
23
+ Yourub::Config
24
+ end
25
+
26
+ NATIONS = [
27
+ 'AR','AU','AT','BE','BR','CA','CL','CO','CZ','EG','FR','DE','GB','HK',
28
+ 'HU','IN','IE','IL','IT','JP','JO','MY','MX','MA','NL','NZ','PE','PH',
29
+ 'PL','RU','SA','SG','ZA','KR','ES','SE','CH','TW','AE','US']
30
+
31
+ def valid?
32
+ validate_nation
33
+ validate_max_results
34
+ end
35
+
36
+ def validate_nation
37
+ raise ArgumentError.new('params not available') unless(
38
+ NATIONS.include?(@nation)
39
+ )
40
+ end
41
+
42
+ def validate_max_results
43
+ raise ArgumentError.new('max 50 videos pro categories or nation') unless(
44
+ @max_results.to_i < 50 || @max_results.to_i == 0
45
+ )
46
+ end
47
+
48
+ def client
49
+ @client ||= Google::APIClient.new(
50
+ :key => config.developer_key,
51
+ :application_name => config.application_name,
52
+ :application_version => config.application_version,
53
+ :authorization => nil,
54
+ )
55
+ end
56
+
57
+ def youtube
58
+ @youtube ||= client.discovered_api(config.youtube_api_service_name,
59
+ config.youtube_api_version)
60
+ end
61
+
62
+ def categories_request
63
+ categories_list = client.execute!(
64
+ :api_method => youtube.video_categories.list,
65
+ :parameters => {"part" => "snippet","regionCode" => @nation }
66
+ )
67
+ end
68
+
69
+ def retrieve_categories
70
+ retrieve_all_categories
71
+ if @category != 'all'
72
+ retrieve_only_one_category
73
+ end
74
+ end
75
+
76
+ def retrieve_all_categories
77
+ categories_request.data.items.each do |cat_result|
78
+ @categories.push(cat_result["id"] => cat_result["snippet"]["title"])
79
+ end
80
+ end
81
+
82
+ def retrieve_only_one_category
83
+ @categories = @categories.select {|k| k.has_value?(@category)}
84
+ if @categories.first.nil?
85
+ raise ArgumentError.new('The category #{@category} does not exists')
86
+ end
87
+ end
88
+
89
+ def default_search_video_options
90
+ opt = {
91
+ :maxResults => @max_results,
92
+ :regionCode => @nation,
93
+ :type => 'video',
94
+ :order => 'date',
95
+ :safeSearch => 'none',
96
+ :videoCategoryId => '10'
97
+ }
98
+ end
99
+
100
+ def retrieve_videos
101
+ #@nations.each do |nat|
102
+ @categories.each do |cat|
103
+ @options[:videoCategoryId] = cat.keys[0].to_i
104
+ #@options[:regionCode] = nat
105
+ @options[:part] = 'id'
106
+ read_response videos_list_request
107
+ end
108
+ #end
109
+ end
110
+
111
+ def read_response(video_list)
112
+ video_list.data.items.each do |video_item|
113
+ video_info_request video_item.id.videoId
114
+ end
115
+ end
116
+
117
+ def videos_list_request
118
+ search_response = client.execute!(
119
+ :api_method => youtube.search.list,
120
+ :parameters => @options
121
+ )
122
+ end
123
+
124
+ def video_info_request(result_video_id)
125
+ params = video_params(result_video_id)
126
+ video_response = client.execute!(
127
+ :api_method => youtube.videos.list,
128
+ :parameters => params
129
+ )
130
+ store_video(result_video_id, video_response)
131
+ end
132
+
133
+ def video_params(result_video_id)
134
+ fields = 'items(snippet(title,thumbnails),statistics(viewCount))'
135
+ parameters = {
136
+ :id => result_video_id,
137
+ :part => 'statistics,snippet',
138
+ :fields => URI::encode(fields)
139
+ }
140
+ end
141
+
142
+ def store_video(video_id, video_response)
143
+ begin
144
+ result = JSON.parse(video_response.data.to_json)
145
+ entry = result['items'].first
146
+ if Yourub::CountFilter.accept?(entry, @filter)
147
+ @videos.push({
148
+ 'title' => entry['snippet']['title'],
149
+ 'url' => 'https://www.youtube.com/watch?v='<< video_id
150
+ })
151
+ end
152
+ rescue StandardError => e
153
+ Yourub.logger.error "Error #{e} reading the video stream"
154
+ end
155
+ end
156
+
157
+ end
158
+ end
@@ -0,0 +1,3 @@
1
+ module Yourub
2
+ VERSION = "0.0.1"
3
+ end
data/lib/yourub.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'json'
2
+ require 'logger'
3
+ require 'net/https'
4
+ require 'open-uri'
5
+ require 'google/api_client'
6
+
7
+ require 'yourub/config'
8
+ require 'yourub/version'
9
+ require 'yourub/logger'
10
+ require 'yourub/count_filter'
11
+ require 'yourub/search'
12
+
13
+ if defined?(Rails)
14
+ require 'yourub/railtie'
15
+ else
16
+ require 'yourub/default'
17
+ end
18
+
@@ -0,0 +1,37 @@
1
+ require 'yourub'
2
+
3
+ describe Yourub::CountFilter do
4
+ let(:video) {
5
+ {"snippet" => {
6
+ "title" => "GoPro: Hiero Day",
7
+ "thumbnails" => {
8
+ "default"=>{"url"=>"https://i1.ytimg.com/vi/mN0Dbj-xHY0/default.jpg"},
9
+ "medium"=>{"url"=>"https://i1.ytimg.com/vi/mN0Dbj-xHY0/mqdefault.jpg"},
10
+ "high"=>{"url"=>"https://i1.ytimg.com/vi/mN0Dbj-xHY0/hqdefault.jpg"},
11
+ "standard"=>{"url"=>"https://i1.ytimg.com/vi/mN0Dbj-xHY0/sddefault.jpg"},
12
+ "maxres"=>{"url"=>"https://i1.ytimg.com/vi/mN0Dbj-xHY0/maxresdefault.jpg"}
13
+ }
14
+ },
15
+ "statistics"=>{"viewCount"=>"301"}
16
+ }
17
+ }
18
+
19
+ it "accept the video if satisfy the condition" do
20
+ count_filter = {'views' => ">= 100"}
21
+ res = Yourub::CountFilter.accept?(video, count_filter)
22
+ expect(res).to be_true
23
+ end
24
+
25
+ it "accept the video if filter is nil" do
26
+ count_filter = nil
27
+ res = Yourub::CountFilter.accept?(video, count_filter)
28
+ expect(res).to be_true
29
+ end
30
+
31
+ it "not accept the video if it does not satisfy the condition" do
32
+ count_filter = {'views' => "< 10"}
33
+ res = Yourub::CountFilter.accept?(video, count_filter)
34
+ expect(res).to be_false
35
+ end
36
+
37
+ end
@@ -0,0 +1,47 @@
1
+ require 'yourub'
2
+
3
+ describe Yourub::Search do
4
+
5
+ context "on initialize" do
6
+ it "retrieves all the available categories for the default country" do
7
+ result = Yourub::Search.new()
8
+ expect(result.categories).to be_a_kind_of(Array)
9
+ end
10
+
11
+ it "retrieves all the available categories for a given country" do
12
+ result = Yourub::Search.new(nation: "US")
13
+ expect(result.categories).to be_a_kind_of(Array)
14
+ end
15
+
16
+ it "return an error if the given country does not exists" do
17
+ expect{ Yourub::Search.new(nation: "MOON") }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it "return an error if the given category does not exists" do
21
+ expect{ Yourub::Search.new(nation: "US", category: "Puzzles") }.to raise_error
22
+ end
23
+
24
+ it "initialize the instance variabe @category with the given category" do
25
+ result = Yourub::Search.new(nation: "US", category: "Sports")
26
+ expect(result.categories.first.values).to include("Sports")
27
+ expect(result.categories.first.key("Sports").to_i).to be_a_kind_of(Integer)
28
+ end
29
+
30
+ it "retrieves 2 videos pro category if no max_results is specified" do
31
+ result = Yourub::Search.new(nation: "US", category: "Sports")
32
+ expect(result.videos.count).to eq(2)
33
+ end
34
+
35
+ it "retrieves 5 videos pro category max_results = 5" do
36
+ result = Yourub::Search.new(nation: "US", category: "Sports", max_results: 5)
37
+ expect(result.videos.count).to eq(5)
38
+ end
39
+
40
+ it "retrieves videos that have more than 100 views" do
41
+ filter = {'views' => ">= 100"}
42
+ result = Yourub::Search.new(nation: "US", category: "Sports", max_results: 5, filter: filter)
43
+ expect(result.videos).to be_a_kind_of(Array)
44
+ end
45
+ end
46
+
47
+ end
data/yourub.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yourub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yourub"
8
+ spec.version = Yourub::VERSION
9
+ spec.authors = ["Davide Prati"]
10
+ spec.email = ["lastexxit@gmail.com "]
11
+ spec.description = %q{Youtube API v3 parser}
12
+ spec.summary = %q{Yourub is a gem that fetch the most recent videos from
13
+ the Youtube API for the given nation, category and number
14
+ of views}
15
+ spec.homepage = ""
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "google-api-client"
26
+
27
+ spec.add_development_dependency "rspec", "~> 2.14"
28
+ spec.add_dependency "thor" , '~> 0.18'
29
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "path": "lib/yourub"
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,338 @@
1
+ {
2
+ "auto_complete":
3
+ {
4
+ "selected_items":
5
+ [
6
+ [
7
+ "https",
8
+ "https"
9
+ ],
10
+ [
11
+ "be",
12
+ "be_true"
13
+ ],
14
+ [
15
+ "is",
16
+ "is_alive"
17
+ ],
18
+ [
19
+ "ra",
20
+ "raise_error"
21
+ ],
22
+ [
23
+ "res",
24
+ "rescue"
25
+ ],
26
+ [
27
+ "Ar",
28
+ "ArgumentError"
29
+ ],
30
+ [
31
+ "sel",
32
+ "self"
33
+ ],
34
+ [
35
+ "N",
36
+ "NATIONS"
37
+ ]
38
+ ]
39
+ },
40
+ "buffers":
41
+ [
42
+ {
43
+ "contents": "module Yourub\n class Page\n include Logging\n\n attr_accessor :url\n\n def initialize(nation = \"US\", category = \"Sports\", type = \"most_recent\")\n @nation = nation\n @category = category\n @type = type\n @api_url = \"https://gdata.youtube.com/feeds/api/standardfeeds/\"\n @json = \"?v=2&alt=json&prettyprint=true\"\n @required_fields = \"(title,media:group(media:player(@url)))\"\n @url = set_url\n end\n\n NATIONS = [\n 'AR','AU','AT','BE','BR','CA','CL','CO','CZ','EG','FR','DE','GB','HK',\n 'HU','IN','IE','IL','IT','JP','JO','MY','MX','MA','NL','NZ','PE','PH',\n 'PL','RU','SA','SG','ZA','KR','ES','SE','CH','TW','AE','US']\n\n CATEGORIES = [\n 'Comedy', 'People', 'Entertainment', 'Music', 'Howto',\n 'Sports', 'Autos', 'Education', 'Film', 'News', 'Animals',\n 'Tech', 'Travel','Games', 'Shortmov']\n\n TYPES = [ \n 'top_rated', 'top_favorites', 'most_viewed', 'most_popular',\n 'most_recent', 'most_discussed', 'most_linked', 'most_responded',\n 'recently_featured', 'watch_on_mobile'] \n\n def valid?\n raise ArgumentError.new('params not available') unless(\n NATIONS.include?(@nation) && \n CATEGORIES.include?(@category) && \n TYPES.include?(@type)\n )\n true\n end\n\n def is_alive?\n begin\n Net::HTTP.start(@url.host, @url.port,\n :use_ssl => @url.scheme == 'https') do |https|\n request = Net::HTTP::Get.new @url\n response = https.request request\n if response.code == \"200\"\n return true\n else\n logger.error \"page #{@url} return code #{res.code}\"\n return false\n end\n end\n rescue StandardError => e\n return false\n logger.error \"Error #{e} trying to connect to the given url #{@url}\" \n end\n end\n\n def set_url\n url = \"#{@api_url}#{@nation}/#{@type}_#{@category}#{@json}#{@required_fields}\"\n @url = URI.parse(url)\n return @url if (valid? && is_alive?)\n\n # begin\n # valid?\n # is_alive?\n # puts @url\n # return @url\n # rescue ArgumentError => e\n # return false\n # logger.error \"#{e}\"\n # end\n end\n\n # TODO\n\n # Va capito bene cosa e' un modulo e come si usa in una classe composta da diversi files\n # http://stackoverflow.com/questions/151505/difference-between-a-class-and-a-module\n\n # Gemme, due modi per organizzarle, il primo\n # nel file lib/gemma.rb vengono inclusi tutti i sotto files.\n # Ogninu di questi comincica con \n # module NomeGemma e puo' includere classi o vattelapesca\n # un esempio e' tire\n # https://github.com/karmi/tire/blob/master/lib/tire.rb\n # e rake\n # https://github.com/jimweirich/rake/blob/master/lib/rake.rb\n\n # oppure nel file lib/gemma.rb\n # come in thor\n # https://github.com/erikhuda/thor/blob/master/lib/thor.rb\n # crei una classe col nome della gemma\n\n # esempio piu' chiaro e' faraday\n # https://github.com/lostisland/faraday/blob/master/lib/faraday.rb'\n \n # integrare un logger\n # tire ha un logger https://github.com/karmi/tire/blob/master/lib/tire/logger.rb\n # aggiungere diversi tipi di exception, far si che queste possano dialogre con la classe Logger\n # unire i due metodi di sopra\n # fare un test ciclando due url\n # aggiungere le Exception, facendo si che il ciclo passi alla seconda ulr se la prima non passa\n\n # pushare su github\n\n\n end\nend",
44
+ "file": "lib/yourub/page.rb",
45
+ "file_size": 3554,
46
+ "file_write_time": 1378764534000000,
47
+ "settings":
48
+ {
49
+ "buffer_size": 3553,
50
+ "line_ending": "Unix"
51
+ }
52
+ }
53
+ ],
54
+ "build_system": "Packages/Ruby/Ruby.sublime-build",
55
+ "command_palette":
56
+ {
57
+ "height": 364.0,
58
+ "selected_items":
59
+ [
60
+ [
61
+ "Pac",
62
+ "Package Control: Install Package"
63
+ ],
64
+ [
65
+ "pack",
66
+ "Package Control: Install Package"
67
+ ]
68
+ ],
69
+ "width": 593.0
70
+ },
71
+ "console":
72
+ {
73
+ "height": 208.0
74
+ },
75
+ "distraction_free":
76
+ {
77
+ "menu_visible": true,
78
+ "show_minimap": false,
79
+ "show_open_files": false,
80
+ "show_tabs": false,
81
+ "side_bar_visible": false,
82
+ "status_bar_visible": false
83
+ },
84
+ "file_history":
85
+ [
86
+ "/home/da/iocose/Gemfile",
87
+ "/home/da/iocose/app/assets/stylesheets/application.css.scss",
88
+ "/home/da/iocose/config/environments/development.rb",
89
+ "/home/da/iocose/config/routes.rb",
90
+ "/home/da/iocose/app/views/layouts/_admin_navigation.html.haml",
91
+ "/home/da/iocose/app/views/layouts/admin.html.haml",
92
+ "/home/da/iocose/config/database.yml",
93
+ "/home/da/iocose/config/application.yml",
94
+ "/home/da/iocose/config/application.rb",
95
+ "/home/da/iocose/db/schema.rb",
96
+ "/home/da/codebeispiel/WeightedQuickUnionUF.rb",
97
+ "/home/da/codebeispiel/README.txt",
98
+ "/home/da/codebeispiel/mediumUF.txt",
99
+ "/home/da/yourub/lib/yourub.rb",
100
+ "/home/da/yourub/lib/yourub/logging.rb",
101
+ "/home/da/yourub/lib/yourub/page.rb",
102
+ "/home/da/yourub/lib/yourub/parser.rb",
103
+ "/home/da/yourub/spec/page_spec.rb",
104
+ "/home/da/yourub/spec/yourub_spec.rb",
105
+ "/home/da/public_html/cake/app/webroot/websites/aca/theories.php",
106
+ "/home/da/ruby/poignant/module_ex/logging.rb",
107
+ "/home/da/ruby/poignant/module_ex/use_logger.rb",
108
+ "/home/da/yourub/lib/yourub/logger.rb",
109
+ "/home/da/ruby/module_use_me.rb",
110
+ "/home/da/ruby/modulo_serre_prati.rb",
111
+ "/home/da/ruby/watchful_saint_agnes.rb",
112
+ "/home/da/yourub/lib/yourub/connect.rb",
113
+ "/home/da/yourub/lib/yourub/watchful_saint_agnes.rb",
114
+ "/home/da/ruby/fibonacci.rb",
115
+ "/home/da/ruby/test.rb",
116
+ "/home/da/yourub/lib/yourub/old.rb",
117
+ "/home/da/Desktop/todo",
118
+ "/home/da/.config/sublime-text-2/Packages/Default/Preferences.sublime-settings",
119
+ "/home/da/public_html/unique/app/assets/javascripts/application.js",
120
+ "/home/da/public_html/unique/app/views/pages/_archiv.html.erb",
121
+ "/home/da/public_html/unique/app/views/shared/_thumbs.html.erb",
122
+ "/home/da/public_html/unique/app/assets/javascripts/unique.js",
123
+ "/home/da/public_html/unique/app/views/pages/_weare.html.erb",
124
+ "/home/da/public_html/unique/app/views/uber-uns.html",
125
+ "/home/da/yourub/spec/parser_spec.rb",
126
+ "/home/da/yourub/spec/connect_spec.rb",
127
+ "/home/da/yourub/features/parser.feature",
128
+ "/home/da/yourub/lib/yourub/cli.rb",
129
+ "/home/da/yourub/bin/yourub",
130
+ "/home/da/yourub/yourub.gemspec",
131
+ "/home/da/.config/sublime-text-2/Packages/Default/Default (Linux).sublime-keymap",
132
+ "/home/da/.config/sublime-text-2/Packages/User/Preferences.sublime-settings",
133
+ "/home/da/yourub/features/support/setup.rb",
134
+ "/home/da/yourub/Gemfile",
135
+ "/media/kurt_ext2/backup/da/ruby/code_basic/variables.rb",
136
+ "/media/kurt_ext2/backup/da/ruby/everyday_scripting/code/affinity-trip/affinity-trip.rb",
137
+ "/media/kurt_ext2/backup/da/ruby/google.rb",
138
+ "/media/kurt_ext2/backup/da/ruby/code_basic/array.rb",
139
+ "/home/da/public_html/unique/app/assets/stylesheets/user/base.css.scss",
140
+ "/home/da/public_html/cake/app/views/pages/home_random.ctp",
141
+ "/home/da/public_html/cake/app/config/routes.php",
142
+ "/home/da/public_html/unique/config/application.rb",
143
+ "/home/da/public_html/unique/config/environments/production.rb",
144
+ "/home/da/public_html/unique/app/views/pages/show.html.erb",
145
+ "/home/da/public_html/unique/app/views/pages/_googlemap.html.erb",
146
+ "/home/da/public_html/unique/app/views/pages/_kontakt.html.erb",
147
+ "/home/da/public_html/unique/app/views/pages/_kataloge.html.erb",
148
+ "/home/da/public_html/unique/app/assets/stylesheets/uberuns.css",
149
+ "/home/da/public_html/unique/config/database.yml",
150
+ "/home/da/public_html/unique/db/seeds.rb",
151
+ "/home/da/public_html/unique/config/environment.rb",
152
+ "/home/da/public_html/unique/config/routes.rb",
153
+ "/home/da/public_html/unique/config/boot.rb",
154
+ "/home/da/public_html/unique/app/controllers/application_controller.rb",
155
+ "/home/da/public_html/unique/config.ru",
156
+ "/home/da/public_html/unique/app/models/item.rb",
157
+ "/home/da/public_html/unique/app/models/image.rb",
158
+ "/home/da/public_html/unique/app/models/gallery.rb"
159
+ ],
160
+ "find":
161
+ {
162
+ "height": 34.0
163
+ },
164
+ "find_in_files":
165
+ {
166
+ "height": 0.0,
167
+ "where_history":
168
+ [
169
+ "/home/da/Downloads/tire-master",
170
+ "/home/da/public_html/unique"
171
+ ]
172
+ },
173
+ "find_state":
174
+ {
175
+ "case_sensitive": false,
176
+ "find_history":
177
+ [
178
+ "betterman94",
179
+ "dapx",
180
+ "kundali",
181
+ "pizza hut is",
182
+ "to communicate with us",
183
+ "Playsta",
184
+ "Secretly",
185
+ "Playstation hac",
186
+ "to control",
187
+ "ericsson is ",
188
+ "<sup",
189
+ "<sup>",
190
+ "<sup></sup>",
191
+ "<sup>",
192
+ "<sup></sup>",
193
+ "<sup>",
194
+ "Jinn",
195
+ "120",
196
+ "Jinn",
197
+ "($",
198
+ "</iframe>\"",
199
+ "\\\"></",
200
+ "\"audio\" =>",
201
+ "\"audio\" => ",
202
+ "Logger",
203
+ "@format",
204
+ "@type",
205
+ "User",
206
+ "end",
207
+ "@most_recent",
208
+ "ET",
209
+ "select",
210
+ "ctrl+alt",
211
+ "foodie",
212
+ "background",
213
+ "cboxLoadedContent",
214
+ "inline_content",
215
+ "order",
216
+ "by_join_position"
217
+ ],
218
+ "highlight": true,
219
+ "in_selection": false,
220
+ "preserve_case": false,
221
+ "regex": false,
222
+ "replace_history":
223
+ [
224
+ "1994immortality",
225
+ "postgres",
226
+ "",
227
+ "\"audio\" => \"<iframe width=\\\"100%\\\" height=\\\"166\\\" scrolling=\\\"no\\\" frameborder=\\\"no\\\" src=\\\"https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F104440492\\\"></iframe>\"",
228
+ "yourub"
229
+ ],
230
+ "reverse": false,
231
+ "show_context": true,
232
+ "use_buffer2": true,
233
+ "whole_word": false,
234
+ "wrap": true
235
+ },
236
+ "groups":
237
+ [
238
+ {
239
+ "sheets":
240
+ [
241
+ {
242
+ "buffer": 0,
243
+ "file": "lib/yourub/page.rb",
244
+ "settings":
245
+ {
246
+ "buffer_size": 3553,
247
+ "regions":
248
+ {
249
+ },
250
+ "selection":
251
+ [
252
+ [
253
+ 725,
254
+ 512
255
+ ]
256
+ ],
257
+ "settings":
258
+ {
259
+ "syntax": "Packages/Ruby/Ruby.tmLanguage",
260
+ "tab_size": 2,
261
+ "translate_tabs_to_spaces": true
262
+ },
263
+ "translation.x": 0.0,
264
+ "translation.y": 675.0,
265
+ "zoom_level": 1.0
266
+ },
267
+ "type": "text"
268
+ }
269
+ ]
270
+ }
271
+ ],
272
+ "incremental_find":
273
+ {
274
+ "height": 0.0
275
+ },
276
+ "input":
277
+ {
278
+ "height": 31.0
279
+ },
280
+ "layout":
281
+ {
282
+ "cells":
283
+ [
284
+ [
285
+ 0,
286
+ 0,
287
+ 1,
288
+ 1
289
+ ]
290
+ ],
291
+ "cols":
292
+ [
293
+ 0.0,
294
+ 1.0
295
+ ],
296
+ "rows":
297
+ [
298
+ 0.0,
299
+ 1.0
300
+ ]
301
+ },
302
+ "menu_visible": true,
303
+ "output.exec":
304
+ {
305
+ "height": 228.0
306
+ },
307
+ "replace":
308
+ {
309
+ "height": 62.0
310
+ },
311
+ "save_all_on_build": true,
312
+ "select_file":
313
+ {
314
+ "height": 0.0,
315
+ "selected_items":
316
+ [
317
+ ],
318
+ "width": 0.0
319
+ },
320
+ "select_project":
321
+ {
322
+ "height": 500.0,
323
+ "selected_items":
324
+ [
325
+ [
326
+ "",
327
+ "/home/da/yourub/yourub.sublime-project"
328
+ ]
329
+ ],
330
+ "width": 380.0
331
+ },
332
+ "show_minimap": true,
333
+ "show_open_files": false,
334
+ "show_tabs": true,
335
+ "side_bar_visible": true,
336
+ "side_bar_width": 249.0,
337
+ "status_bar_visible": true
338
+ }
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yourub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Davide Prati
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-20 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: google-api-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.18'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.18'
83
+ description: Youtube API v3 parser
84
+ email:
85
+ - 'lastexxit@gmail.com '
86
+ executables:
87
+ - yourub
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/yourub
97
+ - config/yourub.yml
98
+ - lib/yourub.rb
99
+ - lib/yourub/cli.rb
100
+ - lib/yourub/config.rb
101
+ - lib/yourub/count_filter.rb
102
+ - lib/yourub/default.rb
103
+ - lib/yourub/logger.rb
104
+ - lib/yourub/railtie.rb
105
+ - lib/yourub/search.rb
106
+ - lib/yourub/version.rb
107
+ - spec/count_filter_spec.rb
108
+ - spec/search_spec.rb
109
+ - yourub.gemspec
110
+ - yourub.sublime-project
111
+ - yourub.sublime-workspace
112
+ homepage: ''
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.0.3
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Yourub is a gem that fetch the most recent videos from the Youtube API for
136
+ the given nation, category and number of views
137
+ test_files:
138
+ - spec/count_filter_spec.rb
139
+ - spec/search_spec.rb