a_parser_client 0.1.3 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc4f9ce094b307b0dd2498562c9b3fed6046550336547e894c75fc480dbfe52
4
- data.tar.gz: fea8994be0bfb6ecb417fbabf5c4c956aa71d21b3e2543ea0a1777d9ff0e0525
3
+ metadata.gz: 8a8bc499efb525fbec81f9baf371d53996c8b161ff84be8bf99d5716a1fd4bdc
4
+ data.tar.gz: 828b64103b24b88d37215e47b4ff218fe0792d61332bdd4a73d239b65e7255aa
5
5
  SHA512:
6
- metadata.gz: 0b752657ce7da0730c2b374ded49bd58031b23a55bc0b18b5f71db130c8ca5bb54dd842226d8b68e00cf32dac418d5baec6dc2cd3d0d7207a52f7aa68e5cec10
7
- data.tar.gz: e2ce75960aae66819ba31e785b9a368178dd9aae2e08a1897a1c112158f3e16fc63ddd42cd642cb50b483a0a1e75b81e6c4225cdc7635d2ec080a40de8301cf2
6
+ metadata.gz: 7ebb4925c0aaf3dc294966d36e26bc189b1b6474a9c7071f6bd7f4737c032ae74fec440fc9879d6fc4ddef97889e38e36607ea00d90abe941a346bd9155e6540
7
+ data.tar.gz: 9406200c8dc40bd5bf51e3334243c6d32c67be0d4c39eb5e3bdba3cc63f9a5bfe9373dea43ff66cd9c13b479321ded812dcdc8325c3fa40baa149963474f7c01
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- a_parser_client (0.1.3)
4
+ a_parser_client (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,31 +1,37 @@
1
1
  # AParserClient
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/a_parser_client.svg)](https://badge.fury.io/rb/a_parser_client)
4
+
3
5
  Ruby client for A-Parser user API.
4
6
 
5
7
  This is a test release, more API coverage is upcoming.
6
8
 
7
9
  Covered for now:
8
10
 
9
- - ping
10
- - info
11
- - getTaskList
12
- - getTaskState
13
- - getTaskConf
14
- - addTask
15
- - changeTaskStatus
11
+ - ping
12
+ - info
13
+ - getTaskList
14
+ - getTaskState
15
+ - getTaskConf
16
+ - addTask
17
+ - changeTaskStatus
18
+ - getAccountsCount
19
+ - getProxies
20
+ - update
21
+ - getTaskResultsFile
22
+ - deleteTaskResultsFile
23
+ - moveTask
24
+ - getParserInfo
25
+ - getParserPreset
26
+ - oneRequest
27
+ - bulkRequest
16
28
 
17
29
  TODO:
18
30
 
19
- - oneRequest
20
- - bulkRequest
21
- - getParserPreset
22
- - getProxies
23
- - getTaskResultsFile
24
- - deleteTaskResultsFile
25
- - moveTask
26
- - getParserInfo
27
- - update
28
- - getAccountsCount
31
+ Some automation procedures:
32
+
33
+ - multitasks operations (like stop all tasks etc.)
34
+
29
35
 
30
36
  ## Installation
31
37
 
@@ -45,13 +51,17 @@ Or install it yourself as:
45
51
 
46
52
  ## Usage
47
53
 
54
+ There will be a wiki page soon.
55
+
56
+ The code sample below is all for now...
57
+
48
58
  ```ruby
49
59
  require 'a_parser_client'
50
60
 
51
- api = AParserClient::API.new 'http://142.54.182.130:9091/API, ''
52
- api.ping
61
+ api = AParserClient::API.new 'http://<your_host_running_aparser>:9091/API, ''
62
+ api.ping
53
63
 
54
- $> {"success" : 1, "data" : "pong"}
64
+ => {"success" : 1, "data" : "pong"}
55
65
  ```
56
66
 
57
67
  ## Development
@@ -70,4 +80,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
70
80
 
71
81
  ## Code of Conduct
72
82
 
73
- Everyone interacting in the AParserClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yvshevchenko /a_parser_client/blob/master/CODE_OF_CONDUCT.md).
83
+ Everyone interacting in the AParserClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/yvshevchenko/a_parser_client/blob/master/CODE_OF_CONDUCT.md).
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Yaroslav Shevchenko"]
9
9
  spec.email = ["yvshevchenko@gmail.com"]
10
10
 
11
- spec.summary = %q{A simple inerface to a-parser API.}
12
- spec.description = %q{Gem allowing to use a-parser API simple way.}
11
+ spec.summary = %q{A simple inerface to A-Parser API.}
12
+ spec.description = %q{Gem allowing to use A-Parser API simple way.}
13
13
  spec.homepage = "https://github.com/yvshevchenko/a_parser_client"
14
14
  spec.license = "MIT"
15
15
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
19
  spec.metadata["source_code_uri"] = "https://github.com/yvshevchenko/a_parser_client"
20
- spec.metadata["changelog_uri"] = "https://github.com/yvshevchenko/a_parser_client"
20
+ spec.metadata["changelog_uri"] = "https://github.com/yvshevchenko/a_parser_client/wiki/Changes-Log"
21
21
 
22
22
  # Specify which files should be added to the gem when it is released.
23
23
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -1,138 +1,28 @@
1
1
  require "a_parser_client/version"
2
+ require "a_parser_client/api"
2
3
 
3
4
  module AParserClient
4
- class Error < StandardError; end
5
+ class Error < StandardError; end
5
6
 
6
- class API
7
- require "json"
8
- require "open-uri"
9
- require "net/http"
7
+ class Control
8
+ attr_reader :tasks
10
9
 
11
- attr :api_url, :api_password, :alive
12
-
13
- def initialize(api_url, api_password)
14
- if api_url =~ URI::regexp
15
- @api_url = api_url
16
- @api_password = api_password
17
- @alive = self.alive?
18
- else
19
- raise "Bad API URL provided."
20
- end
21
- end
22
-
23
- def ping_a_parser
24
- request = {
25
- password: @api_pass,
26
- action: 'ping'
27
- }
28
- do_it request
29
- end
30
-
31
- #updates alive status
32
- def alive?
33
- @alive = ping_a_parser ? true : false
34
- end
35
-
36
-
37
- def get_task_list(completed=false)
38
- request = {
39
- password: @api_password,
40
- action: 'getTasksList',
41
- data: {completed: completed ? 1 : 0}
42
- }
43
- do_it request
44
- end
45
-
46
- def get_task_state(task_id)
47
- request = {
48
- password: @api_password,
49
- action: 'getTaskState',
50
- data: {taskUid: task_id}
51
- }
52
- do_it request
53
- end
54
-
55
- def get_task_conf(task_id)
56
- request = {
57
- password: @api_password,
58
- action: 'getTaskConf',
59
- data: {taskUid: task_id}
60
- }
61
- do_it request
62
- end
63
-
64
-
65
- def get_info
66
- request = {
67
- password: @api_password,
68
- action: 'info',
69
- }
70
- do_it request
71
- end
72
-
73
- def add_task(task_type='text', queries_array=[], queries_file=nil, config, preset, parsers, result_file_name)
74
- request = {
75
- password: @api_password,
76
- action: 'addTask',
77
- data: {
78
- queriesFrom: task_type,
79
- queries: (task_type == 'text' ? queries_array : queries_file),
80
- configPreset: config,
81
- preset: preset,
82
- parsers: parsers,
83
- resultsFileName: result_file_name
84
- }
85
- }
86
- do_it request
87
- end
88
-
89
- def change_task_status(task_id, to_status)
90
- request = {
91
- password: @api_password,
92
- action: 'changeTaskStatus',
93
- data: {
94
- taskUid: task_id,
95
- toStatus: to_status
96
- }
97
- }
98
- do_it request
99
- end
10
+ def initialize(api_driver)
11
+ if api_driver
12
+ unless api_driver.alive?
13
+ raise "API driver should be alive to take control of parser."
14
+ end
100
15
 
16
+ @tasks = fetch_tasks
17
+ else
18
+ raise "No API driver provided."
19
+ end
101
20
 
102
- private # internal use only
21
+ end
103
22
 
104
- def do_it(request)
105
- request_body = request.to_json
106
- response = send_request(request_body)
107
- return response
23
+ def fetch_tasks
24
+ data = api_driver.get_tasks_list
25
+ data['data'] ? data['data'] : []
26
+ end
108
27
  end
109
-
110
- def send_request(request)
111
- uri = URI @api_url
112
-
113
- req = Net::HTTP::Post.new uri
114
- req.body = (request)
115
- req.content_type = 'text/plain; charset=UTF-8'
116
-
117
- begin
118
- res = Net::HTTP.start(uri.hostname, uri.port) {|http|
119
- http.request(req)
120
- }
121
- rescue Exception => e
122
- puts "Send request error: #{e}"
123
- end
124
-
125
- if res
126
- begin
127
- response = JSON.parse res.body
128
- rescue JSON::ParserError => e
129
- raise "Not a JSON type response from the server #{@api_url}. Probably not an API endpoint."
130
- end
131
- else
132
- nil
133
- end
134
- end
135
-
136
-
137
- end
138
28
  end
@@ -0,0 +1,253 @@
1
+ module AParserClient
2
+
3
+ class API
4
+ require "json"
5
+ require "open-uri"
6
+ require "net/http"
7
+
8
+ attr :api_url, :api_password, :alive
9
+
10
+ def initialize(api_url, api_password)
11
+ if api_url =~ URI::regexp
12
+ @api_url = api_url
13
+ @api_password = api_password
14
+ @alive = self.alive?
15
+ else
16
+ raise "Bad API URL provided."
17
+ end
18
+ end
19
+
20
+ def ping
21
+ request = {
22
+ password: @api_pass,
23
+ action: 'ping'
24
+ }
25
+ do_it request
26
+ end
27
+
28
+ #updates alive status
29
+ def alive?
30
+ @alive = ping ? true : false
31
+ end
32
+
33
+
34
+ def get_tasks_list(completed=false)
35
+ request = {
36
+ password: @api_password,
37
+ action: 'getTasksList',
38
+ data: {completed: completed ? 1 : 0}
39
+ }
40
+ do_it request
41
+ end
42
+
43
+ def get_task_state(task_id)
44
+ request = {
45
+ password: @api_password,
46
+ action: 'getTaskState',
47
+ data: {taskUid: task_id}
48
+ }
49
+ do_it request
50
+ end
51
+
52
+ def get_task_conf(task_id)
53
+ request = {
54
+ password: @api_password,
55
+ action: 'getTaskConf',
56
+ data: {taskUid: task_id}
57
+ }
58
+ do_it request
59
+ end
60
+
61
+
62
+ def get_info
63
+ request = {
64
+ password: @api_password,
65
+ action: 'info',
66
+ }
67
+ do_it request
68
+ end
69
+
70
+ def add_task(task_type='text', queries_array=[], queries_file=nil, config, preset, parsers, result_file_name)
71
+ request = {
72
+ password: @api_password,
73
+ action: 'addTask',
74
+ data: {
75
+ queriesFrom: task_type,
76
+ queries: (task_type == 'text' ? queries_array : queries_file),
77
+ configPreset: config,
78
+ preset: preset,
79
+ parsers: parsers,
80
+ resultsFileName: result_file_name
81
+ }
82
+ }
83
+ do_it request
84
+ end
85
+
86
+
87
+ def one_request(query, parser, preset='default', config_preset='default', options=[])
88
+ request = {
89
+ password: @api_password,
90
+ action: 'oneRequest',
91
+ data: {
92
+ query: query,
93
+ parser: parser,
94
+ configPreset: config_preset,
95
+ preset: preset,
96
+ options: options
97
+ }
98
+ }
99
+ do_it request
100
+ end
101
+
102
+ def bulk_request(queries, parser, preset, config_preset, threads, raw_results, need_data, options)
103
+ request = {
104
+ password: @api_password,
105
+ action: 'bulkRequest',
106
+ data: {
107
+ queries: queries,
108
+ parser: parser,
109
+ configPreset: config_preset,
110
+ preset: preset,
111
+ threads: threads,
112
+ rawResults: raw_results,
113
+ needData: need_data,
114
+ options: options
115
+ }
116
+ }
117
+ do_it request
118
+ end
119
+
120
+
121
+ def change_task_status(task_id, to_status)
122
+ request = {
123
+ password: @api_password,
124
+ action: 'changeTaskStatus',
125
+ data: {
126
+ taskUid: task_id,
127
+ toStatus: to_status
128
+ }
129
+ }
130
+ do_it request
131
+ end
132
+
133
+ def get_accounts_count
134
+ request = {
135
+ password: @api_password,
136
+ action: 'getAccountsCount',
137
+ data: {}
138
+ }
139
+ do_it request
140
+ end
141
+
142
+
143
+ def get_proxies
144
+ request = {
145
+ password: @api_password,
146
+ action: 'getProxies'
147
+ }
148
+ do_it request
149
+ end
150
+
151
+ def update!
152
+ request = {
153
+ password: @api_password,
154
+ action: 'update',
155
+ data: {}
156
+ }
157
+ do_it request
158
+ end
159
+
160
+ def get_task_results_file(task_id)
161
+ request = {
162
+ password: @api_password,
163
+ action: 'getTaskResultsFile',
164
+ data: {taskUid: task_id}
165
+ }
166
+ do_it request
167
+ end
168
+
169
+ def delete_task_results_file(task_id)
170
+ request = {
171
+ password: @api_password,
172
+ action: 'deleteTaskResultsFile',
173
+ data: {taskUid: task_id}
174
+ }
175
+ do_it request
176
+ end
177
+
178
+ def move_task(task_id, direction)
179
+ request = {
180
+ password: @api_password,
181
+ action: 'moveTask',
182
+ data: {
183
+ taskUid: task_id,
184
+ toStatus: direction
185
+ }
186
+ }
187
+ do_it request
188
+ end
189
+
190
+ def get_parser_info(parser_name)
191
+ request = {
192
+ password: @api_password,
193
+ action: 'getParserInfo',
194
+ data: {
195
+ parser: parser_name
196
+ }
197
+ }
198
+ do_it request
199
+ end
200
+
201
+
202
+ def get_parser_preset(parser_name, preset_name)
203
+ request = {
204
+ password: @api_password,
205
+ action: 'getParserInfo',
206
+ data: {
207
+ parser: parser_name,
208
+ reset: preset_name
209
+ }
210
+ }
211
+ do_it request
212
+ end
213
+
214
+
215
+ private # internal use only
216
+
217
+ def do_it(request)
218
+ request_body = request.to_json
219
+ response = send_request(request_body)
220
+ return response
221
+ end
222
+
223
+ def send_request(request)
224
+ uri = URI @api_url
225
+
226
+ req = Net::HTTP::Post.new uri
227
+ req.body = (request)
228
+ req.content_type = 'text/plain; charset=UTF-8'
229
+
230
+ begin
231
+ res = Net::HTTP.start(uri.hostname, uri.port) {|http|
232
+ http.request(req)
233
+ }
234
+ rescue Exception => e
235
+ puts "Send request error: #{e}"
236
+ end
237
+
238
+ if res
239
+ begin
240
+ response = JSON.parse res.body
241
+ rescue JSON::ParserError => e
242
+ raise "Not a JSON type response from the server #{@api_url}. Probably not an API endpoint."
243
+ end
244
+ else
245
+ nil
246
+ end
247
+ end
248
+
249
+
250
+ end
251
+
252
+
253
+ end
@@ -1,3 +1,3 @@
1
1
  module AParserClient
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a_parser_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shevchenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-24 00:00:00.000000000 Z
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Gem allowing to use a-parser API simple way.
55
+ description: Gem allowing to use A-Parser API simple way.
56
56
  email:
57
57
  - yvshevchenko@gmail.com
58
58
  executables: []
@@ -72,6 +72,7 @@ files:
72
72
  - bin/console
73
73
  - bin/setup
74
74
  - lib/a_parser_client.rb
75
+ - lib/a_parser_client/api.rb
75
76
  - lib/a_parser_client/version.rb
76
77
  homepage: https://github.com/yvshevchenko/a_parser_client
77
78
  licenses:
@@ -80,7 +81,7 @@ metadata:
80
81
  allowed_push_host: https://rubygems.org
81
82
  homepage_uri: https://github.com/yvshevchenko/a_parser_client
82
83
  source_code_uri: https://github.com/yvshevchenko/a_parser_client
83
- changelog_uri: https://github.com/yvshevchenko/a_parser_client
84
+ changelog_uri: https://github.com/yvshevchenko/a_parser_client/wiki/Changes-Log
84
85
  post_install_message:
85
86
  rdoc_options: []
86
87
  require_paths:
@@ -100,5 +101,5 @@ rubyforge_project:
100
101
  rubygems_version: 2.7.7
101
102
  signing_key:
102
103
  specification_version: 4
103
- summary: A simple inerface to a-parser API.
104
+ summary: A simple inerface to A-Parser API.
104
105
  test_files: []