github-calendar 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/github/calendar.rb +19 -20
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf50a1eafa4c9bc2d866e025534f0d01ee71ba5
4
- data.tar.gz: 4d734ac9bf923934cca3d082f422ba1e01ba1d5e
3
+ metadata.gz: f05f60b5ed374e073c583e77a0940ffb3ec9710c
4
+ data.tar.gz: 1edb5b0427f24504e601695832d3de5f68108bd0
5
5
  SHA512:
6
- metadata.gz: 275737388b653d3f376f3693c1cb504e4aa9777588b8c28253e8c0a2da4f0bedbc3c23111c25672ff5eff9542c77bc0d52973fc9896b65f5176e9ed89b026294
7
- data.tar.gz: 1c24863ea5beb5276cf4c11d78952055aebbfca58de6539428acc57f48f4656a42242a51ceb98e841fa5651fc88a8573c93c27fc76295941dfca4d55bb4b8cbe
6
+ metadata.gz: 4fe87b15a86f10edcb208d177057d0b1d712dfdf95f44a50f2ee64ccb6fe2a2fb63c386edfac9077082870e081ebbba23438258f0173743b76d1a6b26261a465
7
+ data.tar.gz: 70bff1e4714f51fb1ff4433baca136f11e913cb8658fa791ff779052dc1f1908105605ed9180f3448e0be1bf702742b360c22dcfbb304367697f05bb07162fd8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
  ## Version 1
3
+ ### Version 1.2.0
4
+ * Switch to Curb instead of OpenURI for the `#get_page_source` method, due to possible conflicted `Kernel#open` monkeypatches from Sinatra and OpenURI (#4, ghuls-web#15)
5
+ * Improve reliability of `#get_daily`, `#get_weekly`, and `#get_monthly` by properly using Nokogiri's Element methods.
6
+ * `#get_calendar` no longer gets the initial `g` (containing the entire calendar); just the individual weeks as a NodeSet.
7
+
3
8
  ### Version 1.1.0
4
9
  * Bump Ruby to 2.3.0, Nokogiri to 1.6.7.2, and StringUtility to 2.7.1.
5
10
  * Improve some redundant regex.
@@ -1,4 +1,4 @@
1
- require 'open-uri'
1
+ require 'curb'
2
2
  require 'nokogiri'
3
3
  require 'string-utility'
4
4
  require_relative 'exceptions'
@@ -42,13 +42,12 @@ module GitHub
42
42
  weeks = get_calendar(user)
43
43
  ret = {}
44
44
  count = 0
45
- weeks[1..-1].each do |k|
46
- data = 0
47
- capture = k.to_s.scan(/data-count="(.*?)"/)
48
- capture[1..-1].each do |ints|
49
- data += ints[0].to_i
45
+ weeks.each do |k|
46
+ week_data = 0
47
+ k.children.each do |element|
48
+ week_data += element.attribute('data-count').value.to_i
50
49
  end
51
- ret[count] = data
50
+ ret[count] = week_data
52
51
  count += 1
53
52
  end
54
53
  ret
@@ -61,10 +60,10 @@ module GitHub
61
60
  weeks = get_calendar(user)
62
61
  ret = {}
63
62
  count = 0
64
- weeks[1..-1].each do |k|
65
- capture = k.to_s.scan(/data-count="(.*?)"/)
66
- capture[1..-1].each do |i|
67
- ret[count] = i[0].to_i
63
+ weeks.each do |k|
64
+ k.children.each do |day|
65
+ val = day.attribute('data-count').value.to_i
66
+ ret[count] = val
68
67
  count += 1
69
68
  end
70
69
  end
@@ -91,11 +90,11 @@ module GitHub
91
90
  '11' => 0,
92
91
  '12' => 0
93
92
  }
94
- weeks[1..-1].each do |k|
95
- date = k.to_s.scan(/data-date=".*-(.*?)-/)
96
- capture = k.to_s.scan(/data-count="(.*?)"/)
97
- capture[1..-1].each do |i|
98
- ret[date[0][0]] += i[0].to_i
93
+ weeks.each do |k|
94
+ k.children.each do |day|
95
+ date = day.attribute('data-date').value.split('-')[1]
96
+ count = day.attribute('data-count').value
97
+ ret[date] += count.to_i
99
98
  end
100
99
  end
101
100
  ret
@@ -133,7 +132,7 @@ module GitHub
133
132
  # @raise [UserNotFoundException] If the user is not found.
134
133
  def get_page_source(user)
135
134
  begin
136
- Nokogiri::HTML(open("https://github.com/#{user}"), &:noblanks)
135
+ Nokogiri::HTML(Curl.get("https://github.com/#{user}").body_str, &:noblanks)
137
136
  rescue OpenURI::HTTPError
138
137
  raise GitHub::Exceptions::UserNotFoundException.new(user)
139
138
  end
@@ -141,11 +140,11 @@ module GitHub
141
140
 
142
141
  # Gets the parsed calendar HTML source for the user profile.
143
142
  # @param user [String] See #get_total_year
144
- # @return [Nokogiri::XML::NodeSet] The NodeSet for all the g's in the calendar. Consider this as an array of all
145
- # the weeks. In iteration, you will probably want to skip the first, as it is the total yearly.
143
+ # @return [Nokogiri::XML::NodeSet] The NodeSet for all the days in the calendar. Consider this as an array of all
144
+ # the weeks.
146
145
  def get_calendar(user)
147
146
  source = get_page_source(user)
148
- source.css('svg.js-calendar-graph-svg g')
147
+ source.css('svg.js-calendar-graph-svg g g')
149
148
  end
150
149
 
151
150
  # Gets an average for all the integer values in a hash.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eli Foster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.7.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: curb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.1
41
55
  description: A library that allows for quick HTML parsing of GitHub user profile contribution
42
56
  calendars. This project is part of the GitHub User Language Statistics project.
43
57
  email: elifosterwy@gmail.com