Class: MageHand::WikiPage
- Inherits:
-
Base
- Object
- Base
- MageHand::WikiPage
show all
- Defined in:
- lib/ob_port/wiki_page.rb
Constant Summary
collapse
- ROLES =
{'game_master' => 'Game Master', 'player' => 'Player'}
Instance Attribute Summary
Attributes inherited from Base
#client
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
attr_array, attr_instance, attr_simple, attributes, #attributes, #inflate, inflate_if_nil, #initialize, instance_attributes, #instance_attributes, model_name, #simple_attributes, simple_attributes, #update_attributes!
Constructor Details
This class inherits a constructor from MageHand::Base
Class Method Details
.load_wiki_pages(campaign) ⇒ Object
22
23
24
25
|
# File 'lib/ob_port/wiki_page.rb', line 22
def self.load_wiki_pages(campaign)
wiki_hashes = JSON.parse(campaign.client.access_token.get(collection_url(campaign.id)).body)
wiki_hashes.map {|hash| WikiPage.new(campaign.client, hash)}
end
|
Instance Method Details
#campaign=(campaign_hash) ⇒ Object
27
28
29
|
# File 'lib/ob_port/wiki_page.rb', line 27
def campaign=(campaign_hash)
@campaign = Campaign.new(client, campaign_hash)
end
|
#is_post? ⇒ Boolean
31
32
33
|
# File 'lib/ob_port/wiki_page.rb', line 31
def is_post?
type == 'Post'
end
|
#save! ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/ob_port/wiki_page.rb', line 48
def save!
if id
else json_body = {'wiki_page' => self.to_hash}.to_json
@response = client.access_token.post(self.class.collection_url(self.campaign.id),
json_body, {'content-type' => 'application/x-www-form-urlencoded'})
puts "#{@response.code}: #{@response.message}"
puts @response.body
if @response.code == 200
self.update_attributes!(JSON.parse(@response.body))
else
raise WikiPageExists if @response.body =~ /Name has already been taken/
end
end
end
|
#to_hash ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/ob_port/wiki_page.rb', line 35
def to_hash
attribute_hash = {}
simple_attributes.each do |att|
attribute_hash[att] = self.send(att) unless self.send(att).nil?
end
attribute_hash
end
|
#to_json ⇒ Object
44
45
46
|
# File 'lib/ob_port/wiki_page.rb', line 44
def to_json
to_hash.to_json
end
|