halo-reach-api 1.0.0 → 1.0.1

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.
data/README.rdoc CHANGED
@@ -44,8 +44,9 @@ Q: Dates are funky and not parsed as dates. For example:
44
44
  "Name" : "Pass the Rock"
45
45
  },
46
46
 
47
- A: Yes they are funky. Yes. They. Are. I'm considering how I would actually parse that out. I may write a helper method on the API class to take a date like that
48
- and parse it into something useable. Or you can submit a patch for that?!
47
+ A: Yes they are funky. Yes. They. Are. You can now parse them out with the Halo::Reach::Util class.
48
+
49
+ >> parsed_time, parsed_timezone = Halo::Reach::Util::parse_timestamp(api_timestamp)
49
50
 
50
51
  == Contributing to halo-reach-api
51
52
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require 'jeweler'
13
13
  Jeweler::Tasks.new do |gem|
14
14
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
15
  gem.name = "halo-reach-api"
16
- gem.homepage = "http://github.com/czarneckid/halo-reach-api"
16
+ gem.homepage = "http://github.com/agoragames/halo-reach-api"
17
17
  gem.license = "MIT"
18
18
  gem.summary = %Q{Ruby gem for interacting with the Halo:Reach API}
19
19
  gem.description = %Q{Ruby gem for interacting with the Halo:Reach API}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{halo-reach-api}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Czarnecki"]
12
- s.date = %q{2010-11-22}
12
+ s.date = %q{2010-11-23}
13
13
  s.description = %q{Ruby gem for interacting with the Halo:Reach API}
14
14
  s.email = %q{dczarnecki@agoragames.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "halo-reach-api.gemspec",
29
29
  "lib/halo-reach-api.rb",
30
+ "lib/halo-reach-util.rb",
30
31
  "test/fakeweb/get_current_challenges.json",
31
32
  "test/fakeweb/get_file_details.json",
32
33
  "test/fakeweb/get_game_details.json",
@@ -42,16 +43,18 @@ Gem::Specification.new do |s|
42
43
  "test/fakeweb/get_player_rendered_videos.json",
43
44
  "test/fakeweb/reach_file_search.json",
44
45
  "test/helper.rb",
45
- "test/test_halo-reach-api.rb"
46
+ "test/test_halo-reach-api.rb",
47
+ "test/test_halo-reach-util.rb"
46
48
  ]
47
- s.homepage = %q{http://github.com/czarneckid/halo-reach-api}
49
+ s.homepage = %q{http://github.com/agoragames/halo-reach-api}
48
50
  s.licenses = ["MIT"]
49
51
  s.require_paths = ["lib"]
50
52
  s.rubygems_version = %q{1.3.7}
51
53
  s.summary = %q{Ruby gem for interacting with the Halo:Reach API}
52
54
  s.test_files = [
53
55
  "test/helper.rb",
54
- "test/test_halo-reach-api.rb"
56
+ "test/test_halo-reach-api.rb",
57
+ "test/test_halo-reach-util.rb"
55
58
  ]
56
59
 
57
60
  if s.respond_to? :specification_version then
@@ -7,7 +7,7 @@ module Halo
7
7
  class API
8
8
  include HTTParty
9
9
 
10
- VERSION = '1.0.0'.freeze
10
+ VERSION = '1.0.1'.freeze
11
11
  API_URL = 'http://www.bungie.net/api/reach/reachapijson.svc/'
12
12
 
13
13
  DEFAULT_HEADERS = {
@@ -0,0 +1,19 @@
1
+ module Halo
2
+ module Reach
3
+ class Util
4
+ def self.parse_timestamp(timestamp = nil)
5
+ # Expected format: '/Date(1284497520000-0700)/'
6
+ # The API returns the date as a UNIX timestamp in milliseconds
7
+ # The "0700" represents the timezone, in this example the U.S. Pacific (GMT-7) timezone
8
+ # (http://www.haloreachapi.net/wiki/Date_time_format)
9
+
10
+ if timestamp && (timestamp =~ /^\/Date\((\d+)-(\d+)\)\/$/)
11
+ return [Time.at($1.to_i / 1000).utc, $2]
12
+ else
13
+ raise ArgumentError.new('Invalid timestamp')
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
data/test/helper.rb CHANGED
@@ -12,6 +12,7 @@ require 'test/unit'
12
12
  $LOAD_PATH.unshift(File.dirname(__FILE__))
13
13
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
14
  require 'halo-reach-api'
15
+ require 'halo-reach-util'
15
16
 
16
17
  class Test::Unit::TestCase
17
18
  end
@@ -12,7 +12,7 @@ class TestHaloReachApi < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_api_version
15
- assert_equal '1.0.0', Halo::Reach::API::VERSION
15
+ assert_equal '1.0.1', Halo::Reach::API::VERSION
16
16
  end
17
17
 
18
18
  def test_can_set_token
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class TestHaloReachUtil < Test::Unit::TestCase
4
+
5
+ def test_can_parse_correctly_formatted_timestamp
6
+ utc_time = Time.now.utc
7
+ milliseconds_since_epoch = utc_time.to_i * 1000
8
+ timezone = '0500'
9
+ api_timestamp = build_timestamp(milliseconds_since_epoch, timezone)
10
+
11
+ parsed_time, parsed_timezone = Halo::Reach::Util::parse_timestamp(api_timestamp)
12
+ assert_equal utc_time.to_s, parsed_time.to_s
13
+ assert_equal timezone, parsed_timezone
14
+ end
15
+
16
+ def test_raise_invalid_timestamp_argument_error_on_malformed_timestamp
17
+ invalid_timestamps = [
18
+ nil, # nothing at all
19
+ '', # empty timestamp
20
+ '/Date(/', # generally malformed timestamp
21
+ '/Date()/', # malformed timestamp missing actual data
22
+ build_timestamp('',''), # missing both millisends and timezone
23
+ build_timestamp('','0700'), # missing millisends
24
+ build_timestamp(Time.now.utc.to_i * 1000, ''), # missing timezone
25
+ build_timestamp('abc1041', '04jhg'), # prepended/trailing garbage
26
+ build_timestamp('43gi', 'tb01'), # trailing/prepended garbage
27
+ build_timestamp('ed456mb', 'mvn029hgd'), # surrounded by garbage
28
+ build_timestamp('asd;kf', 'sdfoih') # omg pure garbage
29
+ ]
30
+
31
+ invalid_timestamps.each do |invalid_timestamp|
32
+ assert_raises(ArgumentError) do
33
+ Halo::Reach::Util::parse_timestamp(invalid_timestamp)
34
+ end
35
+ end
36
+ end
37
+
38
+ def build_timestamp(milliseconds_since_epoch, timezone)
39
+ "/Date(#{milliseconds_since_epoch.to_s}-#{timezone.to_s})/"
40
+ end
41
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halo-reach-api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Czarnecki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-22 00:00:00 -05:00
18
+ date: 2010-11-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,7 @@ files:
112
112
  - VERSION
113
113
  - halo-reach-api.gemspec
114
114
  - lib/halo-reach-api.rb
115
+ - lib/halo-reach-util.rb
115
116
  - test/fakeweb/get_current_challenges.json
116
117
  - test/fakeweb/get_file_details.json
117
118
  - test/fakeweb/get_game_details.json
@@ -128,8 +129,9 @@ files:
128
129
  - test/fakeweb/reach_file_search.json
129
130
  - test/helper.rb
130
131
  - test/test_halo-reach-api.rb
132
+ - test/test_halo-reach-util.rb
131
133
  has_rdoc: true
132
- homepage: http://github.com/czarneckid/halo-reach-api
134
+ homepage: http://github.com/agoragames/halo-reach-api
133
135
  licenses:
134
136
  - MIT
135
137
  post_install_message:
@@ -165,3 +167,4 @@ summary: Ruby gem for interacting with the Halo:Reach API
165
167
  test_files:
166
168
  - test/helper.rb
167
169
  - test/test_halo-reach-api.rb
170
+ - test/test_halo-reach-util.rb