twitter_embed 0.1.0

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
+ SHA256:
3
+ metadata.gz: 5f082d74b170be29b89b96d1ef1a31d6bf6ad6a686c8b5c949163b749c72653b
4
+ data.tar.gz: f33e2cc4ae11a657feaa98c2fc79a3cc8991023e824258876d6cca6492638bb1
5
+ SHA512:
6
+ metadata.gz: 98772dd18bb727391b420ef093d67c9339d1d066318dade376a0c2bec014a3ada4745d0d4f6ef141d3b4870e010ddeac74925ae0a54c4c3970dd214fe1e68424
7
+ data.tar.gz: a9dd08eda9a5d85b538dd40673df9ce02b73471214143d2a7b12e7786065f8f126aef5583bb04e352f34916357de5a327292c4c11cfb9492581f2b771ecf21af
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .settings/org.eclipse.core.resources.prefs
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>fc-cms</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.dltk.core.scriptbuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.dltk.ruby.core.nature</nature>
16
+ </natures>
17
+ </projectDescription>
data/.release_app.sh ADDED
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+
3
+ rm pkg/*
4
+ bundle install
5
+ bundle exec rspec spec
6
+ rake build
7
+ #gem build twitter_embed.gemspec
8
+
9
+
10
+ exit 0
11
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ #!/bin/bash --login
2
+
3
+ rvm --default use 2.3.1
4
+ ruby -v
5
+
6
+ exit 0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.3
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 TODO: Write your email address. 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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in twitter_embed.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ twitter_embed (0.1.0)
5
+ rails
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.4.2)
11
+ actionpack (= 5.2.4.2)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.4.2)
15
+ actionpack (= 5.2.4.2)
16
+ actionview (= 5.2.4.2)
17
+ activejob (= 5.2.4.2)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.4.2)
21
+ actionview (= 5.2.4.2)
22
+ activesupport (= 5.2.4.2)
23
+ rack (~> 2.0, >= 2.0.8)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.4.2)
28
+ activesupport (= 5.2.4.2)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.4.2)
34
+ activesupport (= 5.2.4.2)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.4.2)
37
+ activesupport (= 5.2.4.2)
38
+ activerecord (5.2.4.2)
39
+ activemodel (= 5.2.4.2)
40
+ activesupport (= 5.2.4.2)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.4.2)
43
+ actionpack (= 5.2.4.2)
44
+ activerecord (= 5.2.4.2)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.4.2)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ builder (3.2.4)
53
+ concurrent-ruby (1.1.6)
54
+ crass (1.0.6)
55
+ diff-lcs (1.3)
56
+ erubi (1.9.0)
57
+ globalid (0.4.2)
58
+ activesupport (>= 4.2.0)
59
+ i18n (1.8.2)
60
+ concurrent-ruby (~> 1.0)
61
+ loofah (2.5.0)
62
+ crass (~> 1.0.2)
63
+ nokogiri (>= 1.5.9)
64
+ mail (2.7.1)
65
+ mini_mime (>= 0.1.1)
66
+ marcel (0.3.3)
67
+ mimemagic (~> 0.3.2)
68
+ method_source (1.0.0)
69
+ mimemagic (0.3.4)
70
+ mini_mime (1.0.2)
71
+ mini_portile2 (2.4.0)
72
+ minitest (5.14.0)
73
+ nio4r (2.5.2)
74
+ nokogiri (1.10.9)
75
+ mini_portile2 (~> 2.4.0)
76
+ rack (2.2.2)
77
+ rack-test (1.1.0)
78
+ rack (>= 1.0, < 3)
79
+ rails (5.2.4.2)
80
+ actioncable (= 5.2.4.2)
81
+ actionmailer (= 5.2.4.2)
82
+ actionpack (= 5.2.4.2)
83
+ actionview (= 5.2.4.2)
84
+ activejob (= 5.2.4.2)
85
+ activemodel (= 5.2.4.2)
86
+ activerecord (= 5.2.4.2)
87
+ activestorage (= 5.2.4.2)
88
+ activesupport (= 5.2.4.2)
89
+ bundler (>= 1.3.0)
90
+ railties (= 5.2.4.2)
91
+ sprockets-rails (>= 2.0.0)
92
+ rails-dom-testing (2.0.3)
93
+ activesupport (>= 4.2.0)
94
+ nokogiri (>= 1.6)
95
+ rails-html-sanitizer (1.3.0)
96
+ loofah (~> 2.3)
97
+ railties (5.2.4.2)
98
+ actionpack (= 5.2.4.2)
99
+ activesupport (= 5.2.4.2)
100
+ method_source
101
+ rake (>= 0.8.7)
102
+ thor (>= 0.19.0, < 2.0)
103
+ rake (12.3.3)
104
+ rspec (3.9.0)
105
+ rspec-core (~> 3.9.0)
106
+ rspec-expectations (~> 3.9.0)
107
+ rspec-mocks (~> 3.9.0)
108
+ rspec-core (3.9.1)
109
+ rspec-support (~> 3.9.1)
110
+ rspec-expectations (3.9.1)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.9.0)
113
+ rspec-mocks (3.9.1)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.9.0)
116
+ rspec-support (3.9.2)
117
+ sprockets (3.7.2)
118
+ concurrent-ruby (~> 1.0)
119
+ rack (> 1, < 3)
120
+ sprockets-rails (3.2.1)
121
+ actionpack (>= 4.0)
122
+ activesupport (>= 4.0)
123
+ sprockets (>= 3.0.0)
124
+ thor (1.0.1)
125
+ thread_safe (0.3.6)
126
+ tzinfo (1.2.7)
127
+ thread_safe (~> 0.1)
128
+ websocket-driver (0.7.1)
129
+ websocket-extensions (>= 0.1.0)
130
+ websocket-extensions (0.1.4)
131
+
132
+ PLATFORMS
133
+ ruby
134
+
135
+ DEPENDENCIES
136
+ rake (~> 12.0)
137
+ rspec (~> 3.0)
138
+ twitter_embed!
139
+
140
+ BUNDLED WITH
141
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
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,37 @@
1
+ # TwitterEmbed
2
+
3
+ Crawl Twitter's embed HTML with no limit.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'twitter_embed'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install twitter_embed
20
+
21
+ ## Usage
22
+
23
+ Retrieve tweet's HTML by providing the tweet's ID.
24
+
25
+ > TwitterEmbed::Tweet.html_str("1240688751082221568")
26
+ Theme and language can also be specified. (defaults: language is 'en', theme is 'light')
27
+
28
+ > TwitterEmbed::Tweet.html_str("1246619311638282242",lang: "ja", theme: "dark")
29
+ You can also check if the tweet exists by prodiving the link.
30
+
31
+ > TwitterEmbed::Tweet.is_exists?("https://twitter.com/rails/status/1240688751082221568")
32
+
33
+ ## Contributing
34
+
35
+ Bug reports are welcome on GitHub at https://github.com/wwwfernand/twitter_embed.
36
+
37
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "twitter_embed"
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,77 @@
1
+ require "twitter_embed/version"
2
+ require 'open-uri'
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'rails/engine'
6
+
7
+ ##
8
+ # This module represents twitter_embed gem
9
+ module TwitterEmbed
10
+ ##
11
+ # This class provides static functionalities for crawling twitter
12
+ class Tweet < ::Rails::Engine
13
+ # Crawl the embed's HTML string of twitter
14
+ #
15
+ # @param tweet_id [String]
16
+ # @param *args [object]
17
+ # @return [String]
18
+ #
19
+ # @example
20
+ # TwitterEmbed.html_str('1234567890') #=> "<ul><li>foo</li><li>bar</li></ul>"
21
+ def self.html_str(tweet_id,*args)
22
+ return nil if tweet_id.nil? || tweet_id.to_s.empty?
23
+ opt={}
24
+ opt=args[0] unless args.nil? || args.empty?
25
+ options={
26
+ lang: 'en',
27
+ theme: 'light'
28
+ }.
29
+ merge(opt).
30
+ merge({callback: "__twttr.callbacks.cb0", ids: tweet_id, suppress_response_codes: true})
31
+ json={}
32
+ domains=[
33
+ "https://cdn.syndication.twimg.com",
34
+ "https://syndication.twitter.com"
35
+ ]
36
+ domain_ctr=0
37
+ while json.empty? && domain_ctr<domains.length
38
+ #url="#{domains[domain_ctr]}/tweets.json?callback=__twttr.callbacks.cb0&ids=#{tweet_id}&lang=#{options[:lang]}&suppress_response_codes=true&theme=#{options[:theme]}"
39
+ url="#{domains[domain_ctr]}/tweets.json"
40
+ uri=URI.parse(url)
41
+ uri.query=URI.encode_www_form( options )
42
+ jsonp=Net::HTTP.get(uri)
43
+ str="{#{jsonp[/{(.*?)}/m, 1]}}"
44
+ json=JSON.parse(str)
45
+ domain_ctr+=1
46
+ end
47
+ html=nil
48
+ html="<div class='twitter_embed_#{options[:theme]}'><div data-twitter-event-id='0' class='SandboxRoot ' style='position: relative;'>#{json.values.first}</div></div>" if json.any?
49
+ return html
50
+ end
51
+
52
+ # Check if a twitter's post exist
53
+ #
54
+ # @param url [String]
55
+ # @return [Boolean]
56
+ #
57
+ # @example
58
+ # TwitterEmbed.is_exists('https://twitter.com/rails/status/1240688751082221568') #=> true
59
+ def self.is_exists?(url)
60
+ return nil if url.nil? || url.to_s.empty?
61
+ begin
62
+ uri = URI("https://publish.twitter.com/oembed?url=#{CGI.escape(url)}&partner=&hide_thread=false")
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = true
65
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
66
+ request = Net::HTTP::Get.new(uri)
67
+ request["cache-control"] = 'no-cache'
68
+ response = http.request(request)
69
+ return true if response.code == "200"
70
+ return false if response.code == "404"
71
+ return nil
72
+ rescue
73
+ nil
74
+ end
75
+ end
76
+ end
77
+ end