onebox 1.8.95 → 1.8.96

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d02de0d9a88959e66217ddb8ee376a74b2966329d6898141ca27c1c67bf528c
4
- data.tar.gz: 586f0dd3b4f7ff9339d02ace072fc0e7e18b7f842e9d6a1466e6e4f69cd9ccc4
3
+ metadata.gz: 3f16554d39128fb96f768eb076e102f93a3a3a5b25225470babdc73b595cc039
4
+ data.tar.gz: e940f9efc136221d4343871fe9ed7032879866358d9c06cba4224d0a6b9d1e9e
5
5
  SHA512:
6
- metadata.gz: b0ee8ace0a72a29fdd6c8d6dabe2648863c3168dd2aa861d766a7a4b51924e6bb562347b3de252cb922d7007f6e776c5901510854aa492d9917fe27cfc8e2491
7
- data.tar.gz: 73417906a702859c059967b3b635438883278542cc3ad4b9a70a2ff3d0408a9a33e441a79125f38db8169859bc50244a690a72fee448e11fa61be3cff6405007
6
+ metadata.gz: d2331514eb4a99ccb813fd8f61522d326d42209a7bb184b24cc8484fa85b7894b8fcfb78806a5a6bbe9012a645c141f5bec30c34d9a900c8d0616671df2bd994
7
+ data.tar.gz: 484b176b361a4afb29d334a8491a9e3dcc51686594c96b23162a2c634b58d357d3e851bf8ecaf952aa847ac86546b34938057eabbf8bfaf9ee6fe20bcb3b6a7a
@@ -23,7 +23,7 @@ module Onebox
23
23
  twitter_data[m_property.to_sym] = m_content
24
24
  end
25
25
  end
26
- return twitter_data
26
+ twitter_data
27
27
  end
28
28
 
29
29
  def match
@@ -31,7 +31,7 @@ module Onebox
31
31
  end
32
32
 
33
33
  def twitter_data
34
- @twitter_data = get_twitter_data
34
+ @twitter_data ||= get_twitter_data
35
35
  end
36
36
 
37
37
  def client
@@ -51,9 +51,7 @@ module Onebox
51
51
  end
52
52
 
53
53
  def access(*keys)
54
- keys.reduce(raw) do |memo, key|
55
- memo[key] || memo[key.to_s]
56
- end
54
+ raw.dig *keys
57
55
  end
58
56
 
59
57
  def tweet
@@ -66,13 +64,12 @@ module Onebox
66
64
 
67
65
  def timestamp
68
66
  if twitter_api_credentials_present?
69
- created_at = access(:created_at)
70
- date = DateTime.strptime(created_at, "%a %b %d %H:%M:%S %z %Y")
67
+ date = DateTime.strptime(access(:created_at), "%a %b %d %H:%M:%S %z %Y")
71
68
  user_offset = access(:user, :utc_offset).to_i
72
69
  offset = (user_offset >= 0 ? "+" : "-") + Time.at(user_offset.abs).gmtime.strftime("%H%M")
73
70
  date.new_offset(offset).strftime("%-l:%M %p - %-d %b %Y")
74
71
  else
75
- raw.at_css(".tweet-timestamp").attr('title')
72
+ attr_at_css(".tweet-timestamp", 'title')
76
73
  end
77
74
  end
78
75
 
@@ -80,7 +77,7 @@ module Onebox
80
77
  if twitter_api_credentials_present?
81
78
  "#{access(:user, :name)} (#{access(:user, :screen_name)})"
82
79
  else
83
- "#{raw.css('.tweet.permalink-tweet')[0].attribute('data-name')} (#{raw.css('.tweet.permalink-tweet')[0].attribute('data-screen-name')})"
80
+ "#{attr_at_css('.tweet.permalink-tweet', 'data-name')} (#{attr_at_css('.tweet.permalink-tweet', 'data-screen-name')})"
84
81
  end
85
82
  end
86
83
 
@@ -94,30 +91,74 @@ module Onebox
94
91
 
95
92
  def likes
96
93
  if twitter_api_credentials_present?
97
- count = access(:favorite_count).to_i
98
- return count > 0 ? client.prettify_number(count) : nil
94
+ prettify_number(access(:favorite_count).to_i)
99
95
  else
100
- raw.at_css(".request-favorited-popup").attr('data-compact-localized-count') rescue nil
96
+ attr_at_css(".request-favorited-popup", 'data-compact-localized-count')
101
97
  end
102
98
  end
103
99
 
104
100
  def retweets
105
101
  if twitter_api_credentials_present?
106
- count = access(:retweet_count).to_i
107
- return count > 0 ? client.prettify_number(count) : nil
102
+ prettify_number(access(:retweet_count).to_i)
108
103
  else
109
- raw.at_css(".request-retweeted-popup").attr('data-compact-localized-count') rescue nil
104
+ attr_at_css(".request-retweeted-popup", 'data-compact-localized-count')
110
105
  end
111
106
  end
112
107
 
108
+ def quoted_full_name
109
+ if twitter_api_credentials_present?
110
+ access(:quoted_status, :user, :name)
111
+ else
112
+ raw.css('.QuoteTweet-fullname')[0]&.text
113
+ end
114
+ end
115
+
116
+ def quoted_screen_name
117
+ if twitter_api_credentials_present?
118
+ access(:quoted_status, :user, :screen_name)
119
+ else
120
+ attr_at_css(".QuoteTweet-innerContainer", "data-screen-name")
121
+ end
122
+ end
123
+
124
+ def quoted_tweet
125
+ if twitter_api_credentials_present?
126
+ access(:quoted_status, :full_text)
127
+ else
128
+ raw.css('.QuoteTweet-text')[0]&.text
129
+ end
130
+ end
131
+
132
+ def quoted_link
133
+ if twitter_api_credentials_present?
134
+ "https://twitter.com/#{quoted_screen_name}/status/#{access(:quoted_status, :id)}"
135
+ else
136
+ "https://twitter.com#{attr_at_css(".QuoteTweet-innerContainer", "href")}"
137
+ end
138
+ end
139
+
140
+ def prettify_number(count)
141
+ count > 0 ? client.prettify_number(count) : nil
142
+ end
143
+
144
+ def attr_at_css(css_property, attribute_name)
145
+ raw.at_css(css_property)&.attr(attribute_name)
146
+ end
147
+
113
148
  def data
114
- { link: link,
149
+ @data ||= {
150
+ link: link,
115
151
  tweet: tweet,
116
152
  timestamp: timestamp,
117
153
  title: title,
118
154
  avatar: avatar,
119
155
  likes: likes,
120
- retweets: retweets }
156
+ retweets: retweets,
157
+ quoted_tweet: quoted_tweet,
158
+ quoted_full_name: quoted_full_name,
159
+ quoted_screen_name: quoted_screen_name,
160
+ quoted_link: quoted_link
161
+ }
121
162
  end
122
163
  end
123
164
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onebox
4
- VERSION = "1.8.95"
4
+ VERSION = "1.8.96"
5
5
  end
@@ -5,7 +5,19 @@
5
5
  </a>
6
6
  </h4>
7
7
 
8
- <div class="tweet">{{{tweet}}}</div>
8
+ <div class="tweet">
9
+ {{{tweet}}}
10
+ {{#quoted_tweet}}
11
+ <a class="quoted-link" href="{{quoted_link}}">
12
+ <div class="quoted">
13
+ <p class="quoted-title">{{quoted_full_name}} <span>@{{quoted_screen_name}}</span></p>
14
+ <div>
15
+ {{quoted_tweet}}
16
+ </div>
17
+ </div>
18
+ </a>
19
+ {{/quoted_tweet}}
20
+ </div>
9
21
 
10
22
  <div class='date'>
11
23
  <a href="{{link}}" target="_blank">{{timestamp}}</a>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onebox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.95
4
+ version: 1.8.96
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joanna Zeta
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-27 00:00:00.000000000 Z
13
+ date: 2019-07-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json