Class: Ubiquitously::Slideshare::Post

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

Instance Attribute Summary

Attributes inherited from Ubiquitously::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

Instance Method Summary collapse

Methods inherited from Ubiquitously::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

Instance Method Details

#createObject



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ubiquitously/services/slideshare.rb', line 18

def create
  page = agent.get(url)
  
  header = {
    "X-Requested-With" => "XMLHttpRequest",
    "Referer" => token[:url],
    "Accept" => "application/json, text/javascript, */*"
  }
  
  id = page.parser.css(".viralShareItem a.bloggerShare").first["href"].split("/").last
  authenticity_token = page.parser.css("input[name=authenticity_token]").first["value"]
  user_id = agent.get("http://www.slideshare.net/#{user.username_for(self)}").body.match(/\"id\":(\d+)/)[1]
  
  # favorite
  params = {
    "authenticity_token" => authenticity_token,
    "favorite[tag_text]" => token[:tags],
    "slideshow_id" => id,
    "source" => "slideviewer",
    "undefined" => "undefined",
    "user_id" => user_id
  }
  
  result = agent.post("http://www.slideshare.net/favorite/create", params, header)
  
  commented = false
  page.parser.css(".comment").each do |comment|
    if comment["class"].match(/author-(\d+)/)[1].to_s == user_id.to_s
      commented = true
      break
    end
  end
  
  unless commented
    # comment
    params = {
      "authenticity_token" => authenticity_token,
      "followup_email" => "undefined",
      "followup_subscribe" => "1",
      "slide_order" => "1",
      "undefined" => "undefined",
      "version" => 2,
      "slide_id" => id,
      "comment[text]" => token[:description]
    }
    result = agent.post("http://www.slideshare.net/comment/create", params, header)
  end
  
  true
end