gscomp 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/lib/gscomp/version.rb +1 -1
  2. data/lib/gscomp.rb +36 -26
  3. metadata +3 -5
  4. data/bin/gscomp +0 -8
@@ -1,3 +1,3 @@
1
1
  module Gscomp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/gscomp.rb CHANGED
@@ -11,7 +11,10 @@ require 'gtk2'
11
11
 
12
12
 
13
13
  module Gscomp
14
- class Taras
14
+ HostAddress = 'http://localhost:3000/' # 'http://195.230.96.80/'
15
+ HostAuth = {:login => 'tester', :passwd => 'qwzxas'}
16
+
17
+ class Prices
15
18
  private
16
19
  def initialize
17
20
  # Разрешаем отображение окна со всеми дочерними элементами
@@ -84,7 +87,6 @@ module Gscomp
84
87
  end
85
88
  end
86
89
  pref.destroy
87
-
88
90
  end
89
91
 
90
92
  def on_click_about
@@ -104,24 +106,26 @@ module Gscomp
104
106
  # Инициализация
105
107
  def get_client_id
106
108
  # Регистрация на сервере
107
- uri = URI.parse('http://localhost:3000/idfactory')
108
- uri.user = 'tester'
109
- uri.password = 'qwzxas'
110
- begin
111
- Net::HTTP.get(uri)
112
- rescue
113
- nil
114
- end
109
+ uri = URI.parse(HostAddress + 'idfactory')
110
+ Net::HTTP.start(uri.host, uri.port) {|http|
111
+ req = Net::HTTP::Get.new(uri.path)
112
+ req.basic_auth HostAuth[:login], HostAuth[:passwd]
113
+ response = http.request(req)
114
+ response.body
115
+ }
115
116
  end
116
117
 
117
118
  # Запрос задания
118
119
  def get_job (client_id)
119
- uri = URI.parse('http://localhost:3000/products')
120
- uri.user = 'tester'
121
- uri.password = 'qwzxas'
122
- uri.query = URI.encode_www_form({:id => client_id})
120
+ uri = URI.parse(HostAddress + 'products')
123
121
  begin
124
- JSON::parse(Net::HTTP.get(uri))
122
+ Net::HTTP.start(uri.host, uri.port) {|http|
123
+ req = Net::HTTP::Get.new(uri.path)
124
+ req.basic_auth HostAuth[:login], HostAuth[:passwd]
125
+ req.set_form_data({:client_id => client_id})
126
+ response = http.request(req)
127
+ JSON::parse(response.body)
128
+ }
125
129
  rescue
126
130
  nil
127
131
  end
@@ -240,7 +244,8 @@ module Gscomp
240
244
  :price => price.nil? ? '' : price[:price],
241
245
  :currency => price.nil? ? '' : price[:currency],
242
246
  :page_id => r['page_id'].to_s,
243
- :link => r['link']
247
+ :link => r['link'],
248
+ :good => (name.length > 0 and price[:price].length > 0 and price[:currency].length > 0).to_s
244
249
  }
245
250
  end
246
251
  @processed += 1
@@ -250,15 +255,19 @@ module Gscomp
250
255
 
251
256
  # Отправка результатов
252
257
  def send_job(result)
253
- uri = URI.parse('http://localhost:3000/products')
254
- uri.user = 'tester'
255
- uri.password = 'qwzxas'
256
- return Net::HTTP.post_form(uri, {:result => result.to_json})
258
+ uri = URI.parse(HostAddress + 'products')
259
+ req = Net::HTTP::Post.new(uri.path)
260
+ req.basic_auth HostAuth[:login], HostAuth[:passwd]
261
+ req.set_form_data({:result => result.to_json})
262
+ Net::HTTP.new(uri.host, uri.port).start {|http|
263
+ http.request(req)
264
+ }
257
265
  end
266
+
258
267
  public
259
268
  def process_packet
260
269
  sleep 1 while not (client_id = get_client_id())
261
- #puts client_id
270
+ puts client_id
262
271
 
263
272
  attempt = 10
264
273
  sleep 1 while not (job = get_job(client_id) and attempt -= 1)
@@ -266,7 +275,7 @@ module Gscomp
266
275
  # puts job
267
276
 
268
277
  records = process_job(job)
269
- # puts records
278
+ puts records
270
279
 
271
280
  result = {
272
281
  :client_id => client_id,
@@ -277,20 +286,21 @@ module Gscomp
277
286
  send_result = send_job(result)
278
287
  case send_result
279
288
  when Net::HTTPSuccess, Net::HTTPRedirection
280
- p 'Good'
289
+ p "Ответ - " + send_result.body
281
290
  else
282
291
  # p result.error
283
292
  end
284
293
  end
285
294
 
286
295
  def main
287
- uu = Thread.new do
296
+ # uu = Thread.new do
288
297
  # Запускаем цикл обработки событий
289
298
  loop do
290
299
  process_packet()
291
300
  sleep @power
292
- end
293
- end
301
+ end
302
+ #end
303
+
294
304
 
295
305
  GLib::Timeout.add(1000) { on_timer }
296
306
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gscomp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,13 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-16 00:00:00.000000000Z
12
+ date: 2012-06-20 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: GS computation
15
15
  email:
16
16
  - gs@gmail.com
17
- executables:
18
- - gscomp
17
+ executables: []
19
18
  extensions: []
20
19
  extra_rdoc_files: []
21
20
  files:
@@ -23,7 +22,6 @@ files:
23
22
  - Gemfile
24
23
  - README.md
25
24
  - Rakefile
26
- - bin/gscomp
27
25
  - gscomp.gemspec
28
26
  - gscomp.sublime-project
29
27
  - gscomp.sublime-workspace
data/bin/gscomp DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- system("gem install gscomp")
4
-
5
- require 'gscomp'
6
-
7
- tt = Gscomp::Taras.new()
8
- tt.main()