Class: Soup::Client
- Inherits:
-
Object
- Object
- Soup::Client
- Defined in:
- lib/soup-client/client.rb,
lib/soup-client/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#login ⇒ Object
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#soup_user_id ⇒ Object
Returns the value of attribute soup_user_id.
Instance Method Summary collapse
- #get_default_request ⇒ Object
- #get_session_id(page) ⇒ Object
-
#initialize(login, password) ⇒ Client
constructor
A new instance of Client.
- #new_image(url, description = '') ⇒ Object
- #new_link(url, title = '', description = '') ⇒ Object
- #new_quote(quote, source) ⇒ Object
- #new_text(text, title = '') ⇒ Object
- #new_video(youtube_url, description = '') ⇒ Object
- #post_submit(request) ⇒ Object
- #redirect_session ⇒ Object
Constructor Details
#initialize(login, password) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/soup-client/client.rb', line 7 def initialize(login, password) @login = login @password = password @agent = Soup::Agent.new end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def agent @agent end |
#domain ⇒ Object
Returns the value of attribute domain.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def domain @domain end |
#login ⇒ Object
Returns the value of attribute login.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def password @password end |
#session_id ⇒ Object
Returns the value of attribute session_id.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def session_id @session_id end |
#soup_user_id ⇒ Object
Returns the value of attribute soup_user_id.
5 6 7 |
# File 'lib/soup-client/client.rb', line 5 def soup_user_id @soup_user_id end |
Instance Method Details
#get_default_request ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/soup-client/client.rb', line 36 def get_default_request { 'post[source]' => '', 'post[body]' => '', 'post[id]' => '', 'post[parent_id]' => '', 'post[original_id]' => '', 'post[edited_after_repost]' => '', 'redirect' => '', 'commit' => 'Save' } end |
#get_session_id(page) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/soup-client/client.rb', line 13 def get_session_id(page) = page.headers["set-cookie"] = CGI::Cookie.parse() @session_id = ["soup_session_id"].first @soup_user_id = ["soup_user_id"].first end |
#new_image(url, description = '') ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/soup-client/client.rb', line 66 def new_image(url, description = '') request = get_default_request() request['post[type]'] = 'PostImage' request['post[url]'] = url request['post[source]'] = url request['post[body]'] = description post_submit(request) end |
#new_link(url, title = '', description = '') ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/soup-client/client.rb', line 56 def new_link(url, title = '', description = '') request = get_default_request() request['post[type]'] = 'PostLink' request['post[source]'] = url request['post[title]'] = title request['post[body]'] = description post_submit(request) end |
#new_quote(quote, source) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/soup-client/client.rb', line 85 def new_quote(quote, source) request = get_default_request() request['post[type]'] = 'PostQuote' request['post[body]'] = quote request['post[title]'] = source post_submit(request) end |
#new_text(text, title = '') ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/soup-client/client.rb', line 76 def new_text(text, title = '') request = get_default_request() request['post[type]'] = 'PostRegular' request['post[title]'] = title request['post[body]'] = text post_submit(request) end |
#new_video(youtube_url, description = '') ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/soup-client/client.rb', line 94 def new_video(youtube_url, description = '') request = get_default_request() request['post[type]'] = 'PostVideo' request['post[embedcode_or_url]'] = youtube_url request['post[body]'] = description post_submit(request) end |
#post_submit(request) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/soup-client/client.rb', line 49 def post_submit(request) agent = @agent.faraday("http://#{@login}.soup.io") agent.post('/save', request) do |req| req.headers["Cookie"] = "soup_session_id=#{session_id}" end end |
#redirect_session ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/soup-client/client.rb', line 20 def redirect_session agent.faraday("http://www.soup.io").get do |req| req.url "/remote/generate" req.params['referer'] = "http://www.soup.io/everyone" req.params['host'] = "#{@login}.soup.io" req.params['redirect_to'] = "/" req.headers["Cookie"] = "soup_session_id=#{@session_id}" end.headers['location'] end |