YTStreamingAPI 0.0.1

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
+ SHA256:
3
+ metadata.gz: 7e38302225baf39cf86257b74c2d83ff98d2ab1f32932de6ebab1266aac46aec
4
+ data.tar.gz: 4125354114df21013516d06a8f8af65ddd085a9d08454e50f327af67f31fd1f0
5
+ SHA512:
6
+ metadata.gz: f03a39c994c3f49d480bb70a333d916736aa18a5850e7b5b183526d1936fe4cc7dc0765d85b19f0eae4fd9c45de0df264fecc2f12500bbee2a6a34f84561e478
7
+ data.tar.gz: 522c5ff45dc9ec01cc8d5ea83140bab7e569f2c92d82708b604a802883a47a91139e01691edb4ed1c43aa878831b80c27b91b15daa2507b1ccd04262bec29a5f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at simoncorreaocampo@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in frm_mercury.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Simon C
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.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # FrmMercury
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/frm_mercury`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'frm_mercury'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install frm_mercury
22
+
23
+ ## Usage
24
+
25
+ First create an frm_mercury.rb in yours config/initializers
26
+
27
+ ```ruby
28
+ require 'frm_mercury'
29
+ FrmMercury.configure do |config|
30
+ config.api_key = "Your Api Key From Firebase console"
31
+ end
32
+ ```
33
+
34
+ Then to send a message...
35
+ ```ruby
36
+ FrmMercury::Sender.send("Device FCM token as String or many tokens as Array", "Some title", "Some body message", "sound.mp3 (Leave empty for default)", "Hash in case you want to send extra info (optional)")
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/frm_mercury. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
52
+
53
+ ## Code of Conduct
54
+
55
+ Everyone interacting in the FrmMercury project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/frm_mercury/blob/master/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yt_streaming_api"
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(__FILE__)
data/bin/setup ADDED
@@ -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
@@ -0,0 +1,8 @@
1
+ require "yt_streaming_api/r_api"
2
+ require "yt_streaming_api/r_api/request"
3
+ require "yt_streaming_api/r_api/broadcast"
4
+ require "yt_streaming_api/r_api/messages"
5
+
6
+ module YtStreamingApi
7
+
8
+ end
@@ -0,0 +1,21 @@
1
+ module YtStreamingApi
2
+ module RApi
3
+ class << self
4
+ require "base64"
5
+ # NOTA: definir si dejar estos campos como accessors
6
+ attr_accessor :api_key, :client_id, :client_secret, :redirect_uri, :response_type, :scope, :access_type
7
+ attr_reader
8
+
9
+ # recibe un bloque inicializador de variables de configuración de payu como la
10
+ # api_key, api_login
11
+ def configure(&block)
12
+ block.call(self)
13
+ end
14
+
15
+ # genera el codigo de autenticación que será enviado en los header de todas las peticiones a la api
16
+ def authorization
17
+ @authorization ||= "Bearer "
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module YtStreamingApi
2
+ module RApi
3
+ class Broadcast < Request
4
+
5
+ def list(part="snippet", status="active", type="all")
6
+ @http_verb = 'Get'
7
+ @url = "https://www.googleapis.com/youtube/v3/liveBroadcasts"
8
+ @headers = {"Content-Type" => "application/json", "Authorization" => "#{RApi.authorization}#{@user.youtube_access_token}"}
9
+ @params = "?part=#{part}&broadcastStatus=#{status}&broadcastType=#{type}&key=#{RApi.api_key}"
10
+
11
+ http
12
+ @response
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,81 @@
1
+ module YtStreamingApi
2
+ module RApi
3
+ class Login < Request
4
+
5
+ def url
6
+ "https://accounts.google.com/o/oauth2/auth?client_id=#{RApi.client_id}&redirect_uri=#{RApi.redirect_uri}&scope=#{RApi.scope}&response_type=#{RApi.response_type}&access_type=#{RApi.access_type}"
7
+ end
8
+
9
+ def is_valid_response(params)
10
+ unless params[:code].blank?
11
+ true
12
+ else
13
+ false
14
+ end
15
+ end
16
+
17
+ def process_response_params(params)
18
+ unless params[:code].blank?
19
+ @user.youtube_authorization_token = params[:code]
20
+ return params[:code]
21
+ end
22
+ end
23
+
24
+ def get_tokens
25
+ if @user.nil?
26
+ return nil
27
+ end
28
+ if @user.youtube_authorization_token.nil?
29
+ return nil
30
+ end
31
+
32
+ @http_verb = 'Post'
33
+ @url = "https://accounts.google.com/o/oauth2/token"
34
+ @headers = {"Content-Type" => "application/x-www-form-urlencoded"}
35
+
36
+ @params = {
37
+ code: @user.youtube_authorization_token,
38
+ client_id: RApi.client_id,
39
+ client_secret: RApi.client_secret,
40
+ redirect_uri: RApi.redirect_uri,
41
+ grant_type: "authorization_code"
42
+ }
43
+
44
+ http
45
+ puts "===>#{@response}"
46
+ process_tokens(@response)
47
+ end
48
+
49
+ def refresh_tokens
50
+ if @user.nil?
51
+ return nil
52
+ end
53
+ if @user.youtube_reset_token.nil?
54
+ return nil
55
+ end
56
+
57
+ @http_verb = 'Post'
58
+ @url = "https://accounts.google.com/o/oauth2/token"
59
+ @headers = {"Content-Type" => "application/x-www-form-urlencoded"}
60
+
61
+ @params = {
62
+ refresh_token: @user.youtube_reset_token,
63
+ client_id: RApi.client_id,
64
+ client_secret: RApi.client_secret,
65
+ grant_type: "refresh_token"
66
+ }
67
+
68
+ http
69
+ puts "===>#{@response}"
70
+ process_tokens(@response)
71
+ end
72
+
73
+ def process_tokens(res)
74
+ @user.youtube_access_token = res["access_token"] unless res["access_token"].blank?
75
+ @user.youtube_reset_token = res["refresh_token"] unless res["refresh_token"].blank?
76
+ {access_token: res["access_token"], refresh_token: res["refresh_token"]}
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module YtStreamingApi
3
+ module RApi
4
+ class Message < Request
5
+
6
+ def list(part="snippet", max_results=2000, chat_id=nil)
7
+ return nil if chat_id.nil?
8
+
9
+ @http_verb = 'Get'
10
+ @url = "https://www.googleapis.com/youtube/v3/liveBroadcasts"
11
+ @headers = {"Content-Type" => "application/json", "Authorization" => "#{RApi.authorization}#{@user.youtube_access_token}"}
12
+ @params = "?liveChatId=#{chat_id}&part=#{part}&maxResults=#{max_results}&key=#{RApi.api_key}"
13
+
14
+ http
15
+ @response
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,72 @@
1
+ module YtStreamingApi
2
+ module RApi
3
+ class Request
4
+
5
+ require 'uri'
6
+ require 'net/https'
7
+ require 'json'
8
+
9
+ attr_accessor :url, :_url, :params, :user, :headers
10
+
11
+ attr_reader :response, :http_verb, :error
12
+
13
+ def initialize(user=nil)
14
+ @user = user
15
+ end
16
+
17
+ def success?
18
+ @error.nil? && !@response.nil?
19
+ end
20
+
21
+ def fail?
22
+ !@error.nil?
23
+ end
24
+
25
+ private
26
+
27
+ def url
28
+ @url ||= _url
29
+ end
30
+
31
+ def reset_url
32
+ @url = url
33
+ end
34
+
35
+ def http
36
+ if http_verb == "Get"
37
+ @url = "#{@url}#{@params}"
38
+ end
39
+
40
+ uri = URI.parse(@url)
41
+
42
+ if @headers["Content-Type"] == "application/x-www-form-urlencoded"
43
+ uri.query = URI.encode_www_form(@params)
44
+ end
45
+
46
+ puts "#{http_verb} #{@url}"
47
+ https = Net::HTTP.new(uri.host,uri.port)
48
+
49
+ https.use_ssl = true
50
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
51
+
52
+ net_class = Object.const_get("Net::HTTP::#{http_verb}")
53
+ request = net_class.new(uri, initheader = @headers)
54
+
55
+ # request['Authorization'] = RApi.authorization
56
+
57
+ unless @headers["Content-Type"] == "application/x-www-form-urlencoded"
58
+ if http_verb != "Get"
59
+ request.body = @params.to_json
60
+ end
61
+ end
62
+
63
+ request = https.request(request)
64
+ # llena @response ó @error
65
+ puts "BODY =====> #{request.body}"
66
+
67
+ @response = JSON.parse(request.body)
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module YtStreamingApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "yt_streaming_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "YTStreamingAPI"
7
+ spec.version = YtStreamingApi::VERSION
8
+ spec.authors = ["MakarovCode"]
9
+ spec.email = ["simoncorreaocampo@gmail.com"]
10
+
11
+ spec.summary = "Gem to use the YouTube Streaming API simple"
12
+ spec.description = "Ruby gem to use the YouTube Streaming API simple"
13
+ spec.homepage = "https://github.com/MakarovCode/YTStreamingAPI"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: YTStreamingAPI
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - MakarovCode
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-06 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Ruby gem to use the YouTube Streaming API simple
28
+ email:
29
+ - simoncorreaocampo@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CODE_OF_CONDUCT.md
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - bin/console
40
+ - bin/setup
41
+ - lib/yt_streaming_api.rb
42
+ - lib/yt_streaming_api/r_api.rb
43
+ - lib/yt_streaming_api/r_api/broadcast.rb
44
+ - lib/yt_streaming_api/r_api/login.rb
45
+ - lib/yt_streaming_api/r_api/messages.rb
46
+ - lib/yt_streaming_api/r_api/request.rb
47
+ - lib/yt_streaming_api/version.rb
48
+ - yt_streaming_api.gemspec
49
+ homepage: https://github.com/MakarovCode/YTStreamingAPI
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.1.2
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Gem to use the YouTube Streaming API simple
72
+ test_files: []