allplayers 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  allplayers.rb
2
2
  =============
3
3
 
4
- AllPlayers.com ruby client https://www.allplayers.com
4
+ AllPlayers.com, Inc. Ruby client for public API.
5
5
 
6
- AllPlayer.com, Inc. Ruby client for importing users, groups, events, etc via
7
- REST API.
6
+ Can be installed as a gem, <code>sudo gem install allplayers</code>
8
7
 
9
8
  Requires Ruby + Rubygems and the following:
10
9
 
@@ -19,9 +18,3 @@ sudo gem install bundler
19
18
  # run bundler
20
19
  bundle install
21
20
 
22
- export APCI_REST_TEST_HOST=host.allplayers.com
23
- export APCI_REST_TEST_USER=user
24
- export APCI_REST_TEST_PASS=password
25
-
26
- then 'rake test'.
27
-
data/allplayers.gemspec CHANGED
@@ -1,15 +1,16 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |spec|
3
- spec.add_dependency 'activesupport', ['2.3.10']
4
- spec.add_dependency 'addressable', ['~> 2.2.7']
5
- spec.add_dependency 'rake', ['~> 0.9.2.2']
6
- spec.add_dependency 'rest-client', ['~> 1.6.7']
7
- spec.add_dependency 'xml-simple', ['~> 1.1.1']
3
+ spec.add_dependency 'rake', ['>= 10.0.3']
4
+ spec.add_dependency 'rack', ['>= 1.4.0']
5
+ spec.add_dependency 'rest-client', ['>= 1.6.7']
6
+ spec.add_dependency 'xml-simple', ['>= 1.1.1']
7
+ spec.add_dependency 'json', ['1.7.6']
8
+ spec.add_dependency 'oauth', ['>= 0.4.7']
8
9
  spec.add_development_dependency 'rspec'
9
10
  spec.authors = ["AllPlayers.com"]
10
11
  spec.description = %q{A Ruby interface to the AllPlayers API.}
11
12
  spec.email = ['support@allplayers.com']
12
- spec.files = %w(README.md Rakefile allplayers.gemspec)
13
+ spec.files = %w(README.md allplayers.gemspec)
13
14
  spec.files += Dir.glob("lib/**/*.rb")
14
15
  spec.files += Dir.glob("spec/**/*")
15
16
  spec.homepage = 'http://www.allplayers.com/'
@@ -19,5 +20,5 @@ Gem::Specification.new do |spec|
19
20
  spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
20
21
  spec.summary = spec.description
21
22
  spec.test_files = Dir.glob("spec/**/*")
22
- spec.version = '0.1.0'
23
- end
23
+ spec.version = '0.1.2'
24
+ end
@@ -1,27 +1,32 @@
1
+ require 'allplayers/request'
2
+ require 'allplayers/authentication'
1
3
  require 'addressable/uri'
2
- require 'xmlsimple'
3
- require 'logger'
4
- require 'active_support/base64'
5
4
  require 'restclient'
6
- require 'allplayers/authentication'
7
- require 'allplayers/request'
8
5
 
9
6
  module AllPlayers
10
7
  class API
8
+
11
9
  include Request
12
10
  include Authentication
13
11
  attr_accessor :logger
14
12
 
15
- def initialize(api_key = nil, server = 'sandbox.allplayers.com', protocol = 'https://', auth = 'session')
16
- if (auth == 'session')
13
+ def initialize(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil)
14
+ @base_uri = server
15
+ if (auth == 'basic')
17
16
  extend AllPlayers::Authentication
18
17
  end
19
- @base_uri = Addressable::URI.join(protocol + server, '')
20
- @key = api_key # TODO - Not implemented in API yet.
21
- @session_cookies = {}
18
+ @access_token = access_token
22
19
  @headers = {}
23
20
  end
24
21
 
22
+ # Exchange your oauth_token and oauth_token_secret for an AccessToken instance.
23
+ def prepare_access_token(oauth_token, oauth_token_secret, consumer_token, consumer_secret)
24
+ consumer = OAuth::Consumer.new(consumer_token, consumer_secret, {:site => @base_uri})
25
+ # now create the access token object from passed values
26
+ token_hash = {:oauth_token => oauth_token, :oauth_token_secret => oauth_token_secret}
27
+ @access_token = OAuth::AccessToken.from_hash(consumer, token_hash)
28
+ end
29
+
25
30
  def log(target)
26
31
  @log = target
27
32
  RestClient.log = target
@@ -38,5 +43,6 @@ module AllPlayers
38
43
  @headers.delete(header)
39
44
  end
40
45
  end
46
+
41
47
  end
42
48
  end
@@ -0,0 +1,15 @@
1
+ module AllPlayers
2
+ module Forms
3
+ def get_submission(form_uuid, submission_id = nil, user_uuid = nil, key_values = {}, html = 0)
4
+ if submission_id.nil?
5
+ get 'forms/' + form_uuid + '/submissions', {:user_uuid => user_uuid, :key_values => key_values, :html => html}
6
+ else
7
+ get 'forms/' + form_uuid + '/submissions/' + submission_id.to_s, {:html => html, :user_uuid => user_uuid}
8
+ end
9
+ end
10
+
11
+ def assign_submission(form_uuid, submission_id, user_uuid, html = 0)
12
+ post 'forms/' + form_uuid + '/assign_submission/' + submission_id.to_s, {:user_uuid => user_uuid, :html => html}
13
+ end
14
+ end
15
+ end
@@ -34,12 +34,20 @@ module AllPlayers
34
34
  put 'groups/' + group_uuid, params
35
35
  end
36
36
 
37
- def group_members_list(group_uuid, user_uuid = '', params = {})
38
- get 'groups/' + group_uuid + '/members/' + user_uuid, params
39
- end
40
-
41
- def group_roles_list(group_uuid, user_uuid = '', params = {})
42
- get 'groups/' + group_uuid + '/roles/' + user_uuid, params
37
+ def group_members_list(group_uuid, user_uuid = nil, params = {})
38
+ if user_uuid.nil?
39
+ get 'groups/' + group_uuid + '/members', params
40
+ else
41
+ get 'groups/' + group_uuid + '/members/' + user_uuid, params
42
+ end
43
+ end
44
+
45
+ def group_roles_list(group_uuid, user_uuid = nil, params = {})
46
+ if user_uuid.nil?
47
+ get 'groups/' + group_uuid + '/roles', params
48
+ else
49
+ get 'groups/' + group_uuid + '/roles/' + user_uuid, params
50
+ end
43
51
  end
44
52
  end
45
53
  end
@@ -37,8 +37,8 @@ module AllPlayers
37
37
  get 'users/' + user_uuid + '/groups', params
38
38
  end
39
39
 
40
- def user_join_group(group_uuid, user_uuid, role_name = nil, options = {}, webform_ids = {})
41
- post 'groups/' + group_uuid + '/join/' + user_uuid, {:org_webform_id => webform_ids, :role_name => role_name.to_s, :role_options => options}
40
+ def user_join_group(group_uuid, user_uuid, role_name = nil, options = {}, webform_id = nil)
41
+ post 'groups/' + group_uuid + '/join/' + user_uuid, {:org_webform_uuid => webform_id, :role_name => role_name.to_s, :role_options => options}
42
42
  end
43
43
 
44
44
  def user_group_add_role(group_uuid, user_uuid, role_uuid, params = {})
@@ -5,12 +5,25 @@ module AllPlayers
5
5
  require 'rubygems'
6
6
  require 'bundler/setup'
7
7
  require 'restclient'
8
+ require 'json'
8
9
  require 'addressable/uri'
10
+ require 'xmlsimple'
11
+ require 'logger'
12
+ require 'active_support/base64'
9
13
  require 'allplayers/client/events'
10
14
  require 'allplayers/client/users'
11
15
  require 'allplayers/client/groups'
16
+ require 'allplayers/client/forms'
17
+ require 'allplayers/authentication'
18
+ require 'allplayers/error'
19
+ require 'allplayers/rate_limit'
20
+ require 'allplayers/error/decode_error'
21
+ require 'allplayers/error/restclient_error'
22
+ require 'oauth'
23
+ require 'rack'
12
24
  include AllPlayers::Events
13
25
  include AllPlayers::Users
14
26
  include AllPlayers::Groups
27
+ include AllPlayers::Forms
15
28
  end
16
29
  end
@@ -0,0 +1,9 @@
1
+ require 'allplayers/error'
2
+
3
+ module AllPlayers
4
+ class Error
5
+ # Raised when JSON parsing fails
6
+ class DecodeError < AllPlayers::Error
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ require 'allplayers/error'
2
+
3
+ module AllPlayers
4
+ class Error
5
+ # Raised when AllPlayers returns a 4xx HTTP status code or there's an error in Faraday
6
+ class ClientError < AllPlayers::Error
7
+
8
+ # Create a new error from an HTTP environment
9
+ #
10
+ # @param response [Hash]
11
+ # @return [AllPlayers::Error]
12
+ def self.from_response(response={})
13
+ new(parse_error(response[:body]), response[:response_headers])
14
+ end
15
+
16
+ private
17
+
18
+ def self.parse_error(body)
19
+ if body.nil?
20
+ ''
21
+ elsif body[:error]
22
+ body[:error]
23
+ elsif body[:errors]
24
+ first = Array(body[:errors]).first
25
+ if first.is_a?(Hash)
26
+ first[:message].chomp
27
+ else
28
+ first.chomp
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ module AllPlayers
2
+ # Custom error class for rescuing from all AllPlayers errors
3
+ class Error < StandardError
4
+ attr_reader :rate_limit, :wrapped_exception
5
+
6
+ # @return [Hash]
7
+ def self.errors
8
+ @errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
9
+ end
10
+
11
+ # @return [Array]
12
+ def self.descendants
13
+ ObjectSpace.each_object(::Class).select{|klass| klass < self}
14
+ end
15
+
16
+ # Initializes a new Error object
17
+ #
18
+ # @param exception [Exception, String]
19
+ # @param response_headers [Hash]
20
+ # @return [AllPlayers::Error]
21
+ def initialize(exception=$!, response_headers={})
22
+ @rate_limit = AllPlayers::RateLimit.new(response_headers)
23
+ @wrapped_exception = exception
24
+ exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
25
+ end
26
+
27
+ def backtrace
28
+ @wrapped_exception.respond_to?(:backtrace) ? @wrapped_exception.backtrace : super
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ module AllPlayers
2
+ class RateLimit
3
+ attr_reader :attrs
4
+ alias to_hash attrs
5
+
6
+ # @return [Twitter::RateLimit]
7
+ def initialize(attrs={})
8
+ @attrs = attrs
9
+ end
10
+
11
+ # @return [Integer]
12
+ def limit
13
+ limit = @attrs['x-rate-limit-limit']
14
+ limit.to_i if limit
15
+ end
16
+
17
+ # @return [Integer]
18
+ def remaining
19
+ remaining = @attrs['x-rate-limit-remaining']
20
+ remaining.to_i if remaining
21
+ end
22
+
23
+ # @return [Time]
24
+ def reset_at
25
+ reset = @attrs['x-rate-limit-reset']
26
+ Time.at(reset.to_i) if reset
27
+ end
28
+
29
+ # @return [Integer]
30
+ def reset_in
31
+ [(reset_at - Time.now).ceil, 0].max if reset_at
32
+ end
33
+ alias retry_after reset_in
34
+
35
+ # Update the attributes of a RateLimit
36
+ #
37
+ # @param attrs [Hash]
38
+ # @return [Twitter::RateLimit]
39
+ def update(attrs)
40
+ @attrs.update(attrs)
41
+ self
42
+ end
43
+
44
+ end
45
+ end
@@ -23,31 +23,37 @@ module AllPlayers
23
23
  # Perform an HTTP request
24
24
  def request(verb, path, query = {}, payload = {}, headers = {})
25
25
  begin
26
- uri = Addressable::URI.join(@base_uri, 'api/v1/rest/'+path.to_s)
27
- uri.query_values = query unless query.empty?
26
+ uri = Addressable::URI.join(@base_uri, 'api/v1/rest/'+path.to_s+'.json')
27
+ query_params = Rack::Utils.build_nested_query(query)
28
+ string_uri = uri.to_s
29
+ string_uri = string_uri + '?' + query_params
28
30
  headers.merge!(@headers) unless @headers.empty?
29
- RestClient.log = @log
30
- RestClient.open_timeout = 600
31
- RestClient.timeout = 600
31
+
32
+ # Use access_token if this is oauth authentication.
33
+ unless @access_token.nil?
34
+ if [:patch, :post, :put].include? verb
35
+ response = @access_token.request(verb, uri.to_s, payload, headers)
36
+ else
37
+ response = @access_token.request(verb, string_uri, headers)
38
+ end
39
+ return JSON.parse(response.body) if response.code == '200'
40
+ return 'No Content' if response.code == '204'
41
+ end
42
+
43
+ # Use RestClient if using basic auth.
32
44
  if [:patch, :post, :put].include? verb
33
45
  response = RestClient.send(verb, uri.to_s, payload, headers)
34
46
  else
35
- response = RestClient.send(verb, uri.to_s, headers)
47
+ response = RestClient.send(verb, string_uri, headers)
36
48
  end
37
- # Had to remove any html tags before the xml because xmlsimple was reading the hmtl errors on pdup and was crashing.
38
- return response unless response.net_http_res.body
39
- xml_response = '<?xml' + response.split("<?xml").last
40
- html_response = response.split("<?xml").first
41
- puts html_response if !html_response.empty?
42
- # @TODO - There must be a way to change the base object (XML string to
43
- # Hash) while keeping the methods...
44
- array_response = XmlSimple.xml_in(xml_response, { 'ForceArray' => ['item'] })
45
- return array_response if array_response.empty? || array_response.include?('item') || array_response['item'].nil?
46
- return array_response['item'].first if array_response['item'].length == 1
47
- array_response['item']
48
- rescue REXML::ParseException => xml_err
49
- # XML Parser error
50
- raise "Failed to parse server response."
49
+ return JSON.parse(response) if response.code == 200
50
+ return 'No Content' if response.code == 204
51
+ rescue RestClient::Exception
52
+ raise AllPlayers::Error::ClientError
53
+ rescue JSON::ParserError
54
+ raise AllPlayers::Error::DecodeError
55
+ rescue Exception
56
+ raise AllPlayers::Error::ClientError
51
57
  end
52
58
  end
53
59
  end
data/lib/allplayers.rb CHANGED
@@ -7,8 +7,13 @@ require 'allplayers/configuration'
7
7
  module AllPlayers
8
8
  extend Configuration
9
9
  class << self
10
- def new(options={})
11
- AllPlayers::Client.new(options)
10
+ def new(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil)
11
+ @client = AllPlayers::Client.new(server, auth, access_token)
12
+ end
13
+
14
+ def client(server = 'https://www.allplayers.com', auth = 'basic', access_token = nil)
15
+ @client = AllPlayers::Client.new(server, auth, access_token) unless defined?(@client)
16
+ @client
12
17
  end
13
18
  end
14
19
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allplayers
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - AllPlayers.com
@@ -15,93 +15,108 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-01-16 00:00:00 Z
18
+ date: 2013-03-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: activesupport
21
+ name: rake
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - "="
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- hash: 23
28
+ hash: 73
29
29
  segments:
30
- - 2
31
- - 3
32
30
  - 10
33
- version: 2.3.10
31
+ - 0
32
+ - 3
33
+ version: 10.0.3
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: addressable
37
+ name: rack
38
38
  prerelease: false
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- hash: 9
44
+ hash: 7
45
45
  segments:
46
- - 2
47
- - 2
48
- - 7
49
- version: 2.2.7
46
+ - 1
47
+ - 4
48
+ - 0
49
+ version: 1.4.0
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: rake
53
+ name: rest-client
54
54
  prerelease: false
55
55
  requirement: &id003 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
- - - ~>
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- hash: 11
60
+ hash: 1
61
61
  segments:
62
- - 0
63
- - 9
64
- - 2
65
- - 2
66
- version: 0.9.2.2
62
+ - 1
63
+ - 6
64
+ - 7
65
+ version: 1.6.7
67
66
  type: :runtime
68
67
  version_requirements: *id003
69
68
  - !ruby/object:Gem::Dependency
70
- name: rest-client
69
+ name: xml-simple
71
70
  prerelease: false
72
71
  requirement: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
- - - ~>
74
+ - - ">="
76
75
  - !ruby/object:Gem::Version
77
- hash: 1
76
+ hash: 17
78
77
  segments:
79
78
  - 1
80
- - 6
81
- - 7
82
- version: 1.6.7
79
+ - 1
80
+ - 1
81
+ version: 1.1.1
83
82
  type: :runtime
84
83
  version_requirements: *id004
85
84
  - !ruby/object:Gem::Dependency
86
- name: xml-simple
85
+ name: json
87
86
  prerelease: false
88
87
  requirement: &id005 !ruby/object:Gem::Requirement
89
88
  none: false
90
89
  requirements:
91
- - - ~>
90
+ - - "="
92
91
  - !ruby/object:Gem::Version
93
- hash: 17
92
+ hash: 7
94
93
  segments:
95
94
  - 1
96
- - 1
97
- - 1
98
- version: 1.1.1
95
+ - 7
96
+ - 6
97
+ version: 1.7.6
99
98
  type: :runtime
100
99
  version_requirements: *id005
101
100
  - !ruby/object:Gem::Dependency
102
- name: rspec
101
+ name: oauth
103
102
  prerelease: false
104
103
  requirement: &id006 !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 1
109
+ segments:
110
+ - 0
111
+ - 4
112
+ - 7
113
+ version: 0.4.7
114
+ type: :runtime
115
+ version_requirements: *id006
116
+ - !ruby/object:Gem::Dependency
117
+ name: rspec
118
+ prerelease: false
119
+ requirement: &id007 !ruby/object:Gem::Requirement
105
120
  none: false
106
121
  requirements:
107
122
  - - ">="
@@ -111,7 +126,7 @@ dependencies:
111
126
  - 0
112
127
  version: "0"
113
128
  type: :development
114
- version_requirements: *id006
129
+ version_requirements: *id007
115
130
  description: A Ruby interface to the AllPlayers API.
116
131
  email:
117
132
  - support@allplayers.com
@@ -123,26 +138,23 @@ extra_rdoc_files: []
123
138
 
124
139
  files:
125
140
  - README.md
126
- - Rakefile
127
141
  - allplayers.gemspec
128
- - lib/allplayers/api.rb
142
+ - lib/allplayers.rb
143
+ - lib/helpers/http_encoding_helper.rb
129
144
  - lib/allplayers/authentication.rb
130
- - lib/allplayers/client/events.rb
145
+ - lib/allplayers/error.rb
146
+ - lib/allplayers/error/restclient_error.rb
147
+ - lib/allplayers/error/decode_error.rb
131
148
  - lib/allplayers/client/groups.rb
149
+ - lib/allplayers/client/forms.rb
150
+ - lib/allplayers/client/events.rb
132
151
  - lib/allplayers/client/users.rb
133
- - lib/allplayers/client.rb
134
152
  - lib/allplayers/configuration.rb
135
- - lib/allplayers/monkey_patches/rest_client.rb
136
153
  - lib/allplayers/request.rb
137
- - lib/allplayers.rb
138
- - lib/helpers/http_encoding_helper.rb
139
- - spec/allplayers/api_spec.rb
140
- - spec/allplayers/client/events_spec.rb
141
- - spec/allplayers/client/groups_spec.rb
142
- - spec/allplayers/client/users_spec.rb
143
- - spec/allplayers/start_apci_session.rb
144
- - spec/allplayers_spec.rb
145
- - spec/helper.rb
154
+ - lib/allplayers/client.rb
155
+ - lib/allplayers/monkey_patches/rest_client.rb
156
+ - lib/allplayers/api.rb
157
+ - lib/allplayers/rate_limit.rb
146
158
  homepage: http://www.allplayers.com/
147
159
  licenses:
148
160
  - MIT
@@ -174,15 +186,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
186
  requirements: []
175
187
 
176
188
  rubyforge_project:
177
- rubygems_version: 1.8.24
189
+ rubygems_version: 1.8.25
178
190
  signing_key:
179
191
  specification_version: 3
180
192
  summary: A Ruby interface to the AllPlayers API.
181
- test_files:
182
- - spec/allplayers/api_spec.rb
183
- - spec/allplayers/client/events_spec.rb
184
- - spec/allplayers/client/groups_spec.rb
185
- - spec/allplayers/client/users_spec.rb
186
- - spec/allplayers/start_apci_session.rb
187
- - spec/allplayers_spec.rb
188
- - spec/helper.rb
193
+ test_files: []
194
+
data/Rakefile DELETED
@@ -1,53 +0,0 @@
1
- #
2
- # To change this template, choose Tools | Templates
3
- # and open the template in the editor.
4
-
5
-
6
- require 'rubygems'
7
- require 'rake'
8
- require 'rake/clean'
9
- require 'rake/gempackagetask'
10
- require 'rake/rdoctask'
11
- require 'rake/testtask'
12
- require 'ci/reporter/rake/test_unit'
13
- require 'rspec/core/rake_task'
14
- require 'ci/reporter/rake/rspec'
15
-
16
- spec = Gem::Specification.new do |s|
17
- s.name = 'allplayers-ruby-client'
18
- s.version = '0.0.1'
19
- s.has_rdoc = true
20
- s.extra_rdoc_files = ['README', 'LICENSE']
21
- s.summary = 'Your summary here'
22
- s.description = s.summary
23
- s.author = ''
24
- s.email = ''
25
- # s.executables = ['your_executable_here']
26
- s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
27
- s.require_path = "lib"
28
- s.bindir = "bin"
29
- end
30
-
31
- Rake::GemPackageTask.new(spec) do |p|
32
- p.gem_spec = spec
33
- p.need_tar = true
34
- p.need_zip = true
35
- end
36
-
37
- Rake::RDocTask.new do |rdoc|
38
- files =['README', 'LICENSE', 'lib/**/*.rb']
39
- rdoc.rdoc_files.add(files)
40
- rdoc.main = "README" # page to start on
41
- rdoc.title = "allplayers-ruby-client Docs"
42
- rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
43
- rdoc.options << '--line-numbers'
44
- end
45
-
46
- Rake::TestTask.new do |t|
47
- t.test_files = FileList['test/**/*.rb']
48
- end
49
-
50
- RSpec::Core::RakeTask.new(:spec => ["ci:setup:rspec"]) do |t|
51
- t.pattern = 'spec/*_spec.rb'
52
- end
53
-
@@ -1,79 +0,0 @@
1
- require 'helper'
2
-
3
- describe AllPlayers::API do
4
- before do
5
- def get_args
6
- # If any environment variable set, skip argument handling.
7
- if ENV.has_key?('APCI_REST_TEST_HOST')
8
- $apci_rest_test_host = ENV['APCI_REST_TEST_HOST']
9
- $apci_rest_test_user = ENV['APCI_REST_TEST_USER']
10
- $apci_rest_test_pass = ENV['APCI_REST_TEST_PASS']
11
- return
12
- end
13
-
14
- $apci_rest_test_user = Etc.getlogin if $apci_rest_test_user.nil?
15
- $apci_rest_test_pass = nil if $apci_rest_test_pass.nil?
16
-
17
- opts = GetoptLong.new(
18
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
19
- [ '-p', GetoptLong::REQUIRED_ARGUMENT]
20
- )
21
-
22
- opts.each do |opt, arg|
23
- case opt
24
- when '--help'
25
- RDoc::usage
26
- when '-p'
27
- $apci_rest_test_pass = arg
28
- end
29
- end
30
-
31
- RDoc::usage if $apci_rest_test_pass.nil?
32
-
33
- # Handle default argument => host to target for import and optional user,
34
- # (i.e. user@sandbox.allplayers.com).
35
- if ARGV.length != 1
36
- puts "No host argument, connecting to default host (try --help)"
37
- $apci_rest_test_host = nil
38
- else
39
- host_user = ARGV.shift.split('@')
40
- $apci_rest_test_user = host_user.shift if host_user.length > 1
41
- $apci_rest_test_host = host_user[0]
42
- puts 'Connecting to ' + $apci_rest_test_host
43
- end
44
- end
45
- if $login_response.nil?
46
- if $apci_rest_test_user.nil? || $apci_rest_test_pass.nil?
47
- get_args
48
- end
49
-
50
- if $apci_session.nil?
51
- $apci_session = AllPlayers::Client.new(nil, $apci_rest_test_host)
52
- end
53
-
54
- # End arguments
55
-
56
- # TODO - Log only with argument (-l)?
57
- # Make a folder for some logs!
58
- path = Dir.pwd + '/test_logs'
59
- begin
60
- FileUtils.mkdir(path)
61
- rescue
62
- # Do nothing, it's already there? Perhaps catch a more specific error?
63
- ensure
64
- logger = Logger.new(path + '/test.log', 'daily')
65
- logger.level = Logger::DEBUG
66
- logger.info('initialize') { "Initializing..." }
67
- $apci_session.log(logger)
68
- end
69
-
70
- # Account shouldn't be hard coded!
71
- $login_response = $apci_session.login($apci_rest_test_user, $apci_rest_test_pass)
72
- end
73
- $apci_session = $apci_session
74
- end
75
- it "should return a valid session." do
76
- $apci_session.should_not == nil
77
- end
78
-
79
- end
@@ -1,53 +0,0 @@
1
- require 'helper'
2
-
3
- describe AllPlayers::Client do
4
- describe "Event" do
5
- before :all do
6
- # Create Group.
7
- $group_title = (0...8).map{65.+(rand(25)).chr}.join
8
- more_params = {}
9
- $location = {
10
- :street => '122 Main ',
11
- :city => 'Lewisville',
12
- :state => 'TX',
13
- :zip => '75067',
14
- }
15
- $group = $apci_session.group_create(
16
- $group_title,
17
- 'This is a test group generated by event_spec.rb',
18
- $location,
19
- ['Sports', 'Baseball'],
20
- more_params
21
- )
22
-
23
- # Create Event.
24
- $event_title = (0...8).map{65.+(rand(25)).chr}.join
25
- more_params = {}
26
- $event = $apci_session.event_create(
27
- $event_title,
28
- 'This is a test event generated by event_spec.rb',
29
- $group['uuid'],
30
- '2012-09-15T08:05:00', # Generic Date
31
- '2012-09-15T09:05:00',
32
- more_params = {}
33
- )
34
- end
35
-
36
- it "should be created properly." do
37
- $event['title'].should == $event_title
38
- $event['groups']['item'].should include($group['uuid'])
39
- end
40
-
41
- it "should be able to update" do
42
- updated_description = 'This is a test event updated by event_spec.rb'
43
- update_params = {
44
- :description => updated_description
45
- }
46
- event = $apci_session.event_update(
47
- $event['uuid'],
48
- update_params
49
- )
50
- event['description'].should == updated_description
51
- end
52
- end
53
- end
@@ -1,80 +0,0 @@
1
- require 'helper'
2
-
3
- describe AllPlayers::Client do
4
- describe "Group" do
5
- before :all do
6
- # Create Group.
7
- $random_title = (0...8).map{65.+(rand(25)).chr}.join
8
- more_params = {}
9
- $location = {
10
- :street => '122 Main ',
11
- :additional => 'Suite 303',
12
- :city => 'Lewisville',
13
- :province => 'TX', # <-- Test Breaker!
14
- :zip => '75067',
15
- :country => 'us',
16
- }
17
- $group = $apci_session.group_create(
18
- $random_title,
19
- 'This is a test group generated by group_spec.rb',
20
- $location,
21
- ['Sports', 'Baseball'],
22
- more_params
23
- )
24
-
25
- # Create User.
26
- $birthday = Date.new(1983,5,23)
27
- $random_first = (0...8).map{65.+(rand(25)).chr}.join
28
- $user = $apci_session.user_create(
29
- $random_first + '@example.com',
30
- $random_first,
31
- 'FakeLast',
32
- $birthday,
33
- 'Male'
34
- )
35
- # User Join Group.
36
- $apci_session.user_join_group($group['uuid'], $user['uuid'], 'Player')
37
- $users = $apci_session.group_members_list($group['uuid'])
38
- $users_uuids = []
39
- $users['item'].each do | user |
40
- $users_uuids.push(user['uuid'])
41
- end
42
-
43
- # User's Groups
44
- $groups = $apci_session.user_groups_list($user['uuid'])
45
-
46
- # Group Roles
47
- $roles = $apci_session.group_roles_list($group['uuid'])
48
- $roles.each do | uuid, role |
49
- $role = uuid.dup if role['name'] == 'Fan'
50
- end
51
- $role[0] = ''
52
- end
53
-
54
- it "should be created properly." do
55
- $group['uuid'].should_not == nil
56
- group = $apci_session.group_get($group['uuid'])
57
- group['title'].should == $random_title
58
- end
59
-
60
- it "should list users." do
61
- $users['item'].first['uri'].should include($group['uuid'].to_s)
62
- $users['item'].first['uuid'].should_not == nil
63
- end
64
-
65
- describe "User" do
66
- it "should be able to join group." do
67
- $users_uuids.include?($user['uuid'].to_s).should == true
68
- end
69
-
70
- it "should list groups." do
71
- $groups['item'].first['uuid'].should == $group['uuid']
72
- end
73
-
74
- it "should be able to have a role assigned in a group." do
75
- response = $apci_session.user_group_add_role($group['uuid'], $user['uuid'], $role)
76
- ['1'].include?(response).should == TRUE
77
- end
78
- end
79
- end
80
- end
@@ -1,101 +0,0 @@
1
- require 'helper'
2
-
3
- describe AllPlayers::Client do
4
- describe "User" do
5
- before :all do
6
- # Create User.
7
- $birthday = Date.new(1983,5,23)
8
- $random_first = (0...8).map{65.+(rand(25)).chr}.join
9
- $user = $apci_session.user_create(
10
- $random_first + '@example.com',
11
- $random_first,
12
- 'FakeLast',
13
- $birthday,
14
- 'Male'
15
- )
16
- end
17
-
18
- it "should be created properly." do
19
- # Check user get response.
20
- user = $apci_session.user_get($user['uuid'])
21
- # Check mail.
22
- user['email'].should == $random_first + '@example.com'
23
- # Check username.
24
- user['username'].should == $random_first + ' FakeLast'
25
- end
26
-
27
- describe "Child" do
28
- it "should be created properly." do
29
- random_first = (0...8).map{65.+(rand(25)).chr}.join
30
- more_params = {
31
- :email => random_first + '@example.com',
32
- }
33
- birthday = Date.new(2004,5,23)
34
- $child = $apci_session.user_create_child(
35
- $user['uuid'],
36
- random_first,
37
- 'FakeLast',
38
- birthday,
39
- 'm',
40
- more_params
41
- )
42
- $child['uuid'].should_not == nil
43
-
44
- # Get children from parent.
45
- children = $apci_session.user_children_list($user['uuid'])
46
- child_uuid = children['item'].first['uuid']
47
-
48
- # Verify parent child relationship.
49
- child_uuid.should == $child['uuid']
50
-
51
- # Check email.
52
- $child['email'].should == random_first + '@example.com'
53
-
54
- # Check calculated username is only first.
55
- $child['nickname'].should == random_first
56
-
57
- # Check name.
58
- $child['firstname'].should == random_first
59
- $child['lastname'].should == 'FakeLast'
60
-
61
- # Check gender.
62
- $child['gender'].should == 'male'
63
- end
64
-
65
- it "should be created properly using an AllPlayers.net email." do
66
- random_first = (0...8).map{65.+(rand(25)).chr}.join
67
- birthday = '2004-05-21'
68
- more_params = {}
69
- $child = $apci_session.user_create_child(
70
- $user['uuid'],
71
- random_first,
72
- 'FakeLast',
73
- birthday,
74
- 'm',
75
- more_params
76
- )
77
- $child['uuid'].should_not == nil
78
-
79
- # Get children from parent.
80
- children = $apci_session.user_children_list($user['uuid'])
81
- child_uuid = children['item'].last['uuid']
82
-
83
- # Verify parent child relationship.
84
- child_uuid.should == $child['uuid']
85
-
86
- # Check email.
87
- $child['email'].should == random_first + 'FakeLast@allplayers.net'
88
-
89
- # Check calculated username is only first.
90
- $child['nickname'].should == random_first
91
-
92
- # Check name.
93
- $child['firstname'].should == random_first
94
- $child['lastname'].should == 'FakeLast'
95
-
96
- # Check gender.
97
- $child['gender'].should == 'male'
98
- end
99
- end
100
- end
101
- end
@@ -1,75 +0,0 @@
1
- RSpec.configure do |c|
2
- c.treat_symbols_as_metadata_keys_with_true_values = true
3
- c.before(:all) {
4
- def get_args
5
- # If any environment variable set, skip argument handling.
6
- if ENV.has_key?('APCI_REST_TEST_HOST')
7
- $apci_rest_test_host = ENV['APCI_REST_TEST_HOST']
8
- $apci_rest_test_user = ENV['APCI_REST_TEST_USER']
9
- $apci_rest_test_pass = ENV['APCI_REST_TEST_PASS']
10
- $ssl_check = ENV['SSL_CHECK']
11
- return
12
- end
13
-
14
- $apci_rest_test_user = Etc.getlogin if $apci_rest_test_user.nil?
15
- $apci_rest_test_pass = nil if $apci_rest_test_pass.nil?
16
-
17
- opts = GetoptLong.new(
18
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
19
- [ '-p', GetoptLong::REQUIRED_ARGUMENT]
20
- )
21
-
22
- opts.each do |opt, arg|
23
- case opt
24
- when '--help'
25
- RDoc::usage
26
- when '-p'
27
- $apci_rest_test_pass = arg
28
- end
29
- end
30
-
31
- RDoc::usage if $apci_rest_test_pass.nil?
32
-
33
- # Handle default argument => host to target for import and optional user,
34
- # (i.e. user@sandbox.allplayers.com).
35
- if ARGV.length != 1
36
- puts "No host argument, connecting to default host (try --help)"
37
- $apci_rest_test_host = nil
38
- else
39
- host_user = ARGV.shift.split('@')
40
- $apci_rest_test_user = host_user.shift if host_user.length > 1
41
- $apci_rest_test_host = host_user[0]
42
- puts 'Connecting to ' + $apci_rest_test_host
43
- end
44
- end
45
- if $login_response.nil?
46
- if $apci_rest_test_user.nil? || $apci_rest_test_pass.nil?
47
- get_args
48
- end
49
-
50
- if $apci_session.nil?
51
- $apci_session = AllPlayers::Client.new(nil, $apci_rest_test_host)
52
- end
53
-
54
- # End arguments
55
-
56
- # TODO - Log only with argument (-l)?
57
- # Make a folder for some logs!
58
- path = Dir.pwd + '/test_logs'
59
- begin
60
- FileUtils.mkdir(path)
61
- rescue
62
- # Do nothing, it's already there? Perhaps catch a more specific error?
63
- ensure
64
- logger = Logger.new(path + '/test.log', 'daily')
65
- logger.level = Logger::DEBUG
66
- logger.info('initialize') { "Initializing..." }
67
- $apci_session.log(logger)
68
- end
69
-
70
- # Account shouldn't be hard coded!
71
- $login_response = $apci_session.login($apci_rest_test_user, $apci_rest_test_pass)
72
- end
73
- $apci_session = $apci_session
74
- }
75
- end
@@ -1,14 +0,0 @@
1
- require 'helper'
2
- require 'allplayers/start_apci_session'
3
- require 'allplayers/api_spec'
4
- require 'allplayers/client/users_spec'
5
- require 'allplayers/client/groups_spec'
6
- require 'allplayers/client/events_spec'
7
-
8
- describe AllPlayers do
9
- describe "New" do
10
- it "should return an Allplayers::Client." do
11
- AllPlayers.new.should be_a AllPlayers::Client
12
- end
13
- end
14
- end
data/spec/helper.rb DELETED
@@ -1,13 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__),'..','lib')
2
-
3
- require 'open-uri'
4
- require 'allplayers/client'
5
- require 'allplayers'
6
- require 'apci_field_mapping'
7
- require 'getoptlong'
8
- require 'rdoc/usage'
9
- require 'logger'
10
- require 'etc'
11
- require 'date'
12
- require 'rspec'
13
- require 'net/https'