Class: Ossert::Fetch::Bestgems

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ossert/fetch/bestgems.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Bestgems

Returns a new instance of Bestgems.



33
34
35
36
# File 'lib/ossert/fetch/bestgems.rb', line 33

def initialize(project)
  @client = SimpleClient.new('http://bestgems.org/api/v1/')
  @project = project
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



28
29
30
# File 'lib/ossert/fetch/bestgems.rb', line 28

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



28
29
30
# File 'lib/ossert/fetch/bestgems.rb', line 28

def project
  @project
end

Instance Method Details

#daily_downloadsObject



42
43
44
# File 'lib/ossert/fetch/bestgems.rb', line 42

def daily_downloads
  client.get("gems/#{project.rubygems_alias}/daily_downloads.json")
end

#daily_rankingObject



50
51
52
# File 'lib/ossert/fetch/bestgems.rb', line 50

def daily_ranking
  client.get("gems/#{project.rubygems_alias}/daily_ranking.json")
end

#processObject



54
55
56
57
58
# File 'lib/ossert/fetch/bestgems.rb', line 54

def process
  process_total_downloads
  process_daily_downloads
  process_delta_downloads
end

#process_daily_downloadsObject



74
75
76
77
78
79
# File 'lib/ossert/fetch/bestgems.rb', line 74

def process_daily_downloads
  daily_downloads.each do |daily|
    downloads_saved = community.quarters[daily['date']].delta_downloads.to_i
    community.quarters[daily['date']].delta_downloads = downloads_saved + daily['daily_downloads']
  end
end

#process_delta_downloadsObject



81
82
83
84
85
86
87
88
89
# File 'lib/ossert/fetch/bestgems.rb', line 81

def process_delta_downloads
  prev_downloads_delta = 0
  community.quarters.each_sorted do |start_date, stat|
    prev_downloads_delta = stat.delta_downloads.to_i - prev_downloads_delta
    community.quarters[start_date].download_divergence = divergence(
      prev_downloads_delta, @downloads_till_now['total_downloads']
    )
  end
end

#process_total_downloadsObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ossert/fetch/bestgems.rb', line 60

def process_total_downloads
  @downloads_till_now = nil
  total_downloads.each do |total|
    @downloads_till_now = total unless @downloads_till_now
    quarter_downloads = community.quarters[total['date']]

    quarter_downloads.total_downloads = [
      quarter_downloads.total_downloads.to_i,
      total['total_downloads']
    ].max
  end
  community.total.total_downloads = @downloads_till_now['total_downloads']
end

#total_downloadsObject



38
39
40
# File 'lib/ossert/fetch/bestgems.rb', line 38

def total_downloads
  client.get("gems/#{project.rubygems_alias}/total_downloads.json")
end

#total_rankingObject



46
47
48
# File 'lib/ossert/fetch/bestgems.rb', line 46

def total_ranking
  client.get("gems/#{project.rubygems_alias}/total_ranking.json")
end