class ContributionCount::Client

Constants

URL

Attributes

url[R]

Public Class Methods

new(account_name) click to toggle source
# File lib/contribution_count/client.rb, line 8
def initialize(account_name)
  @url = URL + account_name + "/contributions"
end

Public Instance Methods

all() click to toggle source
# File lib/contribution_count/client.rb, line 27
def all
  count_hash
end
contribution?(date_str) click to toggle source
# File lib/contribution_count/client.rb, line 38
def contribution?(date_str)
  return false if date(date_str) == 0
  true
end
contribution_today?() click to toggle source
# File lib/contribution_count/client.rb, line 17
def contribution_today?
  return false if today == 0
  true
end
date(date) click to toggle source
# File lib/contribution_count/client.rb, line 31
def date(date)
  return if date.nil?
  count = count_hash[date]
  raise NoDataError if count.nil?
  count
end
today() click to toggle source
# File lib/contribution_count/client.rb, line 12
def today
  today = Date.today.to_s
  count_hash[today]
end
today_contribution_notify_line() click to toggle source
# File lib/contribution_count/client.rb, line 43
def today_contribution_notify_line
  return if today.nil?
  message = "today_contribution_count: #{today}"
  Line::Notify::Client.message(message: message)
end
yesterday() click to toggle source
# File lib/contribution_count/client.rb, line 22
def yesterday
  yesterday = (Date.today - 1).to_s
  count_hash[yesterday]
end

Private Instance Methods

count_hash() click to toggle source
# File lib/contribution_count/client.rb, line 65
def count_hash
  html.css('.day').map{|row|
    date = row.attribute('data-date').value
    count = row.attribute('data-count').value.to_i
    [date, count]
  }.to_h
end
fetch_html() click to toggle source
# File lib/contribution_count/client.rb, line 58
def fetch_html
  open(url) do |f|
    charset = f.charset
    f.read
  end
end
html() click to toggle source
# File lib/contribution_count/client.rb, line 50
def html
  begin
    Nokogiri::HTML.parse(fetch_html, nil, nil)
  rescue OpenURI::HTTPError
    raise NoAccountError
  end
end