a_parser_client 0.1.0 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +44 -2
- data/lib/a_parser_client.rb +95 -6
- data/lib/a_parser_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42e60203410c99b0db06edc1788deee8e1c4ced464b10ef096e9e03de1676d5
|
4
|
+
data.tar.gz: 0d59de0239b5a7e25adb62591f00d39e235cf845954377e1eeab01ae7f645abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e0a2dc347538a632f42dbd6bc02567636f31295aebfd17944bcd3473138fd80085d4a5bc74cbd506f810c99aadec220ea88ed1740e3ee87a7d93309eddf911
|
7
|
+
data.tar.gz: 3620212938726b6594e8dd8a952b866b506ab01ac6e1a1bcfd348ffd9a9e73155bbc6a7cb4467b2f0bb688983ee25a207630f00829c33910b2f362920f3c29d7
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,36 @@
|
|
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
|
+
|
5
|
+
Ruby client for A-Parser user API.
|
6
|
+
|
7
|
+
This is a test release, more API coverage is upcoming.
|
8
|
+
|
9
|
+
Covered for now:
|
10
|
+
|
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
|
+
|
27
|
+
TODO:
|
28
|
+
|
29
|
+
- oneRequest
|
30
|
+
- bulkRequest
|
31
|
+
|
32
|
+
|
33
|
+
|
3
34
|
## Installation
|
4
35
|
|
5
36
|
Add this line to your application's Gemfile:
|
@@ -18,7 +49,18 @@ Or install it yourself as:
|
|
18
49
|
|
19
50
|
## Usage
|
20
51
|
|
21
|
-
|
52
|
+
There will be a wiki page soon.
|
53
|
+
|
54
|
+
The code sample below is all for now...
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
require 'a_parser_client'
|
58
|
+
|
59
|
+
api = AParserClient::API.new 'http://<your_host_running_aparser>:9091/API, ''
|
60
|
+
api.ping
|
61
|
+
|
62
|
+
$> {"success" : 1, "data" : "pong"}
|
63
|
+
```
|
22
64
|
|
23
65
|
## Development
|
24
66
|
|
@@ -36,4 +78,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
36
78
|
|
37
79
|
## Code of Conduct
|
38
80
|
|
39
|
-
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
|
81
|
+
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).
|
data/lib/a_parser_client.rb
CHANGED
@@ -11,9 +11,13 @@ module AParserClient
|
|
11
11
|
attr :api_url, :api_password, :alive
|
12
12
|
|
13
13
|
def initialize(api_url, api_password)
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
17
21
|
end
|
18
22
|
|
19
23
|
def ping_a_parser
|
@@ -42,7 +46,7 @@ module AParserClient
|
|
42
46
|
def get_task_state(task_id)
|
43
47
|
request = {
|
44
48
|
password: @api_password,
|
45
|
-
action: '
|
49
|
+
action: 'getTaskState',
|
46
50
|
data: {taskUid: task_id}
|
47
51
|
}
|
48
52
|
do_it request
|
@@ -51,7 +55,7 @@ module AParserClient
|
|
51
55
|
def get_task_conf(task_id)
|
52
56
|
request = {
|
53
57
|
password: @api_password,
|
54
|
-
action: '
|
58
|
+
action: 'getTaskConf',
|
55
59
|
data: {taskUid: task_id}
|
56
60
|
}
|
57
61
|
do_it request
|
@@ -94,6 +98,87 @@ module AParserClient
|
|
94
98
|
do_it request
|
95
99
|
end
|
96
100
|
|
101
|
+
def get_accounts_count
|
102
|
+
request = {
|
103
|
+
password: @api_password,
|
104
|
+
action: 'getAccountsCount',
|
105
|
+
data: {}
|
106
|
+
}
|
107
|
+
do_it request
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def get_proxies
|
112
|
+
request = {
|
113
|
+
password: @api_password,
|
114
|
+
action: 'getProxies'
|
115
|
+
}
|
116
|
+
do_it request
|
117
|
+
end
|
118
|
+
|
119
|
+
def update!
|
120
|
+
request = {
|
121
|
+
password: @api_password,
|
122
|
+
action: 'update',
|
123
|
+
data: {}
|
124
|
+
}
|
125
|
+
do_it request
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_task_results_file(task_id)
|
129
|
+
request = {
|
130
|
+
password: @api_password,
|
131
|
+
action: 'getTaskResultsFile',
|
132
|
+
data: {taskUid: task_id}
|
133
|
+
}
|
134
|
+
do_it request
|
135
|
+
end
|
136
|
+
|
137
|
+
def delete_task_results_file(task_id)
|
138
|
+
request = {
|
139
|
+
password: @api_password,
|
140
|
+
action: 'deleteTaskResultsFile',
|
141
|
+
data: {taskUid: task_id}
|
142
|
+
}
|
143
|
+
do_it request
|
144
|
+
end
|
145
|
+
|
146
|
+
def move_task(task_id, direction)
|
147
|
+
request = {
|
148
|
+
password: @api_password,
|
149
|
+
action: 'moveTask',
|
150
|
+
data: {
|
151
|
+
taskUid: task_id,
|
152
|
+
toStatus: direction
|
153
|
+
}
|
154
|
+
}
|
155
|
+
do_it request
|
156
|
+
end
|
157
|
+
|
158
|
+
def get_parser_info(parser_name)
|
159
|
+
request = {
|
160
|
+
password: @api_password,
|
161
|
+
action: 'getParserInfo',
|
162
|
+
data: {
|
163
|
+
parser: parser_name
|
164
|
+
}
|
165
|
+
}
|
166
|
+
do_it request
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
def get_parser_preset(parser_name, preset_name)
|
171
|
+
request = {
|
172
|
+
password: @api_password,
|
173
|
+
action: 'getParserInfo',
|
174
|
+
data: {
|
175
|
+
parser: parser_name,
|
176
|
+
reset: preset_name
|
177
|
+
}
|
178
|
+
}
|
179
|
+
do_it request
|
180
|
+
end
|
181
|
+
|
97
182
|
|
98
183
|
private # internal use only
|
99
184
|
|
@@ -119,7 +204,11 @@ module AParserClient
|
|
119
204
|
end
|
120
205
|
|
121
206
|
if res
|
122
|
-
|
207
|
+
begin
|
208
|
+
response = JSON.parse res.body
|
209
|
+
rescue JSON::ParserError => e
|
210
|
+
raise "Not a JSON type response from the server #{@api_url}. Probably not an API endpoint."
|
211
|
+
end
|
123
212
|
else
|
124
213
|
nil
|
125
214
|
end
|