km_resque 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,7 +44,7 @@ Configure your API key:
44
44
 
45
45
  ## Credits
46
46
 
47
- Written by Luke Melia. Thanks to Yapp for open sourcing KMResque. Inspiration from delayed_kiss and km-delay.
47
+ Written by Luke Melia. Thanks to Yapp for open sourcing KmResque. Inspiration from delayed_kiss and km-delay.
48
48
 
49
49
  ## License
50
50
 
@@ -46,8 +46,14 @@ class KmResque
46
46
  raise Error.new("Can't hit the API without an API Key")
47
47
  end
48
48
 
49
- data['_d'] = 1 if data['_t']
50
- data['_t'] ||= Time.now.to_i
49
+ if data['_t']
50
+ data['_d'] = 1
51
+ unless validate_timestamp(data['_t'])
52
+ raise Error.new("Timestamp #{data['_t']} is invalid")
53
+ end
54
+ else
55
+ data['_t'] = Time.now.to_i
56
+ end
51
57
 
52
58
  unsafe = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]", false, 'N')
53
59
 
@@ -62,5 +68,12 @@ class KmResque
62
68
  http.get(query)
63
69
  end
64
70
  end
71
+
72
+ SECONDS_IN_ONE_HUNDRED_YEARS = 60 * 60 * 24 * 365 * 100
73
+
74
+ def validate_timestamp(timestamp)
75
+ timestamp = timestamp.to_i
76
+ (timestamp > 0) && (timestamp < (Time.now.to_i + SECONDS_IN_ONE_HUNDRED_YEARS))
77
+ end
65
78
  end
66
79
  end
@@ -1,3 +1,3 @@
1
1
  class KmResque
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -28,5 +28,11 @@ describe "KmResque::RecordJob" do
28
28
  KmResque::RecordJob.perform(nil, "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp)
29
29
  }.should raise_error(KmResque::Error)
30
30
  end
31
+ it "should raise an error when an invalid timestamp is provided" do
32
+ timestamp = Time.now.to_i * 1000 # common mistake is providing milliseconds instead of seconds
33
+ lambda {
34
+ KmResque::RecordJob.perform("identifier", "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp)
35
+ }.should raise_error(KmResque::Error)
36
+ end
31
37
  end
32
38
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: km_resque
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Luke Melia
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-20 00:00:00 Z
13
+ date: 2012-09-25 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: resque