Class: Ubiquitously::Faves::Post

Inherits:
Service::Post show all
Defined in:
lib/ubiquitously/services/faves.rb

Instance Attribute Summary

Attributes inherited from Service::Post

#captcha, #categories, #description, #downvotes, #extension, #format, #image, #kind, #must_be_unique, #privacy, #rating, #remote, #service_id, #service_url, #slug, #source, #source_url, #state, #status, #tags, #title, #token, #upvotes, #url, #user, #vote

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Service::Post

#access_token, #initialize

Methods included from Loggable::Post

included

Methods included from Restful::Post

included

Methods included from Postable::Post

included

Methods included from Ownable::Post

included

Methods inherited from Base

#apply, #debug?

Methods included from SubclassableCallbacks

included, override

Constructor Details

This class inherits a constructor from Ubiquitously::Service::Post

Class Method Details

.find(options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ubiquitously/services/faves.rb', line 51

def find(options = {})
  result = []
  user = options[:user]
  user_url = "http://faves.com/users/#{user.username_for(self)}"
  html = Nokogiri::HTML(open(user_url).read)
  
  html.css(".userDotList li").each do |node|
    next if node["id"].blank?
    url = node.css(".note > a").first["href"]
    title = node.css(".note > p").first.text
    tags = []
    node.xpath("a").each do |tag|
      tags << tag.text if tag["class"].blank?
    end
    record = new(
      :title => title,
      :url => url,
      :tags => tags
    )
    if options[:url] && options[:url] == record.url
      return record
    end
    result << record
  end
  
  options[:url] ? nil : result
end

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ubiquitously/services/faves.rb', line 17

def create
  page = agent.get("http://faves.com/createdot.aspx")
  form = page.form_with(:name => "createDotForm")
  form["noteText"] = description
  form["urlText"] = url
  form["subjectText"] = title
  form["tagsText"] = tags.join(", ")
  form.field_with(:name => "rateSelect").options.each do |option|
    option.select if option.value.to_s == "5"
  end
  form.field_with(:name => "shareSelect").options.each do |option|
    option.select if option.value.to_s.downcase == "public"
  end
  # hidden fields they fill out with javascript
#        form["imageUrl"] = "http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"
#        form["imageWidth"] = "149"
#        form["imageHeight"] = "149"
  # just before you submit the form they append the current time, so they have a range.
  # mimic the range of time :)
  form["authoringExpiry"] = form["authoringExpiry"] + "loadedtime=#{1.minute.ago.to_i * 1000}publishedtime=#{Time.now.to_i * 1000}"
  headers = {
    "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "Keep-Alive" => "115",
    "Accept-Encoding" => "gzip,deflate"
  }
  
  unless debug?
    page = form.submit(nil, headers)
  end
  
  self
end