halo_waypoint 0.0.1 → 0.0.2

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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec', :cli => '--color --format documentation' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}){ |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb'){ 'spec' }
5
+ end
data/README.md CHANGED
@@ -23,6 +23,18 @@ Or install it yourself as:
23
23
  gem install halo_waypoint
24
24
  ```
25
25
 
26
+ ## Usage
27
+
28
+ ``` ruby
29
+ require 'halo_waypoint'
30
+ player = HaloWaypoint::Player.find('kevinthompson x')
31
+
32
+ player.rank_name #=> "67"
33
+ player.favorite_weapon_name #=> "DMR"
34
+ player.xp #=> "186843"
35
+ player.next_rank_start_xp #=> "214110"
36
+ ```
37
+
26
38
  ## Reference
27
39
 
28
40
  - [Halo Waypoint API Endoints](http://api.auntiedot.net/index.php?title=Reference/Endpoints)
data/Rakefile CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
- require 'rake/testtask'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- Rake::TestTask.new do |task|
5
- task.libs << 'lib'
6
- task.test_files = FileList['spec/**/*_spec.rb']
7
- task.verbose = true
8
- end
9
- task :default => :test
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -3,19 +3,26 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'halo_waypoint/version'
5
5
 
6
- Gem::Specification.new do |gem|
7
- gem.name = 'halo_waypoint'
8
- gem.version = HaloWaypoint::VERSION
9
- gem.authors = ['Kevin Thompson']
10
- gem.email = ['kevin@kevinthompson.info']
11
- gem.description = %q{A simple wrapper around the Halo Waypoint service.}
12
- gem.summary = %q{A simple wrapper around the Halo Waypoint service that can be used for retrieving player and game information from games such as Halo 4.}
13
- gem.homepage = 'https://github.com/kevinthompson/halo_waypoint'
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'halo_waypoint'
8
+ spec.version = HaloWaypoint::VERSION
9
+ spec.authors = ['Kevin Thompson']
10
+ spec.email = ['kevin@kevinthompson.info']
11
+ spec.description = %q{A simple wrapper around the Halo Waypoint service.}
12
+ spec.summary = %q{A simple wrapper around the Halo Waypoint service that can be used for retrieving player and game information from games such as Halo 4.}
13
+ spec.homepage = 'https://github.com/kevinthompson/halo_waypoint'
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ['lib']
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
19
 
20
- gem.add_development_dependency 'rake'
20
+ spec.add_runtime_dependency 'httparty'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'guard'
24
+ spec.add_development_dependency 'guard-rspec'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rb-fsevent', '~> 0.9'
21
28
  end
data/lib/halo_waypoint.rb CHANGED
@@ -1,4 +1,10 @@
1
+ require 'httparty'
2
+ require 'uri'
1
3
  require 'halo_waypoint/version'
4
+ require 'halo_waypoint/resource'
5
+ require 'halo_waypoint/player'
2
6
 
3
7
  module HaloWaypoint
8
+ include HTTParty
9
+ base_uri 'https://stats.svc.halowaypoint.com'
4
10
  end
@@ -0,0 +1,22 @@
1
+ module HaloWaypoint
2
+ class Player < Resource
3
+ attr_reader :background_image_url, :emblem_image_url,
4
+ :favorite_weapon_description, :favorite_weapon_id, :favorite_weapon_image_url, :favorite_weapon_name, :favorite_weapon_total_kills,
5
+ :game_modes, :gamertag,
6
+ :next_rank_id, :next_rank_image_url, :next_rank_name, :next_rank_start_xp, :rank_id, :rank_image_url, :rank_name, :rank_start_xp,
7
+ :service_tag, :specializations, :top_medals, :top_skill_rank, :xp
8
+
9
+ class << self
10
+ def find(gamertag, game = 'h4')
11
+ response = HaloWaypoint.get(URI.escape("/en-us/players/#{gamertag}/#{game}/playercard"))
12
+ data = response.parsed_response
13
+ if data['PlayerCardResponse'] && data['PlayerCardResponse']['StatusCode'] == '1'
14
+ new(data['PlayerCardResponse'])
15
+ else
16
+ raise 'Player Not Found'
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module HaloWaypoint
2
+ class Resource
3
+
4
+ def initialize(attributes = {})
5
+ assign_attributes(attributes)
6
+ end
7
+
8
+ def assign_attributes(attributes)
9
+ attributes.each do |key, value|
10
+ key = self.class.string_to_key(key)
11
+ self.instance_variable_set("@#{key}", value) if respond_to?(key)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ class << self
18
+ def string_to_key(string)
19
+ string = string.dup
20
+ string.gsub!(/::/, '/')
21
+ string.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
22
+ string.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
23
+ string.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
24
+ string.tr!("-", "_")
25
+ string.downcase!
26
+ string
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module HaloWaypoint
2
- VERSION = '0.0.1'
3
- end
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe HaloWaypoint::Player do
4
+ describe '.find' do
5
+ context 'with a valid gamertag' do
6
+ it 'returns a player object' do
7
+ player = HaloWaypoint::Player.find('kevinthompson x')
8
+ player.should be_a(HaloWaypoint::Player)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe HaloWaypoint::Resource do
4
+
5
+ describe '#initialize' do
6
+ it 'should call assign_attributes' do
7
+ HaloWaypoint::Resource.any_instance.should_receive(:assign_attributes)
8
+ HaloWaypoint::Resource.new
9
+ end
10
+ end
11
+
12
+ describe '#assign_attributes' do
13
+ before(:all) do
14
+ HaloWaypoint::Resource.class_eval do
15
+ attr_accessor :master_chief
16
+ end
17
+ end
18
+
19
+ it 'converts CamelCase keys to underscore' do
20
+ resource = HaloWaypoint::Resource.new({ 'MasterChief' => 'Cortana' })
21
+ resource.instance_variable_get('@master_chief').should == 'Cortana'
22
+ end
23
+
24
+ it 'does not assign CamelCase keys' do
25
+ resource = HaloWaypoint::Resource.new({ 'MasterChief' => 'Cortana' })
26
+ resource.instance_variable_get('@MasterChief').should be_nil
27
+ end
28
+ end
29
+
30
+ end
@@ -1,7 +1,7 @@
1
- require_relative '../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
- describe HaloWaypoint::VERSION do
4
- it 'must be defined' do
5
- HaloWaypoint::VERSION.wont_be_nil
3
+ describe 'HaloWaypoint::VERSION' do
4
+ it 'should be defined' do
5
+ HaloWaypoint::VERSION.should_not be_nil
6
6
  end
7
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'minitest/pride'
4
- require File.expand_path('../../lib/halo_waypoint.rb', __FILE__)
1
+ require 'rspec'
2
+ require 'halo_waypoint'
3
+
4
+ RSpec.configure do |config|
5
+ # ...
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halo_waypoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,6 +11,70 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
14
78
  - !ruby/object:Gem::Dependency
15
79
  name: rake
16
80
  requirement: !ruby/object:Gem::Requirement
@@ -27,6 +91,38 @@ dependencies:
27
91
  - - ! '>='
28
92
  - !ruby/object:Gem::Version
29
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rb-fsevent
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '0.9'
30
126
  description: A simple wrapper around the Halo Waypoint service.
31
127
  email:
32
128
  - kevin@kevinthompson.info
@@ -35,13 +131,19 @@ extensions: []
35
131
  extra_rdoc_files: []
36
132
  files:
37
133
  - .gitignore
134
+ - .rspec
38
135
  - Gemfile
136
+ - Guardfile
39
137
  - LICENSE.txt
40
138
  - README.md
41
139
  - Rakefile
42
140
  - halo_waypoint.gemspec
43
141
  - lib/halo_waypoint.rb
142
+ - lib/halo_waypoint/player.rb
143
+ - lib/halo_waypoint/resource.rb
44
144
  - lib/halo_waypoint/version.rb
145
+ - spec/lib/halo_waypoint/player_spec.rb
146
+ - spec/lib/halo_waypoint/resource_spec.rb
45
147
  - spec/lib/halo_waypoint/version_spec.rb
46
148
  - spec/spec_helper.rb
47
149
  homepage: https://github.com/kevinthompson/halo_waypoint
@@ -70,6 +172,8 @@ specification_version: 3
70
172
  summary: A simple wrapper around the Halo Waypoint service that can be used for retrieving
71
173
  player and game information from games such as Halo 4.
72
174
  test_files:
175
+ - spec/lib/halo_waypoint/player_spec.rb
176
+ - spec/lib/halo_waypoint/resource_spec.rb
73
177
  - spec/lib/halo_waypoint/version_spec.rb
74
178
  - spec/spec_helper.rb
75
179
  has_rdoc: