mage-hand 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,9 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "oauth", ">= 0.4.4"
6
+ gem "json"
7
+ gem 'i18n'
8
+ gem 'activesupport'
6
9
 
7
10
  # Add dependencies to develop your gem here.
8
11
  # Include everything needed to run rake, tests, features, etc.
@@ -1,11 +1,14 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ activesupport (3.0.3)
4
5
  git (1.2.5)
6
+ i18n (0.4.2)
5
7
  jeweler (1.5.1)
6
8
  bundler (~> 1.0.0)
7
9
  git (>= 1.2.5)
8
10
  rake
11
+ json (1.4.6)
9
12
  mocha (0.9.8)
10
13
  rake
11
14
  oauth (0.4.4)
@@ -18,8 +21,11 @@ PLATFORMS
18
21
  ruby
19
22
 
20
23
  DEPENDENCIES
24
+ activesupport
21
25
  bundler (~> 1.0.0)
26
+ i18n
22
27
  jeweler (~> 1.5.1)
28
+ json
23
29
  mocha (>= 0.9.8)
24
30
  oauth (>= 0.4.4)
25
31
  rcov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -1,7 +1,11 @@
1
+ require 'OAuth'
2
+ require 'json'
3
+ require 'active_support/core_ext/string'
1
4
  require 'ob_port/client'
2
5
  require 'ob_port/base'
3
6
  require 'ob_port/user'
4
7
  require 'ob_port/campaign'
8
+ require 'ob_port/wiki_page'
5
9
 
6
10
  module MageHand
7
11
 
@@ -3,15 +3,57 @@ module MageHand
3
3
  attr_accessor :id
4
4
 
5
5
  def initialize(attributes)
6
- attributes ||= {}
6
+ update_attributes!(attributes)
7
+ end
8
+
9
+ def update_attributes!(attributes)
10
+ return unless attributes
7
11
  attributes.each do |key, value|
8
12
  setter = "#{key}="
9
13
  self.send setter, value if self.respond_to?(setter)
10
14
  end
11
15
  end
12
16
 
17
+ def inflate
18
+ hash = JSON.parse( MageHand::client.access_token.get(individual_url).body)
19
+ update_attributes!(hash)
20
+ end
21
+
13
22
  def self.model_name
14
23
  @_model_name ||= ActiveModel::Name.new(self)
15
24
  end
25
+
26
+ def self.attr_array(method_name, options={})
27
+ self.class_eval do
28
+ name = method_name.to_s
29
+ class_name = options[:class_name] || name.singularize.classify
30
+ code = <<-CODE
31
+ def #{name}
32
+ @#{name}
33
+ end
34
+
35
+ def #{name}=(new_#{name})
36
+ @#{name} = []
37
+ new_#{name}.each do |#{name.singularize}|
38
+ @#{name} << #{class_name}.new(#{name.singularize})
39
+ end
40
+ end
41
+ CODE
42
+ puts code
43
+ module_eval code
44
+ end
45
+ end
46
+
47
+ def self.inflate_if_nil(*method_names)
48
+ self.class_eval do
49
+ method_names.each do |method_name|
50
+ alias_method "#{method_name.to_s}_original".to_sym, method_name
51
+ define_method method_name do
52
+ inflate if self.send("#{method_name.to_s}_original".to_sym).nil?
53
+ self.send("#{method_name.to_s}_original".to_sym)
54
+ end
55
+ end
56
+ end
57
+ end
16
58
  end
17
59
  end
@@ -1,5 +1,44 @@
1
1
  module MageHand
2
2
  class Campaign < Base
3
- attr_accessor :name, :campaign_url, :role, :visibility
3
+ ROLES = {'game_master' => 'Game Master', 'player' => 'Player'}
4
+
5
+ # public mini-object methods
6
+ attr_accessor :name, :campaign_url, :role, :visibility
7
+
8
+ attr_accessor :game_master_id, :slug
9
+ inflate_if_nil :game_master_id, :slug
10
+
11
+ # Private/Friends
12
+ attr_accessor :banner_image_url, :play_status, :looking_for_players, :created_at, :updated_at
13
+ inflate_if_nil :banner_image_url, :play_status, :looking_for_players, :created_at, :updated_at
14
+
15
+ # Player/GM Only
16
+ attr_accessor :lat, :lng
17
+ inflate_if_nil :lat, :lng
18
+
19
+ attr_array :players, :class_name => 'User'
20
+ inflate_if_nil :players
21
+
22
+ def looking_for_players?
23
+ looking_for_players
24
+ end
25
+
26
+ def role_as_title_string
27
+ ROLES[self.role]
28
+ end
29
+
30
+ def wiki_pages
31
+ @wiki_pages ||= MageHand::WikiPage.load_wiki_pages(self.id)
32
+ end
33
+
34
+ def posts
35
+ @adventure_logs ||= wiki_pages.select{|page| page.is_post?}
36
+ end
37
+
38
+ private
39
+
40
+ def individual_url
41
+ "/v1/campaigns/#{self.id}.json"
42
+ end
4
43
  end
5
44
  end
@@ -40,7 +40,12 @@ module MageHand
40
40
  end
41
41
 
42
42
  def current_user
43
- MageHand::User.new(JSON.parse(access_token.get('/v1/users/me.json').body))
43
+ @current_user ||= MageHand::User.new(JSON.parse(access_token.get('/v1/users/me.json').body))
44
+ end
45
+ alias :me :current_user
46
+
47
+ def campaign(id)
48
+ MageHand::Campaign.new(JSON.parse(access_token.get("/v1/campaigns/#{id}.json").body))
44
49
  end
45
50
  end
46
51
  end
@@ -2,18 +2,18 @@ module MageHand
2
2
  class User < Base
3
3
  attr_accessor :username, :profile_url, :avatar_image_url,
4
4
  :created_at, :last_seen_at, :utc_offset, :locale, :is_ascendant
5
+ inflate_if_nil :avatar_image_url, :created_at, :last_seen_at, :utc_offset,
6
+ :locale, :is_ascendant
5
7
 
6
8
  alias :is_ascendant? :is_ascendant
9
+
10
+ attr_array :campaigns
11
+ inflate_if_nil :campaigns
7
12
 
8
- def campaigns
9
- @campaigns
10
- end
11
-
12
- def campaigns=(new_campaigns)
13
- @campaigns = []
14
- new_campaigns.each do |campaign|
15
- @campaigns << Campaign.new(campaign)
16
- end
13
+ private
14
+
15
+ def individual_url
16
+ "/v1/users/#{self.id}.json"
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,43 @@
1
+ module MageHand
2
+ class WikiPage < Base
3
+ ROLES = {'game_master' => 'Game Master', 'player' => 'Player'}
4
+
5
+ # public methods
6
+ attr_accessor :slug, :name, :wiki_page_url, :campaign, :created_at, :updated_at
7
+
8
+ # Private/Friends
9
+ attr_accessor :type, :is_game_master_only, :body, :body_html, :tags
10
+ inflate_if_nil :body, :body_html
11
+
12
+ # TODO Move these to the posts subclass when we have it.
13
+ attr_accessor :post_title, :post_taglines, :post_time
14
+
15
+ # GM Only fields
16
+ attr_accessor :game_master_info, :game_master_info_markup
17
+ inflate_if_nil :game_master_info, :game_master_info_markup
18
+
19
+ def self.load_wiki_pages(campaign_id)
20
+ wiki_hashes = JSON.parse(
21
+ MageHand::client.access_token.get(collection_url(campaign_id)).body)
22
+ wiki_hashes.map {|hash| WikiPage.new(hash)}
23
+ end
24
+
25
+ def campaign=(campaign_hash)
26
+ @campaign ||= Campaign.new(campaign_hash)
27
+ end
28
+
29
+ def is_post?
30
+ type == 'Post'
31
+ end
32
+
33
+ private
34
+
35
+ def self.collection_url(campaign_id)
36
+ "/v1/campaigns/#{campaign_id}/wikis.json"
37
+ end
38
+
39
+ def individual_url
40
+ "/v1/campaigns/#{self.campaign.id}/wikis/#{self.id}.json?"
41
+ end
42
+ end
43
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mage-hand}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.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{2010-11-30}
12
+ s.date = %q{2011-03-03}
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 = [
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/ob_port/campaign.rb",
30
30
  "lib/ob_port/client.rb",
31
31
  "lib/ob_port/user.rb",
32
+ "lib/ob_port/wiki_page.rb",
32
33
  "mage-hand.gemspec",
33
34
  "test/helper.rb",
34
35
  "test/test_client.rb",
@@ -51,6 +52,9 @@ Gem::Specification.new do |s|
51
52
 
52
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
54
  s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
55
+ s.add_runtime_dependency(%q<json>, [">= 0"])
56
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
57
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
54
58
  s.add_development_dependency(%q<shoulda>, [">= 0"])
55
59
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
60
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
@@ -60,6 +64,9 @@ Gem::Specification.new do |s|
60
64
  s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
61
65
  else
62
66
  s.add_dependency(%q<oauth>, [">= 0.4.4"])
67
+ s.add_dependency(%q<json>, [">= 0"])
68
+ s.add_dependency(%q<i18n>, [">= 0"])
69
+ s.add_dependency(%q<activesupport>, [">= 0"])
63
70
  s.add_dependency(%q<shoulda>, [">= 0"])
64
71
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
72
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
@@ -70,6 +77,9 @@ Gem::Specification.new do |s|
70
77
  end
71
78
  else
72
79
  s.add_dependency(%q<oauth>, [">= 0.4.4"])
80
+ s.add_dependency(%q<json>, [">= 0"])
81
+ s.add_dependency(%q<i18n>, [">= 0"])
82
+ s.add_dependency(%q<activesupport>, [">= 0"])
73
83
  s.add_dependency(%q<shoulda>, [">= 0"])
74
84
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
85
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mage-hand
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.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: 2010-11-30 00:00:00 -05:00
18
+ date: 2011-03-03 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,54 @@ dependencies:
45
45
  segments:
46
46
  - 0
47
47
  version: "0"
48
- name: shoulda
48
+ name: json
49
49
  requirement: *id002
50
- type: :development
50
+ type: :runtime
51
51
  - !ruby/object:Gem::Dependency
52
52
  prerelease: false
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ name: i18n
63
+ requirement: *id003
64
+ type: :runtime
65
+ - !ruby/object:Gem::Dependency
66
+ prerelease: false
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ name: activesupport
77
+ requirement: *id004
78
+ type: :runtime
79
+ - !ruby/object:Gem::Dependency
80
+ prerelease: false
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ name: shoulda
91
+ requirement: *id005
92
+ type: :development
93
+ - !ruby/object:Gem::Dependency
94
+ prerelease: false
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
54
96
  none: false
55
97
  requirements:
56
98
  - - ~>
@@ -62,11 +104,11 @@ dependencies:
62
104
  - 0
63
105
  version: 1.0.0
64
106
  name: bundler
65
- requirement: *id003
107
+ requirement: *id006
66
108
  type: :development
67
109
  - !ruby/object:Gem::Dependency
68
110
  prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
70
112
  none: false
71
113
  requirements:
72
114
  - - ~>
@@ -78,11 +120,11 @@ dependencies:
78
120
  - 1
79
121
  version: 1.5.1
80
122
  name: jeweler
81
- requirement: *id004
123
+ requirement: *id007
82
124
  type: :development
83
125
  - !ruby/object:Gem::Dependency
84
126
  prerelease: false
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
127
+ version_requirements: &id008 !ruby/object:Gem::Requirement
86
128
  none: false
87
129
  requirements:
88
130
  - - ">="
@@ -92,11 +134,11 @@ dependencies:
92
134
  - 0
93
135
  version: "0"
94
136
  name: rcov
95
- requirement: *id005
137
+ requirement: *id008
96
138
  type: :development
97
139
  - !ruby/object:Gem::Dependency
98
140
  prerelease: false
99
- version_requirements: &id006 !ruby/object:Gem::Requirement
141
+ version_requirements: &id009 !ruby/object:Gem::Requirement
100
142
  none: false
101
143
  requirements:
102
144
  - - ">="
@@ -108,11 +150,11 @@ dependencies:
108
150
  - 8
109
151
  version: 0.9.8
110
152
  name: mocha
111
- requirement: *id006
153
+ requirement: *id009
112
154
  type: :development
113
155
  - !ruby/object:Gem::Dependency
114
156
  prerelease: false
115
- version_requirements: &id007 !ruby/object:Gem::Requirement
157
+ version_requirements: &id010 !ruby/object:Gem::Requirement
116
158
  none: false
117
159
  requirements:
118
160
  - - ">="
@@ -122,11 +164,11 @@ dependencies:
122
164
  - 0
123
165
  version: "0"
124
166
  name: redgreen
125
- requirement: *id007
167
+ requirement: *id010
126
168
  type: :development
127
169
  - !ruby/object:Gem::Dependency
128
170
  prerelease: false
129
- version_requirements: &id008 !ruby/object:Gem::Requirement
171
+ version_requirements: &id011 !ruby/object:Gem::Requirement
130
172
  none: false
131
173
  requirements:
132
174
  - - ">="
@@ -138,7 +180,7 @@ dependencies:
138
180
  - 4
139
181
  version: 0.4.4
140
182
  name: oauth
141
- requirement: *id008
183
+ requirement: *id011
142
184
  type: :runtime
143
185
  description: mage-hand is a ghostly hand that reaches across the internet to access the Obsidian Portal API.
144
186
  email: shammond@northpub.com
@@ -162,6 +204,7 @@ files:
162
204
  - lib/ob_port/campaign.rb
163
205
  - lib/ob_port/client.rb
164
206
  - lib/ob_port/user.rb
207
+ - lib/ob_port/wiki_page.rb
165
208
  - mage-hand.gemspec
166
209
  - test/helper.rb
167
210
  - test/test_client.rb