Class: Y2

Inherits:
Site show all
Defined in:
lib/tRuTag.rb

Instance Attribute Summary

Attributes inherited from Site

#attrib

Instance Method Summary collapse

Methods inherited from Site

#get_uml, #initialize, #required_attribute

Constructor Details

This class inherits a constructor from Site

Instance Method Details

#add_tags(tbin) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/tRuTag.rb', line 333

def add_tags(tbin)
	required_attribute("validcode")
	required_attribute("username")
	required_attribute("api_key")

	if !@attrib.fetch('isoffline', FALSE) 
		@tagstotal=1;@tagsreturned=1;@first=0;
		
		Net::HTTP.start(%{api.search.yahoo.com}, 80) { |http|
			def nextrequest
				# I'm not too excited about this looping mechanism.  There must be a better way, probably much easier as well.
				while !@stop
					yield
					@first += @tagsreturned
				end
			end
			
			@stop=FALSE
			nextrequest {

				@response = http.get(%{/MyWebService/V1/tagSearch?appid=#{attrib['api_key']}&yahooid=#{attrib['username']}&results=50&start=#{@first+@tagsreturned}})
				
				if @response.code==@attrib['validcode']
					doc=REXML::Document.new @response.body
					@tagstotal=doc.elements[1].attributes["totalResultsAvailable"]
					@tagsreturned=doc.elements[1].attributes["totalResultsReturned"]
					@first=doc.elements[1].attributes["firstResultPosition"]
					
					doc.elements[1].each do |element|
						tbin[element[0].text.downcase] = (tbin.fetch(element[0].text.downcase, 0) + Integer(element[1].text))
					end

					@stop = (@tagsreturned+@first >= @tagstotal)
				else
					@stop=TRUE
					Trutag::loggit(1, %{Received response: #{@response.code} - #{@response.message} from #{@attrib['sitename']}})
				end
			}
			

			
		}
	end
	
	
end