Class: Scopus::Connection
- Inherits:
-
Object
- Object
- Scopus::Connection
- Extended by:
- URIRequest
- Includes:
- URIRequest
- Defined in:
- lib/scopus/connection.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_msg ⇒ Object
readonly
Returns the value of attribute error_msg.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
#proxy_post ⇒ Object
Returns the value of attribute proxy_post.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
#raw_xml ⇒ Object
readonly
Returns the value of attribute raw_xml.
-
#use_proxy ⇒ Object
Returns the value of attribute use_proxy.
-
#xml_response ⇒ Object
readonly
Returns the value of attribute xml_response.
Instance Method Summary collapse
- #close ⇒ Object
-
#connect_server(uri_string) ⇒ Object
Connect to api and start.
- #connection ⇒ Object
- #get_articles_from_uri(uri) ⇒ Object
- #get_connection ⇒ Object
- #get_journal_articles(journal, year = nil) ⇒ Object
-
#initialize(key, opts = {}) ⇒ Connection
constructor
A new instance of Connection.
Methods included from URIRequest
get_uri_abstract, get_uri_articles_country_year_area, get_uri_author, get_uri_citation_overview, get_uri_journal_articles
Constructor Details
#initialize(key, opts = {}) ⇒ Connection
Returns a new instance of Connection
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/scopus/connection.rb', line 37 def initialize(key, opts={}) @key=key @use_proxy=false @error=false @error_msg=nil if opts[:proxy_host] @use_proxy=true @proxy_host=opts[:proxy_host] @proxy_port=opts[:proxy_port] @proxy_user=opts[:proxy_user] @proxy_pass=opts[:proxy_pass] end end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error
34 35 36 |
# File 'lib/scopus/connection.rb', line 34 def error @error end |
#error_msg ⇒ Object (readonly)
Returns the value of attribute error_msg
34 35 36 |
# File 'lib/scopus/connection.rb', line 34 def error_msg @error_msg end |
#key ⇒ Object (readonly)
Returns the value of attribute key
34 35 36 |
# File 'lib/scopus/connection.rb', line 34 def key @key end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host
36 37 38 |
# File 'lib/scopus/connection.rb', line 36 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass
36 37 38 |
# File 'lib/scopus/connection.rb', line 36 def proxy_pass @proxy_pass end |
#proxy_post ⇒ Object
Returns the value of attribute proxy_post
36 37 38 |
# File 'lib/scopus/connection.rb', line 36 def proxy_post @proxy_post end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user
36 37 38 |
# File 'lib/scopus/connection.rb', line 36 def proxy_user @proxy_user end |
#raw_xml ⇒ Object (readonly)
Returns the value of attribute raw_xml
34 35 36 |
# File 'lib/scopus/connection.rb', line 34 def raw_xml @raw_xml end |
#use_proxy ⇒ Object
Returns the value of attribute use_proxy
35 36 37 |
# File 'lib/scopus/connection.rb', line 35 def use_proxy @use_proxy end |
#xml_response ⇒ Object (readonly)
Returns the value of attribute xml_response
34 35 36 |
# File 'lib/scopus/connection.rb', line 34 def xml_response @xml_response end |
Instance Method Details
#close ⇒ Object
53 54 55 |
# File 'lib/scopus/connection.rb', line 53 def close @connection.close if @connection end |
#connect_server(uri_string) ⇒ Object
Connect to api and start
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/scopus/connection.rb', line 67 def connect_server(uri_string) uri = URI(uri_string) req = Net::HTTP::Get.new(uri.request_uri) req['Accept']='application/xml' res = connection.request(req) xml=Nokogiri::XML(res.body) if xml.xpath("//service-error").length>0 @error=true @error_msg=xml.xpath("//statusText").text elsif xml.xpath("//atom:error",'atom'=>'http://www.w3.org/2005/Atom').length>0 @error=true @error_msg=xml.xpath("//atom:error").text else @error=false @error_msg=nil end @xml_response=Scopus.process_xml(xml) end |
#connection ⇒ Object
50 51 52 |
# File 'lib/scopus/connection.rb', line 50 def connection @connection||=get_connection end |
#get_articles_from_uri(uri) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/scopus/connection.rb', line 86 def get_articles_from_uri(uri) completo=false acumulado=[] pagina=1 while(!completo) do puts "pagina:#{pagina}" xml_response=connect_server(uri) if @error break else acumulado=acumulado+xml_response.entries_to_hash next_page=xml_response.next_page if next_page pagina+=1 uri=next_page.attribute("href").value else puts "completo" completo=true end end end acumulado end |
#get_connection ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/scopus/connection.rb', line 58 def get_connection if @use_proxy proxy = ::Net::HTTP::Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass) proxy.start("api.elsevier.com") else Net::HTTP.new("api.elsevier.com") end end |
#get_journal_articles(journal, year = nil) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/scopus/connection.rb', line 110 def get_journal_articles(journal,year=nil) uri=get_uri_journal_articles(journal,year) completo=false acumulado=[] while !completo do xml_response=connect_server(uri) if @error break else acumulado=acumulado+xml_response.entries_to_hash next_page=xml_response.next_page if next_page uri=next_page.attribute("href").value puts "siguiente pagina" else puts "completo" completo=true end end end acumulado end |