tryphon-pige-client 1.0.2 → 1.0.3

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.
@@ -5,7 +5,10 @@ module Pige::Client
5
5
  time_attribute :begin, :end
6
6
 
7
7
  def completion_rate
8
- self.class.get("#{Pige::Client.box_url}/sources/1/chunks/#{id}.json")["completion_rate"].to_f
8
+ response = self.class.get("#{Pige::Client.box_url}/sources/1/chunks/#{id}.json")
9
+ if response.code == 200
10
+ response["completion_rate"].to_f
11
+ end
9
12
  end
10
13
 
11
14
  def extension
@@ -21,12 +24,15 @@ module Pige::Client
21
24
  end
22
25
 
23
26
  def download(target)
24
- File.open(File.join(target, download_file), "w") do |file|
27
+ target_file = File.join(target, download_file)
28
+
29
+ File.open(target_file, "w") do |file|
25
30
  open(download_url) do |url|
26
31
  IO.copy_stream url, file
27
32
  end
28
33
  end
29
- download_file
34
+
35
+ target_file
30
36
  end
31
37
  end
32
38
  end
@@ -9,6 +9,11 @@ module Pige::Client
9
9
  end
10
10
 
11
11
  def wait(timeout = nil)
12
+ if chunks.empty?
13
+ puts "No chunk to wait"
14
+ return
15
+ end
16
+
12
17
  timeout ||= chunks.size * 5
13
18
  print "Wait for new chunks to be ready : "
14
19
  deadline = Time.now + (timeout * 60)
@@ -20,7 +25,7 @@ module Pige::Client
20
25
  chunk.completion_rate == 1
21
26
  end
22
27
  if uncompleted_chunks.empty?
23
- puts "done\nChunks are ready"
28
+ puts " done\nChunks are ready"
24
29
  break
25
30
  else
26
31
  print "."
@@ -30,6 +35,11 @@ module Pige::Client
30
35
  end
31
36
 
32
37
  def download(target)
38
+ if chunks.empty?
39
+ puts "No chunk to download"
40
+ return []
41
+ end
42
+
33
43
  wait
34
44
 
35
45
  FileUtils.mkdir_p target
@@ -111,7 +121,12 @@ module Pige::Client
111
121
  puts "Create Chunk with #{attributes.inspect}"
112
122
 
113
123
  unless dry_run?
114
- chunks << Pige::Client::Chunk.create(attributes)
124
+ chunk = Pige::Client::Chunk.create(attributes)
125
+ if chunk
126
+ chunks << chunk
127
+ else
128
+ puts "Error: can't create Chunk with #{attributes.inspect}"
129
+ end
115
130
  sleep options[:delay].to_i if options[:delay]
116
131
  end
117
132
  end
@@ -50,7 +50,9 @@ module Pige::Client
50
50
 
51
51
  def self.create(attributes = {})
52
52
  response = post("#{base_url}.json", :query => { resource_name => attributes })
53
- new response
53
+ if [200,201].include? response.code
54
+ new response
55
+ end
54
56
  end
55
57
 
56
58
  def self.all
@@ -1,5 +1,5 @@
1
1
  module Pige
2
2
  module Client
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryphon-pige-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-26 00:00:00.000000000 Z
13
+ date: 2015-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fakeweb
@@ -174,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  segments:
176
176
  - 0
177
- hash: -222627169929893987
177
+ hash: 356711308025352021
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  none: false
180
180
  requirements:
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  segments:
185
185
  - 0
186
- hash: -222627169929893987
186
+ hash: 356711308025352021
187
187
  requirements: []
188
188
  rubyforge_project:
189
189
  rubygems_version: 1.8.23