onebox 1.5.2 → 1.5.3

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
  SHA1:
3
- metadata.gz: 542e1d08ae3e97ddf61f8277d8328b8836a5785a
4
- data.tar.gz: 02d39f351722e9020bff8669d1bbc6ff820bf06e
3
+ metadata.gz: 06db4c95569c90b9238b49e72e33e7f618545f99
4
+ data.tar.gz: 921ab7e92a62a4a43098a38d58baba0186233337
5
5
  SHA512:
6
- metadata.gz: 639e272ae320e29103d3e2ef022cbac34e2ebbefedf5dc0e9e0955dafdb93098af1fda4dd3f2f674d486e2a6f9fc4f118d7d980fdd084d66bcc0ac71ac0284c9
7
- data.tar.gz: b34ca56a4cba354ba0de3d614986325bb316f5e55a54a9a7b684cc55357d01e6050ee601304f6d2187e1d92a02c8726118014329e9baabf8c737579f051b2c79
6
+ metadata.gz: 40995c30495f6ef5352443154da5b3d068e970283dc89240e15559f453ac06164346e917129f38075c4c2b227cc5147ef4228f1ec71fe1ea6b74dc95c9c92cee
7
+ data.tar.gz: bb1f6ab98b37391687d21ed65c5683ea36541ade58ea08f9bc14a15ab0ac7508818723cedeac07a6576f88dbb01e7d5ac12d21b37f5009e7af1a35051033e9c5
@@ -13,58 +13,12 @@ module Onebox
13
13
 
14
14
  private
15
15
 
16
- #Make an api JSON request, will attempt to authenticate if provided in the engine options
17
- # Author: Lidlanca
18
- #: self.options[:github_auth_method] = :basic | :oauth | nil
19
- # :oauth is the recommend way for authentication. when generating token you can control privileges, and you do not expose your password
20
- # :basic require username and password provided in options[:github_auth_user , :github_auth_pass]
21
- # nil or false will make a request without any authentication. request rate limit are lower.
22
-
23
- def api_json_request url
24
- box_options = self.options
25
- case box_options[:github_auth_method]
26
- when :basic
27
- auth = [box_options[:github_auth_user] , box_options[:github_auth_pass]] # user name and password
28
- when :oauth
29
- auth = [box_options[:github_auth_token] , "x-oauth-basic"] #oauth does not need password with token
30
- else
31
- #request without auth
32
- return ::MultiJson.load(open(url,"Accept"=>"application/vnd.github.v3.text+json",read_timeout: timeout))
33
-
34
- end
35
- #Request with auth
36
- return ::MultiJson.load(open(url,"Accept"=>"application/vnd.github.v3.text+json",http_basic_authentication:auth, read_timeout: timeout))
37
- end
38
-
39
- def raw
40
- @raw ||= api_json_request url
41
- end
42
16
  def match
43
17
  @match ||= @url.match(%r{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<number>[^/]+)})
44
18
  end
45
19
 
46
20
  def data
47
- box_options = self.options
48
21
  result = raw.clone
49
-
50
- pull_status = "" << {:closed=>"closed",:open=>"open"}[raw["state"].to_sym] << (raw["state"] == "closed" ? (raw["merged"] ? " & merged" : " & declined") : "") #closed , open
51
- result['pull_status_str'] = pull_status
52
- result['pull_status'] = raw["state"]
53
- result['pull_status_str'] = pull_status
54
- result['pull_status_str_open'] = raw["state"]=="open"
55
- result['pull_status_closed_accepted'] = raw["state"]=="closed" && raw["merged"]
56
- result['pull_status_closed_declined'] = raw["state"]=="closed" && !raw["merged"]
57
- result['pull_status_class'] = (raw["merged"] ? "merged": raw["state"] ) # open, merged, close
58
- result['pull_status_bgcolor'] = {:open=>"#6cc644",:merged =>"6e5494", :closed=> "#bd2c00"}[result['pull_status_class'].to_sym]
59
- result['inline_css'] = false #set to true if you need basic styling and you don't have external css
60
- if box_options[:get_build_status]
61
- url2 = raw["statuses_url"]
62
- raw2 = api_json_request url2 #2nd api request to get build status
63
- unless raw2.empty?
64
- result['build_status'] = "Build status: " + raw2[0]["state"].to_s.capitalize + " | " + raw2[0]["description"].to_s
65
- end
66
- end
67
-
68
22
  result['link'] = link
69
23
  result['created_at'] = Time.parse(result['created_at']).strftime("%I:%M%p - %d %b %y")
70
24
  result
@@ -5,7 +5,6 @@ module Onebox
5
5
  def raw
6
6
  return @raw if @raw
7
7
  response = fetch_response(url)
8
-
9
8
  html_doc = Nokogiri::HTML(response.body)
10
9
 
11
10
  # Determine if we should use OEmbed or OpenGraph
@@ -61,7 +60,7 @@ module Onebox
61
60
  og
62
61
  end
63
62
 
64
- def fetch_response(location, limit = 5, domain = nil)
63
+ def fetch_response(location, limit = 5, domain = nil,headers=nil)
65
64
  raise Net::HTTPError.new('HTTP redirect too deep', location) if limit == 0
66
65
 
67
66
  uri = URI(location)
@@ -75,11 +74,18 @@ module Onebox
75
74
  http.use_ssl = true
76
75
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
77
76
  end
78
- response = http.request_get(uri.request_uri)
77
+
78
+ response = http.request_get(uri.request_uri,headers)
79
+
80
+ cookie = response.get_fields('set-cookie')
81
+ if (cookie)
82
+ header = {'cookie' => cookie.join("")}
83
+ end
84
+ header = nil unless header.is_a? Hash
79
85
 
80
86
  case response
81
87
  when Net::HTTPSuccess then response
82
- when Net::HTTPRedirection then fetch_response(response['location'], limit - 1, "#{uri.scheme}://#{uri.host}")
88
+ when Net::HTTPRedirection then fetch_response(response['location'], limit - 1, "#{uri.scheme}://#{uri.host}",header)
83
89
  else
84
90
  response.error!
85
91
  end
@@ -76,6 +76,7 @@ module Onebox
76
76
  mlb.com
77
77
  myspace.com
78
78
  nba.com
79
+ nytimes.com
79
80
  npr.org
80
81
  photobucket.com
81
82
  pinterest.com
@@ -1,3 +1,3 @@
1
1
  module Onebox
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.3"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  {{#author.avatar_url}}
2
2
  <a href="{{author.html_url}}" target="_blank">
3
- <img alt="{{author.login}}" src="{{author.avatar_url}}" class="thumbnail onebox-avatar">
3
+ <img alt="{{author.login}}" src="{{author.avatar_url}}" class="thumbnail onebox-avatar" width="90" height="90">
4
4
  </a>
5
5
  {{/author.avatar_url}}
6
6
 
@@ -1,6 +1,6 @@
1
1
  {{#user.avatar_url}}
2
2
  <a href="{{user.html_url}}" target="_blank">
3
- <img alt="{{user.login}}" src="{{user.avatar_url}}" class="thumbnail onebox-avatar">
3
+ <img alt="{{user.login}}" src="{{user.avatar_url}}" class="thumbnail onebox-avatar" width="90" height="90">
4
4
  </a>
5
5
  {{/user.avatar_url}}
6
6
 
@@ -8,66 +8,14 @@
8
8
  <a href="{{html_url}}" target="_blank">{{title}}</a>
9
9
  </h4>
10
10
 
11
- <div class='github-commit-status github-content-right' {{#inline_css}}style='margin-bottom:5px;padding: 10px;background: #F5F5F5;margin-left: 100px;border-radius: 5px;'{{/inline_css}}>
12
-
13
- <span class="status_tag {{pull_status_class}}" {{#inline_css}}style="background:{{pull_status_bgcolor}};color:#fff;display:inline-block;border-radius:3px;padding:1px 4px;font-weight:bold;margin-bottom:5px;"{{/inline_css}}> {{pull_status_str}} </span>
14
-
15
-
16
-
17
-
18
- {{#build_status}}
19
- <span class='build_status' {{#inline_css}}style='padding: 2px;font-size:12px'{{/inline_css}}>{{build_status}}</span>
20
- {{/build_status}}
21
-
22
- <div class="github-commit-stats">
23
- <strong>{{commits}} commits</strong>
24
- changed <strong>{{changed_files}} files</strong>
25
- with <strong>{{additions}} additions</strong>
26
- and <strong>{{deletions}} deletions</strong>.
27
- </div>
28
- </div>
29
-
30
- <div class="date github-content-right" {{#inline_css}}style='margin-left:100px;'{{/inline_css}}>
11
+ <div class="date">
31
12
  by <a href="{{user.html_url}}" target="_blank">{{user.login}}</a>
32
13
  on <a href="{{html_url}}" target="_blank">{{created_at}}</a>
33
14
  </div>
34
15
 
35
- {{! // Sample Styling
36
-
37
- .onebox-body .github-commit-status {
38
- background: #F5F5F5;
39
- border-radius: 5px;
40
- margin:0px 0px 5px 100px;
41
- padding: 10px;
42
- }
43
-
44
- .onebox-body .status_tag {
45
- display:inline-block;
46
- color:#fff;
47
- padding:1px 4px;
48
- border-radius:3px;
49
- font-weight:bold;
50
- margin-bottom:5px;
51
- text-transform:capitalize;
52
- }
53
-
54
- .onebox-body .build_status
55
- {
56
- padding: 2px;
57
- font-size:12px;
58
- }
59
-
60
- .onebox-body .status_tag.open {
61
- background-color:#6cc644;
62
- }
63
- .onebox-body .status_tag.merged{
64
- background-color:#6e5494;
65
- }
66
- .onebox-body .status_tag.closed {
67
- background-color:#bd2c00;
68
- }
69
-
70
- .onebox-body .github-content-right{
71
- margin-left:100px;
72
- }
73
- }}
16
+ <div class="github-commit-stats">
17
+ <strong>{{commits}} commits</strong>
18
+ changed <strong>{{changed_files}} files</strong>
19
+ with <strong>{{additions}} additions</strong>
20
+ and <strong>{{deletions}} deletions</strong>.
21
+ </div>
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.5.2
4
+ version: 1.5.3
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: 2014-10-07 00:00:00.000000000 Z
13
+ date: 2014-10-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
344
  version: '0'
345
345
  requirements: []
346
346
  rubyforge_project:
347
- rubygems_version: 2.1.11
347
+ rubygems_version: 2.2.2
348
348
  signing_key:
349
349
  specification_version: 4
350
350
  summary: A gem for turning URLs into previews.