class QiitaScouter::QiitaItemsJsonLoader

QiitaScouter::QiitaItemsJsonLoader

Constants

PAGE_LIMIT
PER_PAGE
QIITA_URL

Attributes

articles[R]
user[R]

Public Class Methods

new() click to toggle source
# File lib/qiita_items_json_loader.rb, line 15
def initialize
  @articles = Articles.new
end

Public Instance Methods

load(user) click to toggle source
# File lib/qiita_items_json_loader.rb, line 19
def load(user)
  @user = user
  tmp_verbose = $VERBOSE
  $VERBOSE = nil
  OpenSSL::SSL.const_set('VERIFY_PEER', OpenSSL::SSL::VERIFY_NONE)
  $VERBOSE = tmp_verbose
  (1..PAGE_LIMIT).each do |page|
    before_size = @articles.size
    load_page(user, page)
    break if before_size == @articles.size
  end
end

Private Instance Methods

load_page(user, page) click to toggle source
# File lib/qiita_items_json_loader.rb, line 34
def load_page(user, page)
  json = open(format(QIITA_URL, user, page, PER_PAGE)).read
  json_articles = JSON.parser.new(json).parse
  @articles += json_articles.each_with_object(Articles.new) do |item, memo|
    memo << Article.new(item)
    memo
  end
end