apple_epf 1.0.3 → 1.1.0

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.
@@ -77,7 +77,16 @@ module AppleEpf
77
77
 
78
78
  # Return false if no url was suggested or file does not exist
79
79
  raise AppleEpf::DownloaderError.new("Unable to find out what file do you want to download") if path.empty?
80
- raise AppleEpf::FileNotExist.new("File does not exist #{path}") unless file_exists?(path)
80
+
81
+ unless file_exists?(path)
82
+ if @type == 'incremental'
83
+ #force prev week. Apple sometimes put files for Sunday to prev week, not current.
84
+ path = "#{main_dir_date(true)}/incremental/#{date_of_file}/#{@filename}#{date_of_file}.tbz"
85
+ raise AppleEpf::FileNotExist.new("File does not exist #{path}") unless file_exists?(path)
86
+ else
87
+ raise AppleEpf::FileNotExist.new("File does not exist #{path}")
88
+ end
89
+ end
81
90
 
82
91
  @apple_filename_full_path = path
83
92
  @apple_filename_full_path
@@ -98,10 +107,10 @@ module AppleEpf
98
107
  FileUtils.mkpath(dirpath)
99
108
  end
100
109
 
101
- def main_dir_date
110
+ def main_dir_date(force_last = false)
102
111
  if @type == "incremental"
103
112
  # from Mon to Thurday dumps are in prev week folder
104
- this_or_last = @filedate.wday <= 4 ? 'last' : 'this'
113
+ this_or_last = @filedate.wday <= 4 || force_last ? 'last' : 'this'
105
114
  elsif @type == "full"
106
115
  # full downloads usually are done only once. user can determine when it should be done
107
116
  this_or_last = 'this'
@@ -124,7 +133,9 @@ module AppleEpf
124
133
  request = Net::HTTP::Head.new(full_url)
125
134
  request.basic_auth(AppleEpf.apple_id, AppleEpf.apple_password)
126
135
 
127
- response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request(request) }
136
+ r = Net::HTTP.new(uri.host, uri.port)
137
+ r.use_ssl = true
138
+ response = r.start { |http| http.request(request) }
128
139
 
129
140
  raise AppleEpf::BadCredentialsError.new('Bad credentials') if response.code == "401"
130
141
 
@@ -1,3 +1,3 @@
1
1
  module AppleEpf
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -34,9 +34,8 @@ describe AppleEpf::Downloader do
34
34
  end
35
35
 
36
36
  context "and file does not exists" do
37
- let(:file_exists) { false }
38
-
39
37
  it "should raise exception" do
38
+ downloader.stub(:file_exists?).and_return(false, false)
40
39
  downloader.filedate = Date.parse('17-01-2013')
41
40
  expect {
42
41
  downloader.get_filename_by_date_and_type
@@ -56,12 +55,18 @@ describe AppleEpf::Downloader do
56
55
  downloader.filedate = Date.parse('17-01-2013')
57
56
  downloader.get_filename_by_date_and_type.should == "20130109/incremental/20130117/popularity20130117.tbz"
58
57
  end
58
+
59
+
60
+ it "should return valid url if file exists but in prev catalog" do
61
+ downloader.stub(:file_exists?).and_return(false, true)
62
+ downloader.filedate = Date.parse('26-04-2013')
63
+ downloader.get_filename_by_date_and_type.should == "20130417/incremental/20130426/popularity20130426.tbz"
64
+ end
59
65
  end
60
66
 
61
67
  context "and file does not exists" do
62
- let(:file_exists) { false }
63
-
64
68
  it "should raise exception" do
69
+ downloader.stub(:file_exists?).and_return(false, false)
65
70
  downloader.filedate = Date.parse('17-01-2013')
66
71
  expect {
67
72
  downloader.get_filename_by_date_and_type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_epf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -221,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  version: '0'
222
222
  segments:
223
223
  - 0
224
- hash: 1456211595176392472
224
+ hash: 2270709244037227608
225
225
  required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  none: false
227
227
  requirements:
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  segments:
232
232
  - 0
233
- hash: 1456211595176392472
233
+ hash: 2270709244037227608
234
234
  requirements: []
235
235
  rubyforge_project:
236
236
  rubygems_version: 1.8.23