apify_server 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +2 -0
- data/apify_server.gemspec +25 -0
- data/bin/apify-server +9 -0
- data/lib/apify_server.rb +45 -0
- data/lib/apify_server/version.rb +5 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7831d569c3ecde93dc5d987e5940530bea7d5cf8
|
4
|
+
data.tar.gz: ccb5ac6d1a578f6dcbf42860fb595104cfec4711
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba116c8e3f37391284e0b563b16d7357bf45c59461cf14f9349dcd87f966fa28db295dece2500f6b73bef8a54817c69eab8facac6793bbea4510b11ae8ab2060
|
7
|
+
data.tar.gz: 2529353cbe789dca3a5f4551eab495e2df5e570a406f4d40dbf423ee33344d5ca2b642e35d102965928f6211df9f9262a3848980b4f0bce854586ee451088857
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 victorvsk
|
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,30 @@
|
|
1
|
+
# Server
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install gem:
|
8
|
+
|
9
|
+
$ gem install apify_server
|
10
|
+
|
11
|
+
## Prepare
|
12
|
+
|
13
|
+
$ apify-server
|
14
|
+
|
15
|
+
## Use
|
16
|
+
|
17
|
+
$ echo 'secret' > ~/.apify_secret
|
18
|
+
|
19
|
+
$ curl -X POST \
|
20
|
+
> -H "Content-type: application/json" \
|
21
|
+
> -d '{ "html": "<div id='title'>text</div>", "pattern": { "title": "<% #title | first | html %>" }}' \
|
22
|
+
> http://0.0.0.0:4567/parser?apify_secret=secret
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/victorvsk/apify-server/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'apify_server/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "apify_server"
|
8
|
+
spec.version = Apify::Server::VERSION
|
9
|
+
spec.authors = ["victorvsk"]
|
10
|
+
spec.email = ["victor@vyskrebentsev.ru"]
|
11
|
+
spec.summary = %q{Apify Server is a part of Apify Project. It creates daemon using Sinatra.}
|
12
|
+
spec.description = %q{A simple way to create multiple nodes on any server to response on your Apify-Requests}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_dependency "apify_core"
|
25
|
+
end
|
data/bin/apify-server
ADDED
data/lib/apify_server.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require "apify_server/version"
|
3
|
+
require 'apify_core'
|
4
|
+
|
5
|
+
module Apify
|
6
|
+
module Server
|
7
|
+
|
8
|
+
class Node < Sinatra::Base
|
9
|
+
set :apify_secret, File.read("#{ENV['HOME']}/.apify_secret")
|
10
|
+
|
11
|
+
before do
|
12
|
+
content_type 'application/json'
|
13
|
+
if params['apify_secret'] == settings.apify_secret
|
14
|
+
pass
|
15
|
+
else
|
16
|
+
sleep(rand(1000...2000) / 1000)
|
17
|
+
halt 403, {'Content-Type' => 'application/json'}, { status: 0, message: 'Invalid API key'}.to_json
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
post '/crawler' do
|
23
|
+
json = JSON.parse(request.body.read)
|
24
|
+
response = Apify::Core.crawl!(json, params['processes'].to_i, params['delay'].to_i)
|
25
|
+
if params['return'] and response.sources.include?(params['return'])
|
26
|
+
response.send(params['return']).to_json
|
27
|
+
else
|
28
|
+
response.to_json
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
post '/test-api-key' do
|
33
|
+
{ status: '1', message: 'API key is valid.' }.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
post '/parser' do
|
37
|
+
json = JSON.parse(request.body.read)
|
38
|
+
html = json['html']
|
39
|
+
pattern = json['pattern']
|
40
|
+
Apify::Core::Parser.new(html, pattern).perform.to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: apify_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- victorvsk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: apify_core
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A simple way to create multiple nodes on any server to response on your
|
56
|
+
Apify-Requests
|
57
|
+
email:
|
58
|
+
- victor@vyskrebentsev.ru
|
59
|
+
executables:
|
60
|
+
- apify-server
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- apify_server.gemspec
|
70
|
+
- bin/apify-server
|
71
|
+
- lib/apify_server.rb
|
72
|
+
- lib/apify_server/version.rb
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Apify Server is a part of Apify Project. It creates daemon using Sinatra.
|
97
|
+
test_files: []
|