<commit_before>class ScopusRest < Source
  
  validates_each :api_key, :partner_id do |record, attr, value|
    record.errors.add(attr, "can't be blank") if value.blank?
  end
  
  def get_data(article, options={})
    raise(ArgumentError, "#{display_name} configuration requires partner_id") \
      if config.partner_id.blank?

    options[:extraheaders] = { "Accept"  => "application/json", "X-ELS-APIKey" => config.api_key, "X-ELS-ResourceVersion" => "XOCS" }
    
    query_url = get_query_url(article, options)
    results = get_json(query_url, options) 
    
    events = results["search-results"]["entry"]

    # Workaround if Scopus returns more than one result for a given DOI (which it shouldn't)
    events = events[0] if events.is_a? Array
    
    total = events["citedby-count"].to_i
    scopus_id = events["dc:identifier"][10..-1]

    event_url = get_event_url(scopus_id)

    {:events => events,
     :events_url => event_url,
     :event_count => total,
     :local_id => scopus_id}}
  end
  
  def get_query_url(article, options={})
    # http://api.elsevier.com/content/search/index:SCOPUS?query=doi(%{doi})"
    config.url % { :doi => CGI.escape(article.doi) }
  end
  
  def get_event_url(scopus_id, options={})
    # http://www.scopus.com/inward/citedby.url?partnerID=%{partner_id}&scp=%{scopus_id}"
    config.event_url % { :partner_id => config.partner_id, :scopus_id => scopus_id }
  end
  
  def get_config_fields
    [{:field_name => "api_key", :field_type => "text_field"},
    {:field_name => "partner_id", :field_type => "text_field"}]
  end

  def partner_id
    config.partner_id
  end
  
  def partner_id=(value)
    config.partner_id = value
  end
  
end<commit_msg>PDEV-723 added config fields to scopus_rest<commit_after>class ScopusRest < Source
  
  validates_each :api_key, :partner_id do |record, attr, value|
    record.errors.add(attr, "can't be blank") if value.blank?
  end
  
  def get_data(article, options={})
    raise(ArgumentError, "#{display_name} configuration requires partner_id") \
      if config.partner_id.blank?

    options[:extraheaders] = { "Accept"  => "application/json", "X-ELS-APIKey" => config.api_key, "X-ELS-ResourceVersion" => "XOCS" }
    
    query_url = get_query_url(article, options)
    results = get_json(query_url, options) 
    
    events = results["search-results"]["entry"]

    # Workaround if Scopus returns more than one result for a given DOI (which it shouldn't)
    events = events[0] if events.is_a? Array
    
    total = events["citedby-count"].to_i
    scopus_id = events["dc:identifier"][10..-1]

    event_url = get_event_url(scopus_id)

    {:events => events,
     :events_url => event_url,
     :event_count => total,
     :local_id => scopus_id}}
  end
  
  def get_query_url(article, options={})
    # http://api.elsevier.com/content/search/index:SCOPUS?query=doi(%{doi})"
    config.url % { :doi => CGI.escape(article.doi) }
  end
  
  def get_event_url(scopus_id, options={})
    # http://www.scopus.com/inward/citedby.url?partnerID=%{partner_id}&scp=%{scopus_id}"
    config.event_url % { :partner_id => config.partner_id, :scopus_id => scopus_id }
  end
  
  def get_config_fields
    [{:field_name => "url", :field_type => "text_area", :size => "90x2"},
    {:field_name => "api_key", :field_type => "text_field"},
    {:field_name => "partner_id", :field_type => "text_field"}]
  end
  
  def url
    config.url
  end

  def url=(value)
    config.url = value
  end
  
  def api_key
    config.api_key
  end

  def api_key=(value)
    config.api_key = value
  end

  def partner_id
    config.partner_id
  end
  
  def partner_id=(value)
    config.partner_id = value
  end
  
end
{'fraction_non_alphanumeric': 0.14076484947111473, 'fraction_numerical': 0.003797125033902902, 'mean_word_length': 3.5530864197530865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5504407', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1339, 'n_words': 260}