allplayers 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ allplayers.rb
2
+ =============
3
+
4
+ AllPlayers.com ruby client https://www.allplayers.com
5
+
6
+ AllPlayer.com, Inc. Ruby client for importing users, groups, events, etc via
7
+ REST API.
8
+
9
+ Requires Ruby + Rubygems and the following:
10
+
11
+ sudo apt-get install ruby libopenssl-ruby
12
+
13
+ # nokogiri requirements
14
+ sudo apt-get install libxslt-dev libxml2-dev
15
+
16
+ # install bundler
17
+ sudo gem install bundler
18
+
19
+ # run bundler
20
+ bundle install
21
+
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/Rakefile ADDED
@@ -0,0 +1,53 @@
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
+
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
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']
8
+ spec.add_development_dependency 'rspec'
9
+ spec.authors = ["AllPlayers.com"]
10
+ spec.description = %q{A Ruby interface to the AllPlayers API.}
11
+ spec.email = ['support@allplayers.com']
12
+ spec.files = %w(README.md Rakefile allplayers.gemspec)
13
+ spec.files += Dir.glob("lib/**/*.rb")
14
+ spec.files += Dir.glob("spec/**/*")
15
+ spec.homepage = 'http://www.allplayers.com/'
16
+ spec.licenses = ['MIT']
17
+ spec.name = 'allplayers'
18
+ spec.require_paths = ['lib']
19
+ spec.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
20
+ spec.summary = spec.description
21
+ spec.test_files = Dir.glob("spec/**/*")
22
+ spec.version = '0.1.0'
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'addressable/uri'
2
+ require 'xmlsimple'
3
+ require 'logger'
4
+ require 'active_support/base64'
5
+ require 'restclient'
6
+ require 'allplayers/authentication'
7
+ require 'allplayers/request'
8
+
9
+ module AllPlayers
10
+ class API
11
+ include Request
12
+ include Authentication
13
+ attr_accessor :logger
14
+
15
+ def initialize(api_key = nil, server = 'sandbox.allplayers.com', protocol = 'https://', auth = 'session')
16
+ if (auth == 'session')
17
+ extend AllPlayers::Authentication
18
+ end
19
+ @base_uri = Addressable::URI.join(protocol + server, '')
20
+ @key = api_key # TODO - Not implemented in API yet.
21
+ @session_cookies = {}
22
+ @headers = {}
23
+ end
24
+
25
+ def log(target)
26
+ @log = target
27
+ RestClient.log = target
28
+ end
29
+
30
+ # Add header method, preferably use array of symbols, e.g. {:USER-AGENT => 'RubyClient'}.
31
+ def add_headers(header = {})
32
+ @headers.merge!(header) unless header.nil?
33
+ end
34
+
35
+ # Remove headers from a session.
36
+ def remove_headers(headers = {})
37
+ headers.each do |header, value|
38
+ @headers.delete(header)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ module AllPlayers
2
+ module Authentication
3
+ def login(name, pass)
4
+ begin
5
+ post 'users/login' , {:username => name, :password => pass}
6
+ end
7
+ end
8
+
9
+ def logout()
10
+ begin
11
+ post 'users/logout'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module AllPlayers
2
+ module Events
3
+ def event_create(title, description, groups, date_start, date_end, more_params = {})
4
+ required_params = {
5
+ :groups => groups,
6
+ :title => title,
7
+ :description => description,
8
+ :date_time => {
9
+ :start => date_start,
10
+ :end => date_end,
11
+ }
12
+ }
13
+ response = post 'events', required_params.merge(more_params)
14
+ end
15
+ def event_update(uuid, update_params)
16
+ put 'events/'+uuid, update_params
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ module AllPlayers
2
+ module Groups
3
+ def group_create(title, description, location, categories, more_params = {})
4
+ required_params = {
5
+ :title => title,
6
+ :description => description,
7
+ :location => location,
8
+ :category => categories
9
+ }
10
+ post 'groups', required_params.merge(more_params)
11
+ end
12
+
13
+ def group_set_manager(group_uuid, user_uuid, remove_previous = false)
14
+ post 'groups/' + group_uuid.to_s + '/setmanager/' + user_uuid.to_s, {:remove_previous => remove_previous}
15
+ end
16
+
17
+ def group_clone(target_uuid, origin_uuid, groups_above_setting = nil)
18
+ post 'groups/' + target_uuid + '/copy/' + origin_uuid, {:groups_above => groups_above_setting}
19
+ end
20
+
21
+ def group_get(group_uuid)
22
+ get 'groups/' + group_uuid
23
+ end
24
+
25
+ def group_search(params = {})
26
+ get 'groups', params
27
+ end
28
+
29
+ def group_delete(group_uuid)
30
+ delete 'groups/' + group_uuid.to_s
31
+ end
32
+
33
+ def group_update(group_uuid, params = {})
34
+ put 'groups/' + group_uuid, params
35
+ end
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
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ module AllPlayers
2
+ module Users
3
+ def user_create(email, firstname, lastname, birthday, gender, more_params = {})
4
+ required_params = {
5
+ :email => email,
6
+ :firstname => firstname,
7
+ :lastname => lastname,
8
+ :birthday => birthday,
9
+ :gender => gender,
10
+ }
11
+ post 'users', required_params.merge(more_params)
12
+ end
13
+
14
+ def user_get_email(email = nil)
15
+ get 'users', {:email => email} if !email.nil?
16
+ end
17
+
18
+ def user_get(uuid = nil)
19
+ get 'users/' + uuid.to_s() if !uuid.nil?
20
+ end
21
+
22
+ def user_children_list(uuid)
23
+ get 'users/' + uuid.to_s() + '/children'
24
+ end
25
+
26
+ def user_create_child(parent_uuid, firstname, lastname, birthday, gender, more_params = {})
27
+ required_params = {
28
+ :firstname => firstname,
29
+ :lastname => lastname,
30
+ :birthday => birthday,
31
+ :gender => gender,
32
+ }
33
+ post 'users/' + parent_uuid.to_s() + '/addchild', required_params.merge(more_params)
34
+ end
35
+
36
+ def user_groups_list(user_uuid, params = {})
37
+ get 'users/' + user_uuid + '/groups', params
38
+ end
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}
42
+ end
43
+
44
+ def user_group_add_role(group_uuid, user_uuid, role_uuid, params = {})
45
+ post 'groups/' + group_uuid + '/addrole/' + user_uuid + '/' + role_uuid, params
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ require 'allplayers/api'
2
+
3
+ module AllPlayers
4
+ class Client < API
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+ require 'restclient'
8
+ require 'addressable/uri'
9
+ require 'allplayers/client/events'
10
+ require 'allplayers/client/users'
11
+ require 'allplayers/client/groups'
12
+ include AllPlayers::Events
13
+ include AllPlayers::Users
14
+ include AllPlayers::Groups
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ module AllPlayers
2
+ module Configuration
3
+ # Convenience method to allow configuration options to be set in a block
4
+ def configure
5
+ yield self
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+
4
+ # monkey patch RestClient to support custom timeouts.
5
+ module RestClient
6
+
7
+ def self.get(url, headers={}, &block)
8
+ Request.execute(:method => :get, :url => url, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
9
+ end
10
+
11
+ def self.post(url, payload, headers={}, &block)
12
+ Request.execute(:method => :post, :url => url, :payload => payload, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
13
+ end
14
+
15
+ def self.put(url, payload, headers={}, &block)
16
+ Request.execute(:method => :put, :url => url, :payload => payload, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
17
+ end
18
+
19
+ def self.delete(url, headers={}, &block)
20
+ Request.execute(:method => :delete, :url => url, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
21
+ end
22
+
23
+ def self.head(url, headers={}, &block)
24
+ Request.execute(:method => :head, :url => url, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
25
+ end
26
+
27
+ def self.options(url, headers={}, &block)
28
+ Request.execute(:method => :options, :url => url, :headers => headers, :timeout => @timeout, :open_timeout => @open_timeout, &block)
29
+ end
30
+
31
+ class << self
32
+ attr_accessor :timeout
33
+ attr_accessor :open_timeout
34
+ end
35
+ end
36
+
37
+ # monkey patch some pretty error messages into RestClient library exceptions.
38
+ RestClient::STATUSES.each_pair do |code, message|
39
+ RestClient::Exceptions::EXCEPTIONS_MAP[code].send(:define_method, :message) {
40
+ response_error = ''
41
+ if !self.response.nil?
42
+ response_error = ' : ' + CGI::unescapeHTML(self.response.gsub(/<\/?[^>]*>/, " ").strip.gsub(/\r\n?/, ', ').squeeze(' '))
43
+ end
44
+ "#{http_code ? "#{http_code} " : ''}#{message}#{response_error}"
45
+ }
46
+ end
@@ -0,0 +1,54 @@
1
+ module AllPlayers
2
+ module Request
3
+ # GET, PUT, POST, DELETE, etc.
4
+ def get(path, query = {}, headers = {})
5
+ # @TODO - cache here (HTTP Headers?)
6
+ request(:get, path, query, {}, headers)
7
+ end
8
+
9
+ def post(path, payload = {}, headers = {})
10
+ request(:post, path, {}, payload, headers)
11
+ end
12
+
13
+ def put(path, payload = {}, headers = {})
14
+ request(:put, path, {}, payload, headers)
15
+ end
16
+
17
+ def delete(path, headers = {})
18
+ request(:delete, path, {}, {}, headers)
19
+ end
20
+
21
+ private
22
+
23
+ # Perform an HTTP request
24
+ def request(verb, path, query = {}, payload = {}, headers = {})
25
+ begin
26
+ uri = Addressable::URI.join(@base_uri, 'api/v1/rest/'+path.to_s)
27
+ uri.query_values = query unless query.empty?
28
+ headers.merge!(@headers) unless @headers.empty?
29
+ RestClient.log = @log
30
+ RestClient.open_timeout = 600
31
+ RestClient.timeout = 600
32
+ if [:patch, :post, :put].include? verb
33
+ response = RestClient.send(verb, uri.to_s, payload, headers)
34
+ else
35
+ response = RestClient.send(verb, uri.to_s, headers)
36
+ 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."
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/allplayers.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Require minimal files needed for AllPlayers public API here.
2
+ require 'allplayers/monkey_patches/rest_client'
3
+ require 'allplayers/api'
4
+ require 'allplayers/client'
5
+ require 'allplayers/configuration'
6
+
7
+ module AllPlayers
8
+ extend Configuration
9
+ class << self
10
+ def new(options={})
11
+ AllPlayers::Client.new(options)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ # Intended to extend the Net::HTTP response object
2
+ # and adds support for decoding gzip and deflate encoded pages
3
+ #
4
+ # Author: Jason Stirk <http://griffin.oobleyboo.com>
5
+ # Home: http://griffin.oobleyboo.com/projects/http_encoding_helper
6
+ # Created: 5 September 2007
7
+ # Last Updated: 23 November 2007
8
+ #
9
+ # Usage:
10
+ #
11
+ # require 'net/http'
12
+ # require 'http_encoding_helper'
13
+ # headers={'Accept-Encoding' => 'gzip, deflate' }
14
+ # http = Net::HTTP.new('griffin.oobleyboo.com', 80)
15
+ # http.start do |h|
16
+ # request = Net::HTTP::Get.new('/', headers)
17
+ # response = http.request(request)
18
+ # content=response.plain_body # Method from our library
19
+ # puts "Transferred: #{response.body.length} bytes"
20
+ # puts "Compression: #{response['content-encoding']}"
21
+ # puts "Extracted: #{response.plain_body.length} bytes"
22
+ # end
23
+ #
24
+
25
+ require 'zlib'
26
+ require 'stringio'
27
+
28
+ class Net::HTTPResponse
29
+ # Return the uncompressed content
30
+ def plain_body
31
+ encoding=self['content-encoding']
32
+ content=nil
33
+ if encoding then
34
+ case encoding
35
+ when 'gzip'
36
+ i=Zlib::GzipReader.new(StringIO.new(self.body))
37
+ content=i.read
38
+ when 'deflate'
39
+ i=Zlib::Inflate.new
40
+ content=i.inflate(self.body)
41
+ else
42
+ raise "Unknown encoding - #{encoding}"
43
+ end
44
+ else
45
+ content=self.body
46
+ end
47
+ return content
48
+ end
49
+ end
@@ -0,0 +1,79 @@
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
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,80 @@
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
@@ -0,0 +1,101 @@
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
@@ -0,0 +1,75 @@
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
@@ -0,0 +1,14 @@
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 ADDED
@@ -0,0 +1,13 @@
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'
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allplayers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - AllPlayers.com
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 10
33
+ version: 2.3.10
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: addressable
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 9
45
+ segments:
46
+ - 2
47
+ - 2
48
+ - 7
49
+ version: 2.2.7
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rake
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 11
61
+ segments:
62
+ - 0
63
+ - 9
64
+ - 2
65
+ - 2
66
+ version: 0.9.2.2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 1
78
+ segments:
79
+ - 1
80
+ - 6
81
+ - 7
82
+ version: 1.6.7
83
+ type: :runtime
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: xml-simple
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 17
94
+ segments:
95
+ - 1
96
+ - 1
97
+ - 1
98
+ version: 1.1.1
99
+ type: :runtime
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ type: :development
114
+ version_requirements: *id006
115
+ description: A Ruby interface to the AllPlayers API.
116
+ email:
117
+ - support@allplayers.com
118
+ executables: []
119
+
120
+ extensions: []
121
+
122
+ extra_rdoc_files: []
123
+
124
+ files:
125
+ - README.md
126
+ - Rakefile
127
+ - allplayers.gemspec
128
+ - lib/allplayers/api.rb
129
+ - lib/allplayers/authentication.rb
130
+ - lib/allplayers/client/events.rb
131
+ - lib/allplayers/client/groups.rb
132
+ - lib/allplayers/client/users.rb
133
+ - lib/allplayers/client.rb
134
+ - lib/allplayers/configuration.rb
135
+ - lib/allplayers/monkey_patches/rest_client.rb
136
+ - 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
146
+ homepage: http://www.allplayers.com/
147
+ licenses:
148
+ - MIT
149
+ post_install_message:
150
+ rdoc_options: []
151
+
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ none: false
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ hash: 23
169
+ segments:
170
+ - 1
171
+ - 3
172
+ - 6
173
+ version: 1.3.6
174
+ requirements: []
175
+
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.24
178
+ signing_key:
179
+ specification_version: 3
180
+ 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