Class: Blekko::Slashtag
- Inherits:
-
Object
- Object
- Blekko::Slashtag
- Defined in:
- lib/blekko-search/slashtag.rb
Instance Attribute Summary collapse
-
#blekko ⇒ Object
Returns the value of attribute blekko.
-
#name ⇒ Object
Returns the value of attribute name.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
- #create! ⇒ Object
- #delete! ⇒ Object
- #delete_url ⇒ Object
-
#initialize(blekko, name, args = {}) ⇒ Slashtag
constructor
A new instance of Slashtag.
- #remove_url(target_urls) ⇒ Object
- #remove_urls!(*target_urls) ⇒ Object
- #save! ⇒ Object
- #save_url(method, target_urls = urls) ⇒ Object
- #saved_urls ⇒ Object
- #update! ⇒ Object
Constructor Details
#initialize(blekko, name, args = {}) ⇒ Slashtag
Returns a new instance of Slashtag.
6 7 8 9 10 11 12 13 14 |
# File 'lib/blekko-search/slashtag.rb', line 6 def initialize(blekko, name, args={}) args = { eager_load: true }.merge(args) @blekko = blekko @name = name @urls = *args[:urls] if args[:eager_load] && urls.empty? self.urls = saved_urls end end |
Instance Attribute Details
#blekko ⇒ Object
Returns the value of attribute blekko.
4 5 6 |
# File 'lib/blekko-search/slashtag.rb', line 4 def blekko @blekko end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/blekko-search/slashtag.rb', line 4 def name @name end |
#urls ⇒ Object
Returns the value of attribute urls.
4 5 6 |
# File 'lib/blekko-search/slashtag.rb', line 4 def urls @urls end |
Instance Method Details
#create! ⇒ Object
45 46 47 |
# File 'lib/blekko-search/slashtag.rb', line 45 def create! blekko.request(save_url("create")) end |
#delete! ⇒ Object
65 66 67 68 |
# File 'lib/blekko-search/slashtag.rb', line 65 def delete! return ArgumentError, "This is not implemented by blekko yet" blekko.reqeust(delete_url) end |
#delete_url ⇒ Object
61 62 63 |
# File 'lib/blekko-search/slashtag.rb', line 61 def delete_url blekko.protocol + blekko.host + "/tag/delete?submit=1&name=#{name}&auth=#{blekko.api_key}" end |
#remove_url(target_urls) ⇒ Object
57 58 59 |
# File 'lib/blekko-search/slashtag.rb', line 57 def remove_url(target_urls) blekko.protocol + blekko.host + "/tag/edit?submit=1&type=del&name=#{name}&urls=#{target_urls.join("%0A")}&auth=#{blekko.api_key}" end |
#remove_urls!(*target_urls) ⇒ Object
39 40 41 42 |
# File 'lib/blekko-search/slashtag.rb', line 39 def remove_urls!(*target_urls) blekko.request(remove_url(target_urls)) true end |
#save! ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/blekko-search/slashtag.rb', line 28 def save! begin if create!.read =~ /already exists/ update! end true rescue false end end |
#save_url(method, target_urls = urls) ⇒ Object
53 54 55 |
# File 'lib/blekko-search/slashtag.rb', line 53 def save_url(method, target_urls=urls) blekko.protocol + blekko.host + "/tag/add?name=#{name}&submit=#{method}&urls=#{urls.join("%0A")}&auth=#{blekko.api_key}" end |
#saved_urls ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/blekko-search/slashtag.rb', line 20 def saved_urls url = blekko.protocol + blekko.host + "/tag/view?name=" + CGI.escape(name) + "&format=text&auth=#{blekko.api_key}" lines = open(url, blekko.headers).collect { |line| line.strip } unless lines.first.scan(" ").any? lines.collect { |line| line } end end |
#update! ⇒ Object
49 50 51 |
# File 'lib/blekko-search/slashtag.rb', line 49 def update! blekko.request(save_url("update")) end |