soup-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/soup-client.rb +4 -0
- data/lib/soup-client/.client.rb.swp +0 -0
- data/lib/soup-client/agent.rb +22 -0
- data/lib/soup-client/client.rb +103 -0
- data/lib/soup-client/version.rb +5 -0
- data/soup-client.gemspec +19 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Piotr Niełacny
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Soup::Client
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'soup-client'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install soup-client
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/soup-client.rb
ADDED
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module Soup
|
5
|
+
class Agent
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def initialize(domain = 'https://www.soup.io/')
|
9
|
+
@agent ||= faraday(domain)
|
10
|
+
end
|
11
|
+
|
12
|
+
def_delegators :@agent, :get, :post, :response_headers, :body, :status
|
13
|
+
|
14
|
+
def faraday(domain)
|
15
|
+
Faraday.new(url: domain) do |builder|
|
16
|
+
builder.use Faraday::Request::UrlEncoded
|
17
|
+
builder.use Faraday::Response::Logger
|
18
|
+
builder.use Faraday::Adapter::NetHttp
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Soup
|
4
|
+
class Client
|
5
|
+
attr_accessor :login, :password, :domain, :agent, :session_id, :soup_user_id
|
6
|
+
|
7
|
+
def initialize(login, password)
|
8
|
+
@login = login
|
9
|
+
@password = password
|
10
|
+
@agent = Soup::Agent.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_session_id(page)
|
14
|
+
cookie = page.headers["set-cookie"]
|
15
|
+
cookie = CGI::Cookie.parse(cookie)
|
16
|
+
@session_id = cookie["soup_session_id"].first
|
17
|
+
@soup_user_id = cookie["soup_user_id"].first
|
18
|
+
end
|
19
|
+
|
20
|
+
def redirect_session
|
21
|
+
agent.faraday("http://www.soup.io").get do |req|
|
22
|
+
req.url "/remote/generate"
|
23
|
+
req.params['referer'] = "http://www.soup.io/everyone"
|
24
|
+
req.params['host'] = "#{@login}.soup.io"
|
25
|
+
req.params['redirect_to'] = "/"
|
26
|
+
req.headers["Cookie"] = "soup_session_id=#{@session_id}"
|
27
|
+
end.headers['location']
|
28
|
+
end
|
29
|
+
|
30
|
+
def login
|
31
|
+
post = { login: @login, password: @password, commit: 'Log in' }
|
32
|
+
get_session_id(@agent.post('/login', post))
|
33
|
+
get_session_id(@agent.get(redirect_session))
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_default_request
|
37
|
+
{
|
38
|
+
'post[source]' => '',
|
39
|
+
'post[body]' => '',
|
40
|
+
'post[id]' => '',
|
41
|
+
'post[parent_id]' => '',
|
42
|
+
'post[original_id]' => '',
|
43
|
+
'post[edited_after_repost]' => '',
|
44
|
+
'redirect' => '',
|
45
|
+
'commit' => 'Save'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_submit(request)
|
50
|
+
agent = @agent.faraday("http://#{@login}.soup.io")
|
51
|
+
agent.post('/save', request) do |req|
|
52
|
+
req.headers["Cookie"] = "soup_session_id=#{session_id}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def new_link(url, title = '', description = '')
|
57
|
+
request = get_default_request()
|
58
|
+
request['post[type]'] = 'PostLink'
|
59
|
+
request['post[source]'] = url
|
60
|
+
request['post[title]'] = title
|
61
|
+
request['post[body]'] = description
|
62
|
+
|
63
|
+
post_submit(request)
|
64
|
+
end
|
65
|
+
|
66
|
+
def new_image(url, description = '')
|
67
|
+
request = get_default_request()
|
68
|
+
request['post[type]'] = 'PostImage'
|
69
|
+
request['post[url]'] = url
|
70
|
+
request['post[source]'] = url
|
71
|
+
request['post[body]'] = description
|
72
|
+
|
73
|
+
post_submit(request)
|
74
|
+
end
|
75
|
+
|
76
|
+
def new_text(text, title = '')
|
77
|
+
request = get_default_request()
|
78
|
+
request['post[type]'] = 'PostRegular'
|
79
|
+
request['post[title]'] = title
|
80
|
+
request['post[body]'] = text
|
81
|
+
|
82
|
+
post_submit(request)
|
83
|
+
end
|
84
|
+
|
85
|
+
def new_quote(quote, source)
|
86
|
+
request = get_default_request()
|
87
|
+
request['post[type]'] = 'PostQuote'
|
88
|
+
request['post[body]'] = quote
|
89
|
+
request['post[title]'] = source
|
90
|
+
|
91
|
+
post_submit(request)
|
92
|
+
end
|
93
|
+
|
94
|
+
def new_video(youtube_url, description = '')
|
95
|
+
request = get_default_request()
|
96
|
+
request['post[type]'] = 'PostVideo'
|
97
|
+
request['post[embedcode_or_url]'] = youtube_url
|
98
|
+
request['post[body]'] = description
|
99
|
+
|
100
|
+
post_submit(request)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/soup-client.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/soup-client/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Piotr Niełacny"]
|
6
|
+
gem.email = ["piotr.nielacny@gmail.com"]
|
7
|
+
gem.description = %q{soup.io client}
|
8
|
+
gem.summary = %q{soup.io client}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "soup-client"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Soup::Client::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("faraday")
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: soup-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Piotr Niełacny
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: &19081880 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *19081880
|
25
|
+
description: soup.io client
|
26
|
+
email:
|
27
|
+
- piotr.nielacny@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/soup-client.rb
|
38
|
+
- lib/soup-client/.client.rb.swp
|
39
|
+
- lib/soup-client/agent.rb
|
40
|
+
- lib/soup-client/client.rb
|
41
|
+
- lib/soup-client/version.rb
|
42
|
+
- soup-client.gemspec
|
43
|
+
homepage: ''
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.15
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: soup.io client
|
67
|
+
test_files: []
|
68
|
+
has_rdoc:
|