Class: MageHand::WikiPage

Inherits:
Base
  • Object
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

Returns:

  • (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
# File 'lib/ob_port/wiki_page.rb', line 48

def save!
  if id # save existing wiki pae
    
  else # create new wiki page
    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'})
    self.update_attributes!(JSON.parse(@response.body))
  end
end

#to_hashObject



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_jsonObject



44
45
46
# File 'lib/ob_port/wiki_page.rb', line 44

def to_json
  to_hash.to_json
end