mage-hand 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/ob_port/base.rb +54 -2
- data/lib/ob_port/campaign.rb +4 -4
- data/lib/ob_port/user.rb +1 -1
- data/lib/ob_port/wiki_page.rb +31 -4
- data/mage-hand.gemspec +6 -6
- data/test/test_base.rb +55 -0
- metadata +6 -6
- data/test/test_mage-hand.rb +0 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/ob_port/base.rb
CHANGED
@@ -1,8 +1,19 @@
|
|
1
1
|
module MageHand
|
2
2
|
class Base
|
3
|
-
|
3
|
+
@@simple_attributes = {}
|
4
|
+
@@instance_attributes = {}
|
4
5
|
|
5
|
-
def
|
6
|
+
def self.attr_simple(*method_names)
|
7
|
+
@@simple_attributes[self.name] = [] unless @@simple_attributes[self.name]
|
8
|
+
method_names.each do |method_name|
|
9
|
+
attr_accessor method_name
|
10
|
+
@@simple_attributes[self.name] << method_name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_simple :id
|
15
|
+
|
16
|
+
def initialize(attributes=nil)
|
6
17
|
update_attributes!(attributes)
|
7
18
|
end
|
8
19
|
|
@@ -15,6 +26,9 @@ module MageHand
|
|
15
26
|
end
|
16
27
|
|
17
28
|
def inflate
|
29
|
+
#if we don't have an id, the opject has not been created on the server yet
|
30
|
+
return unless self.id
|
31
|
+
|
18
32
|
hash = JSON.parse( MageHand::get_client.access_token.get(individual_url).body)
|
19
33
|
update_attributes!(hash)
|
20
34
|
end
|
@@ -22,7 +36,42 @@ module MageHand
|
|
22
36
|
def self.model_name
|
23
37
|
@_model_name ||= ActiveModel::Name.new(self)
|
24
38
|
end
|
39
|
+
|
40
|
+
def self.simple_attributes
|
41
|
+
@@simple_attributes[self.name] || []
|
42
|
+
end
|
43
|
+
|
44
|
+
def simple_attributes
|
45
|
+
self.class.simple_attributes
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.instance_attributes
|
49
|
+
@@instance_attributes[self.name] || []
|
50
|
+
end
|
51
|
+
|
52
|
+
def instance_attributes
|
53
|
+
self.class.instance_attributes
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.attributes
|
57
|
+
simple_attributes + instance_attributes
|
58
|
+
end
|
59
|
+
|
60
|
+
def attributes
|
61
|
+
self.class.attributes
|
62
|
+
end
|
25
63
|
|
64
|
+
def to_json(*a)
|
65
|
+
json_hash = {}
|
66
|
+
self.simple_attributes.each do |attribute|
|
67
|
+
json_hash[attribute.to_s] = self.send(attribute) if self.send(attribute)
|
68
|
+
end
|
69
|
+
self.instance_attributes.each do |attribute|
|
70
|
+
json_hash[attribute.to_s] = self.send(attribute).to_json if self.send(attribute)
|
71
|
+
end
|
72
|
+
json_hash.to_json(*a)
|
73
|
+
end
|
74
|
+
|
26
75
|
def self.attr_instance(method_name, options={})
|
27
76
|
self.class_eval do
|
28
77
|
name = method_name.to_s
|
@@ -38,6 +87,9 @@ module MageHand
|
|
38
87
|
CODE
|
39
88
|
puts code if ENV['DEBUG']
|
40
89
|
module_eval code
|
90
|
+
|
91
|
+
@@instance_attributes[self.name] = [] unless @@instance_attributes[self.name]
|
92
|
+
@@instance_attributes[self.name] << method_name
|
41
93
|
end
|
42
94
|
end
|
43
95
|
|
data/lib/ob_port/campaign.rb
CHANGED
@@ -3,18 +3,18 @@ module MageHand
|
|
3
3
|
ROLES = {'game_master' => 'Game Master', 'player' => 'Player'}
|
4
4
|
|
5
5
|
# public mini-object methods
|
6
|
-
|
6
|
+
attr_simple :name, :campaign_url, :role, :visibility
|
7
7
|
|
8
|
-
|
8
|
+
attr_simple :slug
|
9
9
|
attr_instance :game_master, :class_name => 'User'
|
10
10
|
inflate_if_nil :game_master, :slug
|
11
11
|
|
12
12
|
# Private/Friends
|
13
|
-
|
13
|
+
attr_simple :banner_image_url, :play_status, :looking_for_players, :created_at, :updated_at
|
14
14
|
inflate_if_nil :banner_image_url, :play_status, :looking_for_players, :created_at, :updated_at
|
15
15
|
|
16
16
|
# Player/GM Only
|
17
|
-
|
17
|
+
attr_simple :lat, :lng
|
18
18
|
inflate_if_nil :lat, :lng
|
19
19
|
|
20
20
|
attr_array :players, :class_name => 'User'
|
data/lib/ob_port/user.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module MageHand
|
2
2
|
class User < Base
|
3
|
-
|
3
|
+
attr_simple :username, :profile_url, :avatar_image_url,
|
4
4
|
:created_at, :last_seen_at, :utc_offset, :locale, :is_ascendant
|
5
5
|
inflate_if_nil :avatar_image_url, :created_at, :last_seen_at, :utc_offset,
|
6
6
|
:locale, :is_ascendant
|
data/lib/ob_port/wiki_page.rb
CHANGED
@@ -3,19 +3,22 @@ module MageHand
|
|
3
3
|
ROLES = {'game_master' => 'Game Master', 'player' => 'Player'}
|
4
4
|
|
5
5
|
# public methods
|
6
|
-
|
6
|
+
attr_simple :slug, :name, :wiki_page_url, :created_at, :updated_at
|
7
7
|
|
8
8
|
# Private/Friends
|
9
|
-
|
9
|
+
attr_simple :type, :is_game_master_only, :body, :body_html, :tags
|
10
10
|
inflate_if_nil :body, :body_html
|
11
11
|
|
12
12
|
# TODO Move these to the posts subclass when we have it.
|
13
|
-
|
13
|
+
attr_simple :post_title, :post_tagline, :post_time
|
14
14
|
|
15
15
|
# GM Only fields
|
16
|
-
|
16
|
+
attr_simple :game_master_info, :game_master_info_markup
|
17
17
|
inflate_if_nil :game_master_info, :game_master_info_markup
|
18
18
|
|
19
|
+
attr_instance :campaign
|
20
|
+
inflate_if_nil :campaign
|
21
|
+
|
19
22
|
def self.load_wiki_pages(campaign_id)
|
20
23
|
wiki_hashes = JSON.parse(
|
21
24
|
MageHand::get_client.access_token.get(collection_url(campaign_id)).body)
|
@@ -30,6 +33,30 @@ module MageHand
|
|
30
33
|
type == 'Post'
|
31
34
|
end
|
32
35
|
|
36
|
+
def to_hash
|
37
|
+
attribute_hash = {}
|
38
|
+
simple_attributes.each do |att|
|
39
|
+
attribute_hash[att] = self.send(att) unless self.send(att).nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
attribute_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_json
|
46
|
+
to_hash.to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
def save!
|
50
|
+
if id # save existing wiki pae
|
51
|
+
|
52
|
+
else # create new wiki page
|
53
|
+
json_body = {'wiki_page' => self.to_hash}.to_json
|
54
|
+
@response = MageHand.get_client.access_token.post(self.class.collection_url(self.campaign.id),
|
55
|
+
json_body, {'content-type' => 'application/x-www-form-urlencoded'})
|
56
|
+
self.update_attributes!(JSON.parse(@response.body))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
33
60
|
private
|
34
61
|
|
35
62
|
def self.collection_url(campaign_id)
|
data/mage-hand.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mage-hand}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steven Hammond"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-11-06}
|
13
13
|
s.description = %q{mage-hand is a ghostly hand that reaches across the internet to access the Obsidian Portal API.}
|
14
14
|
s.email = %q{shammond@northpub.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,9 +35,9 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/ob_port/wiki_page.rb",
|
36
36
|
"mage-hand.gemspec",
|
37
37
|
"test/helper.rb",
|
38
|
+
"test/test_base.rb",
|
38
39
|
"test/test_campaign.rb",
|
39
|
-
"test/test_client.rb"
|
40
|
-
"test/test_mage-hand.rb"
|
40
|
+
"test/test_client.rb"
|
41
41
|
]
|
42
42
|
s.homepage = %q{http://github.com/shammond42/mage-hand}
|
43
43
|
s.licenses = ["MIT"]
|
@@ -46,9 +46,9 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.summary = %q{Ruby wrapper around the Obsidian Portal API}
|
47
47
|
s.test_files = [
|
48
48
|
"test/helper.rb",
|
49
|
+
"test/test_base.rb",
|
49
50
|
"test/test_campaign.rb",
|
50
|
-
"test/test_client.rb"
|
51
|
-
"test/test_mage-hand.rb"
|
51
|
+
"test/test_client.rb"
|
52
52
|
]
|
53
53
|
|
54
54
|
if s.respond_to? :specification_version then
|
data/test/test_base.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class TestBase < Test::Unit::TestCase
|
4
|
+
context 'the Base class' do
|
5
|
+
should 'use the attr_simple method to add an attribute' do
|
6
|
+
MageHand::Base.attr_simple :test_attribute, :second_attribute
|
7
|
+
@instance = MageHand::Base.new
|
8
|
+
@instance.test_attribute = 'Hello'
|
9
|
+
@instance.second_attribute = 'World'
|
10
|
+
assert_equal 'Hello', @instance.test_attribute
|
11
|
+
assert_equal 'World', @instance.second_attribute
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'be able to get a list of simple attributes' do
|
15
|
+
MageHand::Base.attr_simple :test_attribute, :second_attribute
|
16
|
+
@instance = MageHand::Base.new
|
17
|
+
|
18
|
+
assert MageHand::Base.simple_attributes.include?(:test_attribute)
|
19
|
+
assert @instance.simple_attributes.include?(:test_attribute)
|
20
|
+
|
21
|
+
assert MageHand::Base.simple_attributes.include?(:second_attribute)
|
22
|
+
assert @instance.simple_attributes.include?(:second_attribute)
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'be able to add an instance of another class as an attribute' do
|
26
|
+
MageHand::Base.attr_instance :test_campaign, :class_name => 'Campaign'
|
27
|
+
@instance = MageHand::Base.new
|
28
|
+
@instance.test_campaign = {:name => "A Great Time"}
|
29
|
+
assert_equal "A Great Time", @instance.test_campaign.name
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'be able to get a list of instance attributes' do
|
33
|
+
MageHand::Base.attr_instance :test_campaign, :class_name => 'Campaign'
|
34
|
+
@instance = MageHand::Base.new
|
35
|
+
|
36
|
+
assert MageHand::Base.instance_attributes.include?(:test_campaign)
|
37
|
+
assert @instance.instance_attributes.include?(:test_campaign)
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'be able to get a list of all declared attributes' do
|
41
|
+
MageHand::Base.attr_instance :test_campaign, :class_name => 'Campaign'
|
42
|
+
MageHand::Base.attr_simple :test_attribute
|
43
|
+
@instance = MageHand::Base.new
|
44
|
+
|
45
|
+
assert MageHand::Base.attributes.include?(:test_campaign)
|
46
|
+
assert @instance.attributes.include?(:test_campaign)
|
47
|
+
assert MageHand::Base.attributes.include?(:test_attribute)
|
48
|
+
assert @instance.attributes.include?(:test_attribute)
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'have id as a simple attribute' do
|
52
|
+
assert MageHand::Base.simple_attributes.include?(:id)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
7
|
+
- 4
|
8
|
+
- 0
|
9
9
|
segments_generated: true
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steven Hammond
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-06 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -214,9 +214,9 @@ files:
|
|
214
214
|
- lib/ob_port/wiki_page.rb
|
215
215
|
- mage-hand.gemspec
|
216
216
|
- test/helper.rb
|
217
|
+
- test/test_base.rb
|
217
218
|
- test/test_campaign.rb
|
218
219
|
- test/test_client.rb
|
219
|
-
- test/test_mage-hand.rb
|
220
220
|
has_rdoc: true
|
221
221
|
homepage: http://github.com/shammond42/mage-hand
|
222
222
|
licenses:
|
@@ -251,6 +251,6 @@ specification_version: 3
|
|
251
251
|
summary: Ruby wrapper around the Obsidian Portal API
|
252
252
|
test_files:
|
253
253
|
- test/helper.rb
|
254
|
+
- test/test_base.rb
|
254
255
|
- test/test_campaign.rb
|
255
256
|
- test/test_client.rb
|
256
|
-
- test/test_mage-hand.rb
|