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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 795b81d4f6d3ea0e71c8b64f72ec017c1945aa6c25b8ce72448a7ad96d20e10e
4
- data.tar.gz: 4fa2df5c11b3600bc7d407b9a44a550bf6b90dbcef44a790f484045022936d1c
3
+ metadata.gz: f42e60203410c99b0db06edc1788deee8e1c4ced464b10ef096e9e03de1676d5
4
+ data.tar.gz: 0d59de0239b5a7e25adb62591f00d39e235cf845954377e1eeab01ae7f645abe
5
5
  SHA512:
6
- metadata.gz: a15d99d21f04edec68444041d513b38447e360a6415682ba1c661133c21bbe6bf109253df0b83ae1484110f9b2a884ca983fc934bbcec70a4ab68c64273e171d
7
- data.tar.gz: e8fe26165e168f2b10ca8ade13b09650c5b7506f0e5d1067ab3254bf0d5f4253baca5fb59fbf88757adfefe4298ab0141759aa63173149cbd5aa793bfc5f98e2
6
+ metadata.gz: 68e0a2dc347538a632f42dbd6bc02567636f31295aebfd17944bcd3473138fd80085d4a5bc74cbd506f810c99aadec220ea88ed1740e3ee87a7d93309eddf911
7
+ data.tar.gz: 3620212938726b6594e8dd8a952b866b506ab01ac6e1a1bcfd348ffd9a9e73155bbc6a7cb4467b2f0bb688983ee25a207630f00829c33910b2f362920f3c29d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- a_parser_client (0.1.0)
4
+ a_parser_client (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- TODO: Write usage instructions here
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 /a_parser_client/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -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
- @api_url = api_url
15
- @api_password = api_password
16
- @alive = self.alive? #fails whenever url is bad
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: 'getTasksState',
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: 'getTasksConf',
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
- response = JSON.parse res.body
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
@@ -1,3 +1,3 @@
1
1
  module AParserClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a_parser_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Shevchenko