rbglitch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rbglitch.rb +27 -0
- data/lib/rbglitch/achievements_api.rb +20 -0
- data/lib/rbglitch/auctions_api.rb +35 -0
- data/lib/rbglitch/auth_api.rb +19 -0
- data/lib/rbglitch/avatar_api.rb +18 -0
- data/lib/rbglitch/base_api.rb +37 -0
- data/lib/rbglitch/calendar_api.rb +20 -0
- data/lib/rbglitch/locations_api.rb +30 -0
- data/lib/rbglitch/players_api.rb +62 -0
- data/lib/rbglitch/skills_api.rb +57 -0
- metadata +69 -0
data/lib/rbglitch.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rbglitch/achievements_api'
|
2
|
+
require 'rbglitch/auctions_api'
|
3
|
+
require 'rbglitch/auth_api'
|
4
|
+
require 'rbglitch/avatar_api'
|
5
|
+
require 'rbglitch/calendar_api'
|
6
|
+
require 'rbglitch/locations_api'
|
7
|
+
require 'rbglitch/players_api'
|
8
|
+
require 'rbglitch/skills_api'
|
9
|
+
|
10
|
+
|
11
|
+
# The glue holding everything together.
|
12
|
+
class GlitchAPI
|
13
|
+
|
14
|
+
attr_reader :achievements, :auctions, :auth, :avatar, :calendar, :locations
|
15
|
+
attr_reader :players, :skills
|
16
|
+
|
17
|
+
def initialize(player_token = '')
|
18
|
+
@achievements = RBGlitch::AchievementsAPI.new(player_token)
|
19
|
+
@auctions = RBGlitch::AuctionsAPI.new(player_token)
|
20
|
+
@auth = RBGlitch::AuthAPI.new(player_token)
|
21
|
+
@avatar = RBGlitch::AvatarAPI.new(player_token)
|
22
|
+
@calendar = RBGlitch::CalendarAPI.new(player_token)
|
23
|
+
@locations = RBGlitch::LocationsAPI.new(player_token)
|
24
|
+
@players = RBGlitch::PlayersAPI.new(player_token)
|
25
|
+
@skills = RBGlitch::SkillsAPI.new(player_token)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class AchievementsAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/achievements.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_all(page=1, per_page=10)
|
10
|
+
params = {
|
11
|
+
'page' => page,
|
12
|
+
'per_page' => per_page
|
13
|
+
}
|
14
|
+
|
15
|
+
send('listAll', params)
|
16
|
+
end
|
17
|
+
|
18
|
+
private :get_path
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class AuctionsAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/auctions.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(category='', defs=0, page=1, per_page=10)
|
10
|
+
params = {
|
11
|
+
'defs' => defs,
|
12
|
+
'page' => page,
|
13
|
+
'per_page' => per_page
|
14
|
+
}
|
15
|
+
|
16
|
+
unless category == ''
|
17
|
+
params['category'] = category
|
18
|
+
end
|
19
|
+
|
20
|
+
send('list', params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def create(stack_tsid, count, cost)
|
24
|
+
params = {
|
25
|
+
'stack_tsid' => stack_tsid,
|
26
|
+
'count' => count,
|
27
|
+
'cost' => cost,
|
28
|
+
'oauth_token' => @player_token
|
29
|
+
}
|
30
|
+
send('create', params)
|
31
|
+
end
|
32
|
+
|
33
|
+
private :get_path
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class AuthAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/auth.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def check(page=1, per_page=10)
|
10
|
+
params = {
|
11
|
+
'oauth_token' => @player_token
|
12
|
+
}
|
13
|
+
|
14
|
+
send('check', params)
|
15
|
+
end
|
16
|
+
|
17
|
+
private :get_path
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class AvatarAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/avatar.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_details
|
10
|
+
params = {
|
11
|
+
'oauth_token' => @player_token
|
12
|
+
}
|
13
|
+
send('getDetails', params)
|
14
|
+
end
|
15
|
+
|
16
|
+
private :get_path
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module RBGlitch
|
5
|
+
# The base class from which all the other API things extend.
|
6
|
+
class BaseAPI
|
7
|
+
def initialize(player_token = '')
|
8
|
+
@api_base = 'api.glitch.com'
|
9
|
+
@player_token = player_token
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_path
|
13
|
+
end
|
14
|
+
|
15
|
+
# Build out a proper get request, with the parameters and everything.
|
16
|
+
def build_request(subpath, params)
|
17
|
+
subpath = "/simple" + get_path(subpath)
|
18
|
+
r = Net::HTTP::Get.new(subpath)
|
19
|
+
r.set_form_data(params)
|
20
|
+
# Fancy dancing cause Net::HTTP doesn't support native GET params. FFF.
|
21
|
+
r = Net::HTTP::Get.new(subpath + '?' + r.body)
|
22
|
+
return r
|
23
|
+
end
|
24
|
+
|
25
|
+
# Where most of the heavy lifting happens. Build the request based on the
|
26
|
+
# api call, then send it.
|
27
|
+
def send(subpath, params)
|
28
|
+
http = Net::HTTP.new(@api_base)
|
29
|
+
request = build_request(subpath, params)
|
30
|
+
|
31
|
+
response = http.request(request)
|
32
|
+
return JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
private :build_request, :get_path, :send
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class CalendarAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/calendar.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_holidays(page=1, per_page=10)
|
10
|
+
params = {
|
11
|
+
'page' => page,
|
12
|
+
'per_page' => per_page
|
13
|
+
}
|
14
|
+
|
15
|
+
send('getHolidays', params)
|
16
|
+
end
|
17
|
+
|
18
|
+
private :get_path
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class LocationsAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/locations.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_hubs
|
10
|
+
params = {}
|
11
|
+
send('getHubs', params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_streets(hub_id)
|
15
|
+
params = {
|
16
|
+
'hub_id' => hub_id
|
17
|
+
}
|
18
|
+
send('getStreets', params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def street_info(street_tsid)
|
22
|
+
params = {
|
23
|
+
'street_tsid' => street_tsid
|
24
|
+
}
|
25
|
+
send('streetInfo', params)
|
26
|
+
end
|
27
|
+
|
28
|
+
private :get_path
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class PlayersAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/players.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def full_info(player_tsid, viewer_tsid='')
|
10
|
+
params = {
|
11
|
+
'player_tsid' => player_tsid
|
12
|
+
}
|
13
|
+
unless viewer_tsid == ''
|
14
|
+
params['viewer_tsid'] = viewer_tsid
|
15
|
+
end
|
16
|
+
send('fullInfo', params)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_animations(player_tsid)
|
20
|
+
params = {
|
21
|
+
'player_tsid' => player_tsid
|
22
|
+
}
|
23
|
+
send('getAnimations', params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_clothing(player_tsid)
|
27
|
+
params = {
|
28
|
+
'player_tsid' => player_tsid
|
29
|
+
}
|
30
|
+
send('getClothing', params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def info
|
34
|
+
params = {
|
35
|
+
'oauth_token' => @player_token
|
36
|
+
}
|
37
|
+
send('info', params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def inventory(defs = 0)
|
41
|
+
params = {
|
42
|
+
'oauth_token' => @player_token
|
43
|
+
}
|
44
|
+
if defs == 1
|
45
|
+
params['defs'] = 1
|
46
|
+
end
|
47
|
+
|
48
|
+
send('inventory', params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def stats
|
52
|
+
params = {
|
53
|
+
'oauth_token' => @player_token
|
54
|
+
}
|
55
|
+
send('stats', params)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
private :get_path
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rbglitch/base_api'
|
2
|
+
|
3
|
+
module RBGlitch
|
4
|
+
class SkillsAPI < BaseAPI
|
5
|
+
def get_path(subpath)
|
6
|
+
return "/skills.#{subpath}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_info(skill_id, skill_class)
|
10
|
+
params = {
|
11
|
+
'skill_id' => skill_id,
|
12
|
+
'skill_class' => skill_class
|
13
|
+
}
|
14
|
+
send('getInfo', params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def learn(skill_id, skill_class)
|
18
|
+
params = {
|
19
|
+
'oauth_token' => @player_token,
|
20
|
+
'skill_id' => skill_id,
|
21
|
+
'skill_class' => skill_class
|
22
|
+
}
|
23
|
+
send('learn', params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def list_all(page=1, per_page=10)
|
27
|
+
params = {
|
28
|
+
'page' => page,
|
29
|
+
'per_page' => per_page
|
30
|
+
}
|
31
|
+
send('listAll', params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def list_available
|
35
|
+
params = {
|
36
|
+
'oauth_token' => @player_token
|
37
|
+
}
|
38
|
+
send('listAvailable', params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def list_learned
|
42
|
+
params = {
|
43
|
+
'oauth_token' => @player_token
|
44
|
+
}
|
45
|
+
send('listLearned', params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def list_learning
|
49
|
+
params = {
|
50
|
+
'oauth_token' => @player_token
|
51
|
+
}
|
52
|
+
send('listLearning', params)
|
53
|
+
end
|
54
|
+
|
55
|
+
private :get_path
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbglitch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Kuang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70274369404460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70274369404460
|
25
|
+
description: ! " A thin ruby wrapper around the Glitch game API. This code is more
|
26
|
+
likely to be\n updated by me than pyglitch, since I'm more likely to be playing
|
27
|
+
around with it\n and maybe building a few random apps in my quest for Ruby proficiency.\n\n
|
28
|
+
\ API docs can be found here: http://developer.glitch.com/api/\n\n Check github
|
29
|
+
for more detailed docs.\n"
|
30
|
+
email:
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/rbglitch/achievements_api.rb
|
36
|
+
- lib/rbglitch/auctions_api.rb
|
37
|
+
- lib/rbglitch/auth_api.rb
|
38
|
+
- lib/rbglitch/avatar_api.rb
|
39
|
+
- lib/rbglitch/base_api.rb
|
40
|
+
- lib/rbglitch/calendar_api.rb
|
41
|
+
- lib/rbglitch/locations_api.rb
|
42
|
+
- lib/rbglitch/players_api.rb
|
43
|
+
- lib/rbglitch/skills_api.rb
|
44
|
+
- lib/rbglitch.rb
|
45
|
+
homepage:
|
46
|
+
licenses: []
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.10
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Ruby bindings for the Glitch game API
|
69
|
+
test_files: []
|