Class: Sitethree::Search
- Inherits:
-
Object
- Object
- Sitethree::Search
- Defined in:
- lib/sitethree.rb
Class Attribute Summary collapse
-
.errors ⇒ Object
Returns the value of attribute errors.
-
.feed_id ⇒ Object
Returns the value of attribute feed_id.
-
.keywords ⇒ Object
Returns the value of attribute keywords.
-
.publisher_id ⇒ Object
Returns the value of attribute publisher_id.
-
.source ⇒ Object
Returns the value of attribute source.
-
.user_agent ⇒ Object
Returns the value of attribute user_agent.
-
.user_ip ⇒ Object
Returns the value of attribute user_ip.
Instance Method Summary collapse
- #get_ads(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Search
constructor
A new instance of Search.
Constructor Details
#initialize(options = {}) ⇒ Search
Returns a new instance of Search.
16 17 18 19 |
# File 'lib/sitethree.rb', line 16 def initialize( = {}) self.class.publisher_id = [:publisher_id] self.class.feed_id = [:feed_id] end |
Class Attribute Details
.errors ⇒ Object
Returns the value of attribute errors.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def errors @errors end |
.feed_id ⇒ Object
Returns the value of attribute feed_id.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def feed_id @feed_id end |
.keywords ⇒ Object
Returns the value of attribute keywords.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def keywords @keywords end |
.publisher_id ⇒ Object
Returns the value of attribute publisher_id.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def publisher_id @publisher_id end |
.source ⇒ Object
Returns the value of attribute source.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def source @source end |
.user_agent ⇒ Object
Returns the value of attribute user_agent.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def user_agent @user_agent end |
.user_ip ⇒ Object
Returns the value of attribute user_ip.
12 13 14 |
# File 'lib/sitethree.rb', line 12 def user_ip @user_ip end |
Instance Method Details
#get_ads(params = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sitethree.rb', line 21 def get_ads(params = {}) ads = [] url = "#{API_URL}?partner_id=#{self.class.publisher_id}&feed_id=#{self.class.feed_id}&source=#{CGI::escape(params[:source])}&user_ip=#{params[:user_ip]}&user_agent=#{CGI::escape(params[:user_agent])}&keywords=#{CGI::escape(params[:keywords])}#{params[:testapi] ? "&test=testapi" : ""}" uri = URI.parse(url) response = Net::HTTP.get_response(uri) doc = Nokogiri::XML.parse(response.body) response = doc.xpath("/response").first if response.attr("valid_request") == "true" && response.attr("num_results") != '0' doc.xpath("//ad").each do |ad| ads << {'title' => ad.attr("title"), 'description' => ad.attr("description"), 'display_url' => ad.attr("display_url"), 'click_url' => ad.text.strip} end else Rails.logger.info url end ads end |