scoreoid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGES.md +9 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +8 -0
- data/lib/scoreoid.rb +20 -0
- data/lib/scoreoid/api_client.rb +61 -0
- data/lib/scoreoid/player.rb +15 -0
- data/lib/scoreoid/version.rb +3 -0
- data/scoreoid.gemspec +21 -0
- data/spec/api_client_spec.rb +80 -0
- data/spec/player_spec.rb +10 -0
- data/spec/scoreoid_spec.rb +14 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/version_spec.rb +7 -0
- metadata +99 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Justin Workman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
Scoreoid Ruby
|
2
|
+
=============
|
3
|
+
|
4
|
+
Scoreoid Ruby is a wrapper for the Scoreoid API. It is in the early development stages,
|
5
|
+
with plans to support all Scoreoid API methods.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'scoreoid'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install scoreoid
|
21
|
+
|
22
|
+
Contributing
|
23
|
+
------------
|
24
|
+
|
25
|
+
Contributions are most welcome!
|
26
|
+
|
27
|
+
1. [Fork it on Bitbucket](https://bitbucket.org/xtagon/scoreoid-ruby-gem/fork)
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
33
|
+
Please use the [issue tracker](https://bitbucket.org/xtagon/scoreoid-ruby-gem/issues?status=new&status=open) if you encounter a bug or have a feature request.
|
34
|
+
|
35
|
+
License
|
36
|
+
-------
|
37
|
+
|
38
|
+
Copyright © 2012 [Justin Workman](mailto:xtagon@gmail.com)
|
39
|
+
|
40
|
+
MIT License
|
41
|
+
|
42
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
43
|
+
a copy of this software and associated documentation files (the
|
44
|
+
"Software"), to deal in the Software without restriction, including
|
45
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
46
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
47
|
+
permit persons to whom the Software is furnished to do so, subject to
|
48
|
+
the following conditions:
|
49
|
+
|
50
|
+
The above copyright notice and this permission notice shall be
|
51
|
+
included in all copies or substantial portions of the Software.
|
52
|
+
|
53
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
54
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
55
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
56
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
57
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
58
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
59
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/scoreoid.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'scoreoid/version'
|
2
|
+
require 'scoreoid/api_client'
|
3
|
+
require 'scoreoid/player'
|
4
|
+
|
5
|
+
module Scoreoid
|
6
|
+
# This exception is raised when Scoreoid Ruby is used without first being configured.
|
7
|
+
# To configure Scoreoid Ruby, see {Scoreoid.configure}.
|
8
|
+
class NotConfiguredError < RuntimeError; end
|
9
|
+
|
10
|
+
# Configure Scoreoid Ruby with your Scoreoid API key and game ID.
|
11
|
+
# This must be done once before calling any Scoreoid API methods.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# Scoreoid.configure(ENV['SCOREOID_API_KEY'], ENV['SCOREOID_GAME_ID'])
|
15
|
+
#
|
16
|
+
# @return [Hash] A hash of the parameters you just configured.
|
17
|
+
def self.configure(api_key, game_id)
|
18
|
+
Scoreoid::APIClient.default_params = {api_key: api_key, game_id: game_id}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'rest_client'
|
3
|
+
|
4
|
+
module Scoreoid
|
5
|
+
# This exception is raised when the Scoreoid API returns an error response.
|
6
|
+
class APIError < StandardError; end
|
7
|
+
|
8
|
+
class APIClient
|
9
|
+
REQUIRED_PARAMETERS = [:api_key, :game_id]
|
10
|
+
|
11
|
+
@@default_params = Hash.new
|
12
|
+
|
13
|
+
# Set the default request parameters.
|
14
|
+
# Normally you would not call this directly, but instead use {Scoreoid.configure}.
|
15
|
+
#
|
16
|
+
# @param [Hash] params A hash of the default parameters to set.
|
17
|
+
#
|
18
|
+
# @return [Hash] Default request parameters.
|
19
|
+
def self.default_params= params
|
20
|
+
@@default_params = params
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the default request parameters.
|
24
|
+
#
|
25
|
+
# @raise [Scoreoid::NotConfiguredError] if required parameters are not set.
|
26
|
+
#
|
27
|
+
# @return Default request paremeters.
|
28
|
+
def self.default_params
|
29
|
+
REQUIRED_PARAMETERS.each do |param_key|
|
30
|
+
unless @@default_params.key?(param_key)
|
31
|
+
raise Scoreoid::NotConfiguredError, "Scoreoid Ruby has not been configured correctly. Please set the API key and game ID with Scoreoid.configure(api_key, game_id) before using this library."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
@@default_params
|
36
|
+
end
|
37
|
+
|
38
|
+
# Query the Scoreoid API and return the un-parsed response.
|
39
|
+
# This is used internally and you should only call it if you really know what you're doing.
|
40
|
+
def self.api_call(api_method)
|
41
|
+
# Add :response => 'json' to the post parameters because the entire library
|
42
|
+
# epects JSON responses.
|
43
|
+
post_params = self.default_params.merge({response: 'json'})
|
44
|
+
RestClient.post("https://www.scoreoid.com/api/#{api_method}", post_params)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Query the Scoreoid API method "countPlayers()" and parse the response.
|
48
|
+
#
|
49
|
+
# @see Scoreoid::Player.count
|
50
|
+
#
|
51
|
+
# @raise [Scoreoid::APIError] if the Scoreoid API returns an error response.
|
52
|
+
#
|
53
|
+
# @return [Hash] The Scoreoid API response parsed into a Hash.
|
54
|
+
def self.countPlayers
|
55
|
+
api_response = self.api_call('countPlayers')
|
56
|
+
json = MultiJson.load(api_response)
|
57
|
+
raise APIError, json['error'] if json.key? 'error'
|
58
|
+
json
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'scoreoid/api_client'
|
2
|
+
|
3
|
+
module Scoreoid
|
4
|
+
class Player
|
5
|
+
# @return [Integer] The total number of players for the game.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# Scoreoid.configure 'YOUR_API_KEY', 'YOUR_GAME_ID'
|
9
|
+
#
|
10
|
+
# puts "This game has #{Scoreoid::Player.count} players!"
|
11
|
+
def self.count
|
12
|
+
Scoreoid::APIClient.countPlayers['players']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/scoreoid.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'scoreoid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'scoreoid'
|
8
|
+
gem.version = Scoreoid::VERSION
|
9
|
+
gem.author = 'Justin Workman'
|
10
|
+
gem.email = 'xtagon@gmail.com'
|
11
|
+
gem.summary = 'Scoreoid Ruby is a wrapper for the Scoreoid API.'
|
12
|
+
|
13
|
+
gem.required_ruby_version = '1.9.2'
|
14
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.3'
|
15
|
+
gem.add_runtime_dependency 'rest-client', '~> 1.6'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ['lib']
|
21
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Scoreoid::APIClient do
|
4
|
+
describe 'self.default_params' do
|
5
|
+
it 'should be set to empty hash by default' do
|
6
|
+
Scoreoid::APIClient.class_variable_get(:@@default_params).should be_instance_of Hash
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'setting default parameters' do
|
10
|
+
it 'should set default parameters when required parameters are provided' do
|
11
|
+
example_params = {api_key: 'API_KEY', game_id: 'GAME_ID'}
|
12
|
+
Scoreoid::APIClient.default_params = example_params
|
13
|
+
Scoreoid::APIClient.class_variable_get(:@@default_params).should == example_params
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'getting default parameters' do
|
18
|
+
it 'returns exactly the parameters which were set' do
|
19
|
+
example_params = {api_key: 'API_KEY', game_id: 'GAME_ID'}
|
20
|
+
Scoreoid::APIClient.default_params = example_params
|
21
|
+
Scoreoid::APIClient.default_params.should == example_params
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'raises an error if required parameters are absent' do
|
25
|
+
Scoreoid::APIClient.default_params = {api_key: 'API_KEY'} # missing :game_id
|
26
|
+
expect do
|
27
|
+
Scoreoid::APIClient.default_params
|
28
|
+
end.to raise_error Scoreoid::NotConfiguredError
|
29
|
+
|
30
|
+
Scoreoid::APIClient.default_params = {game_key: 'GAME_ID'} # missing :api_key
|
31
|
+
expect do
|
32
|
+
Scoreoid::APIClient.default_params
|
33
|
+
end.to raise_error Scoreoid::NotConfiguredError
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'self.api_call' do
|
39
|
+
it 'should call Scoreoid API methods with default parameters' do
|
40
|
+
# We're testing that :response => 'json' is added to the parameters
|
41
|
+
# because the entire library expects JSON responses.
|
42
|
+
|
43
|
+
example_response = %q({"players": 7})
|
44
|
+
default_params = {api_key: 'API_KEY', game_id: 'GAME_ID'}
|
45
|
+
post_params = default_params.merge({response: 'json'})
|
46
|
+
|
47
|
+
Scoreoid::APIClient.stub(:default_params).and_return(default_params)
|
48
|
+
RestClient.stub(:post).and_return(example_response)
|
49
|
+
RestClient.should_receive(:post).with('https://www.scoreoid.com/api/playerCount', post_params)
|
50
|
+
|
51
|
+
api_response = Scoreoid::APIClient.api_call('playerCount')
|
52
|
+
api_response.should be_instance_of String
|
53
|
+
api_response.should == example_response
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'self.countPlayers' do
|
58
|
+
it 'should call the countPlayers() Scoreoid API method' do
|
59
|
+
Scoreoid::APIClient.stub(:api_call).and_return(%q({"players":7}))
|
60
|
+
Scoreoid::APIClient.should_receive(:api_call).with('countPlayers')
|
61
|
+
Scoreoid::APIClient.countPlayers
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should parse the JSON result into a Hash' do
|
65
|
+
Scoreoid::APIClient.stub(:api_call).and_return(%q({"players":7}))
|
66
|
+
result = Scoreoid::APIClient.countPlayers
|
67
|
+
result.should be_instance_of Hash
|
68
|
+
result.should == {'players' => 7}
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should raise an error if the Scoreoid API returns an error' do
|
72
|
+
example_response = %q({"error": "The API key is broken or the game is not active"})
|
73
|
+
Scoreoid::APIClient.stub(:api_call).and_return(example_response)
|
74
|
+
|
75
|
+
expect do
|
76
|
+
Scoreoid::APIClient.countPlayers
|
77
|
+
end.to raise_error(Scoreoid::APIError, 'The API key is broken or the game is not active')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/player_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Scoreoid::Player do
|
4
|
+
it 'should count players' do
|
5
|
+
Scoreoid::APIClient.should_receive(:countPlayers).and_return({'players' => 7})
|
6
|
+
how_many_players = Scoreoid::Player.count
|
7
|
+
how_many_players.should be_kind_of Integer
|
8
|
+
how_many_players.should >= 0
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Scoreoid do
|
4
|
+
describe 'self.configure' do
|
5
|
+
it 'should set Scoreoid API key and game ID parameters' do
|
6
|
+
Scoreoid.configure('API_KEY', 'GAME_ID')
|
7
|
+
default_params = Scoreoid::APIClient.class_variable_get(:@@default_params)
|
8
|
+
default_params.key?(:api_key).should be_true
|
9
|
+
default_params.key?(:game_id).should be_true
|
10
|
+
default_params[:api_key].should == 'API_KEY'
|
11
|
+
default_params[:game_id].should == 'GAME_ID'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'scoreoid'
|
2
|
+
|
3
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
|
9
|
+
# Run specs in random order to surface order dependencies. If you find an
|
10
|
+
# order dependency and want to debug it, you can fix the order by providing
|
11
|
+
# the seed, which is printed after each run.
|
12
|
+
# --seed 1234
|
13
|
+
#config.order = 'random'
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scoreoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Justin Workman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
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: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.6'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.6'
|
46
|
+
description:
|
47
|
+
email: xtagon@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- .rspec
|
54
|
+
- CHANGES.md
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/scoreoid.rb
|
60
|
+
- lib/scoreoid/api_client.rb
|
61
|
+
- lib/scoreoid/player.rb
|
62
|
+
- lib/scoreoid/version.rb
|
63
|
+
- scoreoid.gemspec
|
64
|
+
- spec/api_client_spec.rb
|
65
|
+
- spec/player_spec.rb
|
66
|
+
- spec/scoreoid_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/version_spec.rb
|
69
|
+
homepage:
|
70
|
+
licenses: []
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - '='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.9.2
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.8.24
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Scoreoid Ruby is a wrapper for the Scoreoid API.
|
93
|
+
test_files:
|
94
|
+
- spec/api_client_spec.rb
|
95
|
+
- spec/player_spec.rb
|
96
|
+
- spec/scoreoid_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/version_spec.rb
|
99
|
+
has_rdoc:
|