binarybeast 0.1.5.pre → 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .project
data/README.md CHANGED
@@ -66,6 +66,14 @@ more to come soon....
66
66
 
67
67
  ## Some stuff you should know
68
68
 
69
+ ### Eigenclass: Tourney
70
+
71
+ There is an eigenclass of the Tourney Class. Functions are
72
+
73
+ .list
74
+ .listpopular
75
+ .load
76
+
69
77
  ### :force => true
70
78
 
71
79
  The BinaryBeast API sends back JSON from every request. However, if you use this gem we catch the JSON Data and proccess it. If you want to have a direct response from the API you can go with something like this:
@@ -82,6 +90,15 @@ the :force options is currently available to almost every function, the exceptio
82
90
 
83
91
  ## Changelog
84
92
 
93
+ ### Version: 0.1.5.pre
94
+
95
+ * Added list to eigenclass. It lists tourneys that you've created. Example: tourneys = Binarybeast::Tourney.list
96
+ * Added listpopular to eigenclass. It lists popular tourney. Example: tourneys = Binarybeast::Tourney.listpopular
97
+
98
+ ### Version: 0.1.4.pre
99
+
100
+ * Fixed a typo in some tests.
101
+
85
102
  ### Version: 0.1.3.pre
86
103
 
87
104
  * Added Eigenclass to Tourney, so you can call Binarybeast::Tourney.load(:id => "").
@@ -5,7 +5,7 @@ require 'binarybeast/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "binarybeast"
8
- gem.version = Binarybeast::VERSION
8
+ gem.version = BinaryBeast::VERSION
9
9
  gem.authors = ["Crispin Schaeffler"]
10
10
  gem.email = ["crispinschaeffler@googlemail.com"]
11
11
  gem.description = %q{Ruby gem to access the binary beast api.}
@@ -10,25 +10,30 @@ require "HTTParty"
10
10
  # ---------------------
11
11
  # does contain all the classes that interact with binarybeast api.
12
12
 
13
- module Binarybeast
13
+ module BinaryBeast
14
14
  include HTTParty
15
15
  # Base URI for the BinaryBeast API
16
- base_uri 'https://binarybeast.com/api'
16
+ base_uri 'https://api.binarybeast.com/'
17
17
  # Set HTTParty standard format to JSON, its standard what binarybeast api returns.
18
18
  format :json
19
19
  # Default api_key, this one is taken from my personal account.
20
- @@api_key = "3c8955130c6e1406420d6202649651fe.50c9faa593f9c6.00530099"
20
+ # @todo the api key should not be initialized with a personal account for the public release,
21
+ # in the future, use the test account api if anything: e17d31bfcbedd1c39bcb018c5f0d0fbf.4dcb36f5cc0d74.24632846
22
+ @@api_key = 'e17d31bfcbedd1c39bcb018c5f0d0fbf.4dcb36f5cc0d74.24632846'
23
+
24
+ # Autoload the service classes
25
+ require 'binarybeast/constants'
26
+ autoload :Service, 'binarybeast/service'
27
+ autoload :Tournament, 'binarybeast/tournament'
28
+ autoload :Team, 'binarybeast/team'
29
+ autoload :Game, 'binarybeast/game'
21
30
 
22
- # Autoload Tourney Class when needed
23
- autoload :Tourney, 'binarybeast/tourney'
24
- # Autoload Team Class when needed
25
- autoload :Team, 'binarybeast/team'
26
31
 
27
32
  # Getter for api_key Variable
28
33
  def self.api_key
29
34
  @@api_key
30
35
  end
31
-
36
+
32
37
  # Setter for api_key Variable
33
38
  def self.api_key=(api_key)
34
39
  @@api_key=api_key
@@ -37,14 +42,24 @@ module Binarybeast
37
42
  # Call
38
43
  # Method
39
44
  # ------------
40
- # Raw Call Method for those who want to make raw calls on the API of Binarybeast. APIKey will be taken from the module variable
45
+ # Raw Call Method for those who want to make raw calls on the API of Binarybeast. api_key will be taken from the module variable
41
46
  # Example:
42
- # tourney = Binarybeast.call(:APIService => "Tourney.TourneyCreate.Create", :title => "Test")
47
+ # tourney = Binarybeast.call('Tourney.TourneyCreate.Create', :title => "Test")
43
48
  # ------------
44
49
 
45
- def self.call(options={})
46
- options.merge!({:APIKey => @@api_key})
47
- return self.get("", :query => options)
50
+ def self.call(service, options={})
51
+ options.merge!({
52
+ :api_key => @@api_key,
53
+ :api_use_underscores => true,
54
+ :api_service => service,
55
+ :api_agent => "BinaryBeast API Ruby: Version #{BinaryBeast::VERSION}"
56
+ })
57
+
58
+ response = self.get('', :query => options)
59
+
60
+ yield response if block_given?
61
+ return response
62
+
48
63
  end
49
64
 
50
- end
65
+ end
@@ -0,0 +1,32 @@
1
+ module BinaryBeast
2
+
3
+ # Constants
4
+ # ---------------------
5
+ BRACKET_GROUPS = 0
6
+ BRACKET_WINNERS = 1
7
+ BRACKET_LOSERS = 2
8
+ BRACKET_FINALS = 3
9
+ BRACKET_BRONZE = 4
10
+ # ---------------------
11
+ ELIMINATION_SINGLE = 1
12
+ ELIMINATION_DOUBLE = 2
13
+ # ---------------------
14
+ # Brackets
15
+ TOURNAMENT_TYPE_BRACKETS = 0
16
+ # Round Robin -> Brackets
17
+ TOURNAMENT_TYPE_CUP = 1
18
+ # ---------------------
19
+ SEEDING_RANDOM = 'random'
20
+ SEEDING_SPORTS = 'sports'
21
+ SEEDING_BALANCED = 'balanced'
22
+ SEEDING_MANUAL = 'manual'
23
+ # ---------------------
24
+ REPLAY_DOWNLOADS_DISABLED = 0
25
+ REPLAY_DOWNLOADS_ENABLED = 1
26
+ REPLAY_DOWNLOADS_POST_COMPLETE = 2
27
+ # ---------------------
28
+ REPLAY_UPLOADS_DISABLED = 0
29
+ REPLAY_UPLOADS_OPTIONAL = 1
30
+ REPLAY_UPLOADS_MANDATORY = 2
31
+
32
+ end
@@ -0,0 +1,60 @@
1
+ module BinaryBeast
2
+
3
+ # Service
4
+ # Class
5
+ # ---------------
6
+ # This is the base service class that all other classes inherit from, it provides the basic
7
+ # API interaction functionality, in order to make this API library a bit more DRY
8
+ # ---------------
9
+ # gives you a Service object
10
+
11
+ class Service
12
+
13
+
14
+ # convertKeys
15
+ # Method
16
+ # ---------------
17
+ # This method used in conjuction with assignAttributes, will convert all keys of a hash returned by BinaryBeast,
18
+ # from strings to symbols
19
+ # For example in Tournament::initialize({:title=>'title of the tour'}), :title will automatically be assigned to this.title = 'Title of the tour'
20
+ # ---------------
21
+ def convertHashKeys(hash)
22
+
23
+ hash.inject({}) do |mem, (key, value)|
24
+ mem[key.to_sym] = value
25
+ mem
26
+ end
27
+
28
+ end
29
+
30
+
31
+ # assignAttributes
32
+ # Method
33
+ # ---------------
34
+ # Used by the service class constructors to iterate through inputs to quickly assign the values
35
+ # into the instance variables
36
+ # For example in Tournament::initialize({:title=>'title of the tour'}), :title will automatically be assigned to this.title = 'Title of the tour'
37
+ # ---------------
38
+ def assignAttributes(values = {})
39
+ values.each_pair do |key, value|
40
+ # Continue only if this method has an attribute setter for this value
41
+ if respond_to?("#{key}=")
42
+ self.send("#{key}=", value)
43
+ end
44
+ end
45
+ end
46
+
47
+ # getAttributes
48
+ # Method
49
+ # ---------------
50
+ # Used by service methods for calling update services without having
51
+ # to type out every single attribute in the code, once they're listed as
52
+ # an attr_accessor, it will be sent - if there happen to be extraneous values, it won't make any difference
53
+ # ---------------
54
+ def getAttributes()
55
+ Hash[instance_variables.map {|attr| [attr.slice(1..-1), instance_variable_get(attr)] } ]
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -1,4 +1,4 @@
1
- module Binarybeast
1
+ module BinaryBeast
2
2
  class Team
3
3
  end
4
4
  end
@@ -0,0 +1,264 @@
1
+ module BinaryBeast
2
+ # Tourney
3
+ # Class
4
+ # ---------------
5
+ # This is the Tourney service class. It will be used to most. It gives you a brand new Tourney object to call methods on.
6
+ # Example:
7
+ # tourney = Binarybeast::Tourney.new("Gamkoi Test")
8
+ # ---------------
9
+ # gives you a tourney object
10
+
11
+ class Tournament < BinaryBeast::Service
12
+
13
+ attr_accessor :api_key, :id, :tourney_id, :title, :public, :display_name, :url,
14
+ :game_code, :game, :game_style, :game_icon,
15
+ :status, :type_id, :elimination, :teams_confirmed_count, :teams_joined_count,
16
+ :team_mode, :teams_from_group, :max_teams, :group_count,
17
+ :view_count, :date_start, :location,
18
+ :replay_uploads, :replay_downloads,
19
+ :description, :return_data
20
+
21
+
22
+ # Default values for each attribute
23
+ DEFAULTS = {
24
+ :id => nil,
25
+ :title => 'Gamkoi DevTest', #"BinaryBeast API Ruby (#{BinaryBeast::VERSION}) Test Tournament",
26
+ :game_code => 'misc',
27
+ :game => 'Misc.',
28
+ :type_id => BinaryBeast::TOURNAMENT_TYPE_BRACKETS,
29
+ :elimination => BinaryBeast::ELIMINATION_SINGLE,
30
+ :team_mode => 1,
31
+ :group_count => 1,
32
+ :teams_from_group => 2,
33
+ :date_start => Time.new.strftime("%Y-%m-%d"),
34
+ :location => '',
35
+ :max_teams => 16,
36
+ :replay_uploads => BinaryBeast::REPLAY_UPLOADS_OPTIONAL,
37
+ :replay_downloads => BinaryBeast::REPLAY_DOWNLOADS_ENABLED,
38
+ :description => nil,
39
+ :return_data => 0,
40
+ }
41
+
42
+ # Tourney Eigenclass
43
+ # Eigenclass
44
+ # ----------------
45
+ # provides some functionality in order to allow certain things before creating a tourney.
46
+ # ----------------
47
+
48
+ class << self
49
+
50
+ # Load
51
+ # Method
52
+ # ----------------
53
+ # Loads a tourney from binarybeast and returns an tourney object.
54
+ # Example:
55
+ # @tourney = Binarybest::Tourney.load(:id => "xSC21212194")
56
+ # ----------------
57
+
58
+ def load(options={:force => false, :id => 'xSC21212194'})
59
+
60
+ #Use this test tournament as a default value for now
61
+ id = options[:id] || options[:tourney_id] || 'xSC21212194'
62
+
63
+ BinaryBeast.call('Tourney.TourneyLoad.Info', :tourney_id => id) do |response|
64
+
65
+ return false if response['result'] != 200
66
+ return response if options[:force]
67
+
68
+ return BinaryBeast::Tournament.new(response['tourney_info'])
69
+
70
+ end
71
+
72
+ end
73
+
74
+
75
+
76
+ # List
77
+ # Method
78
+ # ----------------
79
+ # Loads the List of Tourneys you've created. Returns an array if successful, else false
80
+ # Example:
81
+ # @tourneylist = BinaryBeast::Tourney.list
82
+ # ----------------
83
+
84
+ def list(options={:order => 'date_start'})
85
+ BinaryBeast.call('Tourney.TourneyList.Creator', {:order => 'date_start'}.merge(options)) do |response|
86
+ return response if options[:force]
87
+ return false if response['result'] != 200
88
+
89
+ # return an array of initialized tournaments instead of just the raw data, unless asked otherwise
90
+ return response['list'].map do |tourney|
91
+ BinaryBeast::Tournament.new(tourney)
92
+ end
93
+
94
+ end
95
+ # end Tourney.TourneyList.Popular
96
+
97
+ end
98
+
99
+ # ListPopular
100
+ # Method
101
+ # ----------------
102
+ # Loads the List of Popular Tourneys. Retuns an hash if successful, else false
103
+ # Example:
104
+ # @tourneylist = Binarybeast::Tourney.listpopular
105
+ # ----------------
106
+
107
+ def listPopular(options={:limit => 30})
108
+
109
+ BinaryBeast.call('Tourney.TourneyList.Popular', {:limit => 3}.merge(options)) do |response|
110
+ return false if response['result'] != 200
111
+ return response if options[:force]
112
+
113
+ # return an array of initialized tournaments instead of just the raw data, unless asked otherwise
114
+ return response['list'].map do |tourney|
115
+ BinaryBeast::Tournament.new(tourney)
116
+ end
117
+
118
+ end
119
+ # end Tourney.TourneyList.Popular
120
+
121
+ end
122
+ # end listPopular
123
+
124
+ end
125
+ # END EIGENCLASS
126
+
127
+
128
+
129
+ # Constructor
130
+ # Method
131
+ # ----------------
132
+ # all tourney attributes can be given here. The title parameter is needed, all else is optional.
133
+ # Example:
134
+ # Binarybeast::Tourney.new(:title => "Gamkoi DevCup")
135
+ # ----------------
136
+
137
+ def initialize(options={})
138
+ # Merge the default values and assign all values locally using the base serice classes attribute assigner, saves loads of typing :)
139
+ options[:id] = options[:id] || options['id'] || options[:tourney_id] || options['tourney_id']
140
+ assignAttributes(Tournament::DEFAULTS.merge(options))
141
+ end
142
+
143
+
144
+ # Update
145
+ # Method
146
+ # ----------------
147
+ # Pushes the attributes from the object to the binarybeast api. Pushes updates from object to Binarybeast
148
+ # Example:
149
+ # @tourney = Binarybeast::Tourney.new(:title => "lol")
150
+ # @tourney.title = 'New Title!'
151
+ # @tourney.update
152
+ # ----------------
153
+
154
+ def update(options={:force => false})
155
+ response = BinaryBeast.call('Tourney.TourneyUpdate.Settings', getAttributes.merge({:tourney_id => self.id}) )
156
+ options[:force] ? response : response['result'] == 200 ? true : false
157
+ end
158
+
159
+ # Create
160
+ # Method
161
+ # ----------------
162
+ # Creates the tournament object at binarybeast. You want to call this once after setting up your local Tourney object.
163
+ # Example:
164
+ # @tourney = Binarybeast::Tourny.new
165
+ # @tourney.title = "Blabla"
166
+ # @tourney.description = "Changing some attributes locally..."
167
+ # @tourney.create
168
+ # ----------------
169
+
170
+ def create(options={:force => false})
171
+ response = BinaryBeast.call('Tourney.TourneyCreate.Create', getAttributes)
172
+ self.id = response['tourney_id'] if response['result'] == 200
173
+ options[:force] ? response : response['result'] == 200 ? true : false
174
+ end
175
+
176
+ # Delete
177
+ # Method
178
+ # ----------------
179
+ # Deletes the tourney object from binarybeast. Does not delete the tourney object itself locally.
180
+ # Example:
181
+ # @tourney = Binarybeast::Tourney.new(:title => "Test")
182
+ # @tourney.create
183
+ # @tourney.delete
184
+ # ----------------
185
+
186
+ def delete(options={:force => false})
187
+ response = BinaryBeast.call('Tourney.TourneyDelete.Delete', :tourney_id => self.id)
188
+ options[:force] ? response : response['result'] == 200 ? true : false
189
+ end
190
+
191
+ # Start
192
+ # Method
193
+ # ----------------
194
+ # Starts the object tourney on binarybeast.
195
+ # Example:
196
+ # @tourney = Binarybeast::Tourney.new(:title => "test")
197
+ # @tourney.create
198
+ # @tourney.start
199
+ # ----------------
200
+
201
+ def start(options={:force => false})
202
+
203
+ response = BinaryBeast.call('Tourney.TourneyStart.Start', {
204
+ :tourney_id => self.id,
205
+ :seeding => BinaryBeast::SEEDING_RANDOM
206
+ }.merge(options))
207
+
208
+ options[:force] ? response : response['result'] == 200 ? true : false
209
+
210
+
211
+ end
212
+
213
+ # Load
214
+ # Method
215
+ # ----------------
216
+ # Loads the information of a binarybeast tourney and saving it in the object. Pulling information - inverse of update
217
+ # Example:
218
+ # @tourney = Binarybeast::Tourney.new(:id => 'xSC21212194')
219
+ # @tourney.load
220
+ # ----------------
221
+
222
+ def load(options={:force => false})
223
+
224
+ response = BinaryBeast.call('Tourney.TourneyLoad.Info', {:tourney_id => self.id}.merge(options))
225
+
226
+ return response if options[:force]
227
+ return false if response['result']
228
+
229
+ self.assignAttributes(response['tourney_info'])
230
+ return true
231
+ end
232
+
233
+ # setBuilding
234
+ # Method
235
+ # ----------------
236
+ # Sets the status of the tourney correlating to the object to: Status: Building
237
+ # Example:
238
+ # @tourney = Binarybeast::Tourney.new
239
+ # @tourney.setBuilding
240
+ # ----------------
241
+
242
+ def setBuilding(options={:force => false})
243
+ response = BinaryBeast.call('Tourney.TourneySetStatus.Building', :tourney_id => self.id)
244
+ options[:force] ? response : response['result'] == 200 ? true : false
245
+ end
246
+
247
+
248
+ # setConfirmation
249
+ # Method
250
+ # ----------------
251
+ # Sets the status of the tourney correlating to the object to: Status: Confirmation
252
+ # Example:
253
+ # @tourney = BinaryBeast::Tourney.new
254
+ # @tourney.setConfirmation
255
+ # ----------------
256
+
257
+ def setConfirmation(options={:force => false})
258
+ response = BinaryBeast.call('Tourney.TourneySetStatus.Confirmation', :tourney_id => self.id)
259
+ options[:force] ? response : response['result'] == 200 ? true : false
260
+ end
261
+
262
+ end
263
+ # END Class Tournament
264
+ end
@@ -1,3 +1,3 @@
1
- module Binarybeast
2
- VERSION = "0.1.5.pre"
3
- end
1
+ module BinaryBeast
2
+ VERSION = "0.2.0.pre"
3
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Binarybeast do
3
+ describe BinaryBeast do
4
4
  it "must have apikey variable" do
5
- Binarybeast.api_key.should == "3c8955130c6e1406420d6202649651fe.50c9faa593f9c6.00530099"
5
+ BinaryBeast.api_key.should == "3c8955130c6e1406420d6202649651fe.50c9faa593f9c6.00530099"
6
6
  end
7
7
  it "should have a raw call method" do
8
- Binarybeast.should respond_to(:call)
8
+ BinaryBeast.should respond_to(:call)
9
9
  end
10
10
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Binarybeast::Team do
3
+ describe BinaryBeast::Team do
4
4
  it "should work" do
5
5
  end
6
6
  end
@@ -1,114 +1,117 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Binarybeast::Tourney do
3
+ describe BinaryBeast::Tournament do
4
4
  before :all do
5
- @tourney = Binarybeast::Tourney.new(:title => "Gamkoi DevTest Ruby", :description => "This is a tourney created via the Gamkoi.com ruby gem.")
5
+ @tournament = BinaryBeast::Tournament.new(:title => 'Gamkoi DevTest Ruby', :description => 'This is a tourney created via the Gamkoi.com ruby gem.', :game_code => 'HotS')
6
6
  end
7
7
  describe "eigenclass" do
8
8
  describe "list" do
9
- it "should return list of tourneys" do
10
- response = Binarybeast::Tourney.list
11
- response.should be_instance_of Hash
9
+ it "should return array of tourneys" do
10
+ response = BinaryBeast::Tournament.list
11
+ response.should be_instance_of Array
12
12
  end
13
13
  end
14
- describe "listpopular" do
14
+ describe "listPopular" do
15
15
  it "should return list of popular tourneys" do
16
- response = Binarybeast::Tourney.listpopular
17
- response.should be_instance_of Hash
16
+ response = BinaryBeast::Tournament.listPopular
17
+ response.should be_instance_of Array
18
18
  end
19
19
  end
20
20
  describe "load" do
21
21
  it "should load from eigenclass" do
22
- tourney = Binarybeast::Tourney.load(:id => "xSC21212194")
23
- tourney.should be_an_instance_of Binarybeast::Tourney
24
- tourney.title.should eq("Gamkoi Dev Dummy")
22
+ tournament = BinaryBeast::Tournament.load(:id => @tournament.tourney_id)
23
+ tournament.should be_an_instance_of BinaryBeast::Tournament
24
+ tournament.title.should eq('Gamkoi DevTest Ruby')
25
25
  end
26
26
  end
27
27
  end
28
28
  describe "new" do
29
29
  it "takes one to all parameters and returns an tourney object" do
30
- @tourney.should be_an_instance_of Binarybeast::Tourney
30
+ @tournament.should be_an_instance_of BinaryBeast::Tournament
31
31
  end
32
32
  it "should respond to title" do
33
- @tourney.title.should eq("Gamkoi DevTest Ruby")
33
+ @tournament.title.should eq('Gamkoi DevTest Ruby')
34
34
  end
35
35
  it "should respond to description" do
36
- @tourney.description.should eq("This is a tourney created via the Gamkoi.com ruby gem.")
36
+ @tournament.description.should eq('This is a tourney created via the Gamkoi.com ruby gem.')
37
37
  end
38
38
  it "should respond to all attributes" do
39
- @tourney.should respond_to(:title)
40
- @tourney.should respond_to(:id)
41
- @tourney.should respond_to(:publish)
42
- @tourney.should respond_to(:game_code)
43
- @tourney.should respond_to(:type_id)
44
- @tourney.should respond_to(:elimination)
45
- @tourney.should respond_to(:team_mode)
46
- @tourney.should respond_to(:group_count)
47
- @tourney.should respond_to(:teams_from_group)
48
- @tourney.should respond_to(:date_start)
49
- @tourney.should respond_to(:location)
50
- @tourney.should respond_to(:max_teams)
51
- @tourney.should respond_to(:replay_uploads)
52
- @tourney.should respond_to(:replay_downloads)
53
- @tourney.should respond_to(:description)
54
- @tourney.should respond_to(:return_data)
55
- @tourney.should respond_to(:api_key)
56
- end
57
- end
58
- describe "update" do
59
- it "should respond to update" do
60
- @tourney.should respond_to(:update)
61
- response = @tourney.update(:force => true)
62
- response.should be_instance_of Hash
39
+ @tournament.should respond_to(:title)
40
+ @tournament.should respond_to(:id)
41
+ @tournament.should respond_to(:public)
42
+ @tournament.should respond_to(:game_code)
43
+ @tournament.should respond_to(:type_id)
44
+ @tournament.should respond_to(:elimination)
45
+ @tournament.should respond_to(:team_mode)
46
+ @tournament.should respond_to(:group_count)
47
+ @tournament.should respond_to(:teams_from_group)
48
+ @tournament.should respond_to(:date_start)
49
+ @tournament.should respond_to(:location)
50
+ @tournament.should respond_to(:max_teams)
51
+ @tournament.should respond_to(:replay_uploads)
52
+ @tournament.should respond_to(:replay_downloads)
53
+ @tournament.should respond_to(:description)
54
+ @tournament.should respond_to(:return_data)
55
+ @tournament.should respond_to(:api_key)
63
56
  end
64
57
  end
65
58
  describe "create" do
66
59
  it "should respond to publish" do
67
- @tourney.should respond_to(:publish)
60
+ @tournament.should respond_to(:public)
68
61
  end
69
62
  it "should return parsed json array" do
70
- @tourney.create.should eq(true)
63
+ @tournament.create.should eq(true)
71
64
  end
72
65
  it "should return forced broadcast" do
73
- response = @tourney.create(:force => true)
74
- response["Result"].should eq(200)
66
+ response = @tournament.create(:force => true)
67
+ response['result'].should eq(200)
68
+ response.should be_instance_of Hash
69
+ end
70
+ end
71
+ describe "update" do
72
+ it "should respond to update" do
73
+ @tournament.should respond_to(:update)
74
+ response = @tournament.update(:force => true)
75
75
  response.should be_instance_of Hash
76
76
  end
77
77
  end
78
78
  describe "delete" do
79
79
  it "should respond to delete" do
80
- @tourney.should respond_to(:delete)
80
+ @tournament.should respond_to(:delete)
81
81
  end
82
82
  it "should delete the tourney" do
83
- tourney = Binarybeast::Tourney.new(:title => "Delete Test")
84
- tourney.create
85
- response = tourney.delete(:force => true)
83
+ tournament = BinaryBeast::Tournament.new(:title => "Delete Test")
84
+ tournament.create
85
+ response = tournament.delete(:force => true)
86
86
  response.should be_instance_of Hash
87
87
  end
88
88
  end
89
89
  describe "start" do
90
90
  it "should respond to start" do
91
- @tourney.should respond_to(:start)
91
+ @tournament.should respond_to(:start)
92
92
  end
93
93
  it "should start the tourney" do
94
+ #@tournament.start
95
+ #@tournament.load
96
+ #@tournament.status.should eq('Active')
94
97
  end
95
98
  end
96
99
  describe "load" do
97
100
  it "should respond to load" do
98
- @tourney.should respond_to(:load)
101
+ @tournament.should respond_to(:load)
99
102
  end
100
103
  it "should load a tourney and set attributes" do
101
- tourney = Binarybeast::Tourney.new(:id => "xSC21212194")
102
- tourney.load
103
- tourney.title.should eq("Gamkoi Dev Dummy")
104
+ tournament = BinaryBeast::Tournament.load(:id => @tournament.tourney_id)
105
+ tournament.load
106
+ tournament.title.should eq("Gamkoi DevTest Ruby")
104
107
  end
105
108
  end
106
109
  describe "set status" do
107
110
  it "should respond to building" do
108
- @tourney.should respond_to(:setBuilding)
111
+ @tournament.should respond_to(:setBuilding)
109
112
  end
110
113
  it "should respond to confirmation" do
111
- @tourney.should respond_to(:setConfirmation)
114
+ @tournament.should respond_to(:setConfirmation)
112
115
  end
113
116
  end
114
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binarybeast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.pre
4
+ version: 0.2.0.pre
5
5
  prerelease: 6
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: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -89,8 +89,10 @@ files:
89
89
  - Rakefile
90
90
  - binarybeast.gemspec
91
91
  - lib/binarybeast.rb
92
+ - lib/binarybeast/constants.rb
93
+ - lib/binarybeast/service.rb
92
94
  - lib/binarybeast/team.rb
93
- - lib/binarybeast/tourney.rb
95
+ - lib/binarybeast/tournament.rb
94
96
  - lib/binarybeast/version.rb
95
97
  - spec/binarybeast_spec.rb
96
98
  - spec/spec_helper.rb
@@ -1,271 +0,0 @@
1
- module Binarybeast
2
- # Tourney
3
- # Class
4
- # ---------------
5
- # This is the Tourney class. It will be used to most. It gives you a brand new Tourney object to call methods on.
6
- # Example:
7
- # tourney = Binarybeast::Tourney.new("Gamkoi Test")
8
- # ---------------
9
- # gives you a tourney object
10
-
11
- class Tourney
12
- include HTTParty
13
- base_uri 'https://binarybeast.com/api'
14
- format :json
15
- attr_accessor :api_key, :id, :title, :publish, :game_code, :type_id, :elimination, :team_mode, :group_count, :teams_from_group, :date_start, :location, :max_teams, :replay_uploads, :replay_downloads, :description, :return_data
16
-
17
- # Tourney Eigenclass
18
- # Eigenclass
19
- # ----------------
20
- # provides some functionality in order to allow certain things before creating a tourney.
21
- # ----------------
22
-
23
- class << self
24
- include HTTParty
25
- format :json
26
-
27
- # Load
28
- # Method
29
- # ----------------
30
- # Loads a tourney from binarybeast and returns an tourney object.
31
- # Example:
32
- # @tourney = Binarybest::Tourney.load(:id => "xSC21212194")
33
- # ----------------
34
-
35
- def load(options={:force => false})
36
- options[:id] ? id = options[:id] : id = "xSC21212194"
37
- options[:force] ? force = options[:force] : force = false
38
- response = self.get('https://binarybeast.com/api', :query => {:APIKey => Binarybeast.api_key, :APIService => "Tourney.TourneyLoad.Info", :TourneyID => id})
39
- if response["Result"] == 200
40
- return response if force
41
- tourney = Binarybeast::Tourney.new( :id => id,
42
- :title => response["TourneyInfo"]["Title"],
43
- :publish => response["TourneyInfo"]["Public"],
44
- :game_code => response["TourneyInfo"]["GameCode"],
45
- :type_id => response["TourneyInfo"]["TypeID"],
46
- :elimination => response["TourneyInfo"]["Elimination"],
47
- :team_mode => response["TourneyInfo"]["TeamMode"],
48
- :group_count => response["TourneyInfo"]["GroupCount"],
49
- :teams_from_group => response["TourneyInfo"]["TeamsFromGroup"],
50
- :date_start => response["TourneyInfo"]["DateStart"],
51
- :location => response["TourneyInfo"]["Location"],
52
- :max_teams => response["TourneyInfo"]["MaxTeams"],
53
- :replay_uploads => response["TourneyInfo"]["ReplayUploads"],
54
- :replay_downloads => response["TourneyInfo"]["ReplayDownloads"],
55
- :description => response["TourneyInfo"]["Description"],
56
- :return_data => response["TourneyInfo"]["ReturnData"],
57
- :api_key => Binarybeast.api_key)
58
- return tourney
59
- else
60
- return false
61
- end
62
- end
63
-
64
- # List
65
- # Method
66
- # ----------------
67
- # Loads the List of Tourneys you've created. Returns an hash if successful, else false
68
- # Example:
69
- # @tourneylist = Binarybeast::Tourney.list
70
- # ----------------
71
-
72
- def list(options={:order => "DateStart"})
73
- options[:api_key] ? api_key = options[:api_key] : api_key = Binarybeast.api_key
74
- options[:order] ? order = options[:order] : order = "DateStart"
75
- options[:direction] ? direction = options[:direction] : direction = "DESC"
76
- options[:verbose] ? verbose = options[:verbose] : verbose = false
77
- response = self.get('https://binarybeast.com/api', :query => {:APIKey => api_key, :APIService => "Tourney.TourneyList.My", :Order => order, :Direction => direction, :Verbose => verbose})
78
- response["Result"] == 200 ? response : false
79
- end
80
-
81
- # ListPopular
82
- # Method
83
- # ----------------
84
- # Loads the List of Popular Tourneys. Retuns an hash if successful, else false
85
- # Example:
86
- # @tourneylist = Binarybeast::Tourney.listpopular
87
- # ----------------
88
-
89
- def listpopular(options={:limit => 30})
90
- options[:limit] ? limit = options[:limit] : limit = 30
91
- options[:api_key] ? api_key = options[:api_key] : api_key = Binarybeast.api_key
92
- response = self.get('https://binarybeast.com/api', :query => {:APIKey => api_key, :APIService => "Tourney.TourneyList.Popular", :Limit => limit})
93
- response["Result"] == 200 ? response : false
94
- end
95
-
96
- end
97
-
98
- # END EIGENCLASS
99
-
100
-
101
-
102
- # Constructor
103
- # Method
104
- # ----------------
105
- # all tourney attributes can be given here. The title parameter is needed, all else is optional.
106
- # Example:
107
- # Binarybeast::Tourney.new(:title => "Gamkoi DevCup")
108
- # ----------------
109
-
110
- def initialize(options={:title => "Gamkoi DevTest"})
111
- self.id = options[:id] if options[:id]
112
- options[:title] ? self.title = options[:title] : self.title = "Test"
113
- options[:public] ? self.publish = options[:public] : self.publish = 0
114
- options[:game_code] ? self.game_code = options[:game_code] : self.game_code = ""
115
- options[:type_id] ? self.type_id = options[:type_id] : self.type_id = 0
116
- options[:elimination] ? self.elimination = options[:elimination] : self.elimination = 1
117
- options[:team_mode] ? self.team_mode = options[:team_mode] : self.team_mode = 1
118
- options[:group_count] ? self.group_count = options[:group_count] : self.group_count = 1
119
- options[:teams_from_group] ? self.teams_from_group = options[:teams_from_group] : self.teams_from_group = 2
120
- options[:date_start] ? self.date_start = options[:date_start] : self.date_start = nil
121
- options[:location] ? self.location = options[:location] : self.location = ""
122
- options[:max_teams] ? self.max_teams = options[:max_teams] : self.max_teams = 16
123
- options[:replay_uploads] ? self.replay_uploads = options[:replay_uploads] : self.replay_uploads = 1
124
- options[:replay_downloads] ? self.replay_downloads = options[:replay_downloads] : self.replay_downloads = 1
125
- options[:description] ? self.description = options[:description] : self.description = ""
126
- options[:return_data] ? self.return_data = options[:return_data] : self.return_data = 0
127
- options[:api_key] ? self.api_key = options[:api_key] : self.api_key = Binarybeast.api_key
128
- end
129
-
130
-
131
- # Update
132
- # Method
133
- # ----------------
134
- # Pushes the attributes from the object to the binarybeast api. Pushes updates from object to Binarybeast
135
- # Example:
136
- # @tourney = Binarybeast::Tourney.new(:title => "lol")
137
- # @tourney.update
138
- # ----------------
139
-
140
- def update(options={:force => false})
141
- response = self.class.get("", :query => {:TourneyID => self.id, :APIKey => self.api_key, :APIService => "Tourney.TourneyUpdate.Settings",
142
- :Title => self.title, :Public => self.publish, :game_code => self.game_code,
143
- :TypeID => self.type_id, :Elimination => self.elimination,
144
- :TeamMode => self.team_mode, :GroupCount => self.group_count,
145
- :TeamsFromGroup => self.teams_from_group, :DateStart => self.date_start,
146
- :Location => self.location, :MaxTeams => self.max_teams, :ReplayUploads => self.replay_uploads,
147
- :ReplayDownloads => self.replay_downloads, :Description => self.description, :ReturnData => self.return_data})
148
- options[:force] ? response : response["Result"] == 200 ? true : false
149
- end
150
-
151
- # Create
152
- # Method
153
- # ----------------
154
- # Creates the tournament object at binarybeast. You want to call this once after setting up your local Tourney object.
155
- # Example:
156
- # @tourney = Binarybeast::Tourny.new
157
- # @tourney.title = "Blabla"
158
- # @tourney.description = "Changing some attributes locally..."
159
- # @tourney.create
160
- # ----------------
161
-
162
- def create(options={:force => false})
163
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneyCreate.Create",
164
- :Title => self.title, :Public => self.publish, :GameCode => self.game_code,
165
- :TypeID => self.type_id, :Elimination => self.elimination,
166
- :TeamMode => self.team_mode, :GroupCount => self.group_count,
167
- :TeamsFromGroup => self.teams_from_group, :DateStart => self.date_start,
168
- :Location => self.location, :MaxTeams => self.max_teams, :ReplayUploads => self.replay_uploads,
169
- :ReplayDownloads => self.replay_downloads, :Description => self.description, :ReturnData => self.return_data})
170
- self.id = response["TourneyID"] if response["Result"] == 200
171
- options[:force] ? response : response["Result"] == 200 ? true : false
172
- end
173
-
174
- # Delete
175
- # Method
176
- # ----------------
177
- # Deletes the tourney object from binarybeast. Does not delete the tourney object itself locally.
178
- # Example:
179
- # @tourney = Binarybeast::Tourney.new(:title => "Test")
180
- # @tourney.create
181
- # @tourney.delete
182
- # ----------------
183
-
184
- def delete(options={:force => false})
185
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneyDelete.Delete", :TourneyID => self.id})
186
- options[:force] ? response : response["Result"] == 200 ? true : false
187
- end
188
-
189
- # Start
190
- # Method
191
- # ----------------
192
- # Starts the object tourney on binarybeast.
193
- # Example:
194
- # @tourney = Binarybeast::Tourney.new(:title => "test")
195
- # @tourney.create
196
- # @tourney.start
197
- # ----------------
198
-
199
- def start(options={:force => false})
200
- options[:force] ? force = true : force = false
201
- options[:seeding] ? seeding = options[:seeding] : seeding = "random"
202
- options[:teams] ? teams = options[:teams] : teams = nil
203
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneyStart.Start", :Seeding => seeding, :Teams => teams, :TourneyID => self.id})
204
- options[:force] ? response : response["Result"] == 200 ? true : false
205
- end
206
-
207
- # Load
208
- # Method
209
- # ----------------
210
- # Loads the information of a binarybeast tourney and saving it in the object. Pulling information - inverse of update
211
- # Example:
212
- # @tourney = Binarybeast::Tourney.new(:id => "xSC21212194")
213
- # @tourney.load
214
- # ----------------
215
-
216
- def load(options={:force => false})
217
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneyLoad.Info", :TourneyID => self.id})
218
- return response if options[:force]
219
- if response["Result"] == 200
220
- self.title = response["TourneyInfo"]["Title"]
221
- self.publish = response["TourneyInfo"]["Public"]
222
- self.game_code = response["TourneyInfo"]["GameCode"]
223
- self.type_id = response["TourneyInfo"]["TypeID"]
224
- self.elimination = response["TourneyInfo"]["Elimination"]
225
- self.team_mode = response["TourneyInfo"]["TeamMode"]
226
- self.group_count = response["TourneyInfo"]["GroupCount"]
227
- self.teams_from_group = response["TourneyInfo"]["TeamsFromGroup"]
228
- self.date_start = response["TourneyInfo"]["DateStart"]
229
- self.location = response["TourneyInfo"]["Location"]
230
- self.max_teams = response["TourneyInfo"]["MaxTeams"]
231
- self.replay_uploads = response["TourneyInfo"]["ReplayUploads"]
232
- self.replay_downloads = response["TourneyInfo"]["ReplayDownloads"]
233
- self.description = response["TourneyInfo"]["Description"]
234
- self.return_data = response["TourneyInfo"]["ReturnData"]
235
- return true
236
- else
237
- return false
238
- end
239
- end
240
-
241
- # setBuilding
242
- # Method
243
- # ----------------
244
- # Sets the status of the tourney correlating to the object to: Status: Building
245
- # Example:
246
- # @tourney = Binarybeast::Tourney.new
247
- # @tourney.setBuilding
248
- # ----------------
249
-
250
- def setBuilding(options={:force => false})
251
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneySetStatus.Building", :TourneyID => self.id})
252
- options[:force] ? response : response["Result"] == 200 ? true : false
253
- end
254
-
255
- # setConfirmation
256
- # Method
257
- # ----------------
258
- # Sets the status of the tourney correlating to the object to: Status: Confirmation
259
- # Example:
260
- # @tourney = Binarybeast::Tourney.new
261
- # @tourney.setConfirmation
262
- # ----------------
263
-
264
- def setConfirmation(options={:force => false})
265
- response = self.class.get("", :query => {:APIKey => self.api_key, :APIService => "Tourney.TourneySetStatus.Confirmation", :TourneyID => self.id})
266
- options[:force] ? response : response["Result"] == 200 ? true : false
267
- end
268
-
269
- end
270
- # END Class Tourney
271
- end