mage-hand 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -0
- data/TODO +9 -0
- data/VERSION +1 -1
- data/lib/mage-hand.rb +10 -1
- data/lib/ob_port/base.rb +20 -2
- data/lib/ob_port/campaign.rb +14 -3
- data/lib/ob_port/client.rb +19 -2
- data/lib/ob_port/user.rb +1 -1
- data/lib/ob_port/wiki_page.rb +2 -2
- data/mage-hand.gemspec +10 -3
- data/test/helper.rb +1 -0
- data/test/test_campaign.rb +44 -0
- data/test/test_client.rb +7 -6
- metadata +25 -5
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,6 +2,8 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
activesupport (3.0.3)
|
5
|
+
addressable (2.2.4)
|
6
|
+
crack (0.1.8)
|
5
7
|
git (1.2.5)
|
6
8
|
i18n (0.4.2)
|
7
9
|
jeweler (1.5.1)
|
@@ -16,6 +18,9 @@ GEM
|
|
16
18
|
rcov (0.9.9)
|
17
19
|
redgreen (1.2.2)
|
18
20
|
shoulda (2.11.3)
|
21
|
+
webmock (1.6.2)
|
22
|
+
addressable (>= 2.2.2)
|
23
|
+
crack (>= 0.1.7)
|
19
24
|
|
20
25
|
PLATFORMS
|
21
26
|
ruby
|
@@ -31,3 +36,4 @@ DEPENDENCIES
|
|
31
36
|
rcov
|
32
37
|
redgreen
|
33
38
|
shoulda
|
39
|
+
webmock (>= 1.6.2)
|
data/TODO
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/mage-hand.rb
CHANGED
@@ -8,11 +8,20 @@ require 'ob_port/campaign'
|
|
8
8
|
require 'ob_port/wiki_page'
|
9
9
|
|
10
10
|
module MageHand
|
11
|
+
def self.set_app_keys(app_key, app_secret)
|
12
|
+
Client.set_app_keys(app_key, app_secret)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_client(session_request_token=nil, session_access_token_key=nil, session_access_token_secret=nil,
|
16
|
+
callback=nil, params=nil)
|
17
|
+
Client.get_client(session_request_token, session_access_token_key, session_access_token_secret,
|
18
|
+
callback, params)
|
19
|
+
end
|
11
20
|
|
12
21
|
protected
|
13
22
|
|
14
23
|
def obsidian_portal_login_required
|
15
|
-
@mage_client =
|
24
|
+
@mage_client = Client.get_client(session[:request_token], session[:access_token_key],
|
16
25
|
session[:access_token_secret], request.url, params)
|
17
26
|
store_tokens
|
18
27
|
return true if logged_in?
|
data/lib/ob_port/base.rb
CHANGED
@@ -15,13 +15,31 @@ module MageHand
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def inflate
|
18
|
-
hash = JSON.parse( MageHand::
|
18
|
+
hash = JSON.parse( MageHand::get_client.access_token.get(individual_url).body)
|
19
19
|
update_attributes!(hash)
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.model_name
|
23
23
|
@_model_name ||= ActiveModel::Name.new(self)
|
24
24
|
end
|
25
|
+
|
26
|
+
def self.attr_instance(method_name, options={})
|
27
|
+
self.class_eval do
|
28
|
+
name = method_name.to_s
|
29
|
+
class_name = options[:class_name] || name.classify
|
30
|
+
code = <<-CODE
|
31
|
+
def #{name}
|
32
|
+
@#{name}
|
33
|
+
end
|
34
|
+
|
35
|
+
def #{name}=(new_#{name})
|
36
|
+
@#{name} = #{class_name}.new(new_#{name.singularize})
|
37
|
+
end
|
38
|
+
CODE
|
39
|
+
puts code if ENV['DEBUG']
|
40
|
+
module_eval code
|
41
|
+
end
|
42
|
+
end
|
25
43
|
|
26
44
|
def self.attr_array(method_name, options={})
|
27
45
|
self.class_eval do
|
@@ -39,7 +57,7 @@ module MageHand
|
|
39
57
|
end
|
40
58
|
end
|
41
59
|
CODE
|
42
|
-
puts code
|
60
|
+
puts code if ENV['DEBUG']
|
43
61
|
module_eval code
|
44
62
|
end
|
45
63
|
end
|
data/lib/ob_port/campaign.rb
CHANGED
@@ -5,8 +5,9 @@ module MageHand
|
|
5
5
|
# public mini-object methods
|
6
6
|
attr_accessor :name, :campaign_url, :role, :visibility
|
7
7
|
|
8
|
-
attr_accessor :
|
9
|
-
|
8
|
+
attr_accessor :slug
|
9
|
+
attr_instance :game_master, :class_name => 'User'
|
10
|
+
inflate_if_nil :game_master, :slug
|
10
11
|
|
11
12
|
# Private/Friends
|
12
13
|
attr_accessor :banner_image_url, :play_status, :looking_for_players, :created_at, :updated_at
|
@@ -18,6 +19,16 @@ module MageHand
|
|
18
19
|
|
19
20
|
attr_array :players, :class_name => 'User'
|
20
21
|
inflate_if_nil :players
|
22
|
+
|
23
|
+
def self.find_by_slug(slug)
|
24
|
+
hash = JSON.parse( MageHand::get_client.access_token.get("/v1/campaigns/#{slug}.json?use_slug=true").body)
|
25
|
+
Campaign.new(hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find(id)
|
29
|
+
hash = JSON.parse( MageHand::get_client.access_token.get("/v1/campaigns/#{id}.json").body)
|
30
|
+
Campaign.new(hash)
|
31
|
+
end
|
21
32
|
|
22
33
|
def looking_for_players?
|
23
34
|
looking_for_players
|
@@ -35,7 +46,7 @@ module MageHand
|
|
35
46
|
@adventure_logs ||= wiki_pages.select{|page| page.is_post?}
|
36
47
|
end
|
37
48
|
|
38
|
-
|
49
|
+
protected
|
39
50
|
|
40
51
|
def individual_url
|
41
52
|
"/v1/campaigns/#{self.id}.json"
|
data/lib/ob_port/client.rb
CHANGED
@@ -1,12 +1,23 @@
|
|
1
1
|
module MageHand
|
2
2
|
class Client
|
3
3
|
attr_accessor :request_token, :access_token_key, :access_token_secret
|
4
|
+
@@client = nil
|
4
5
|
|
5
|
-
def self.
|
6
|
+
def self.set_app_keys(key, secret)
|
6
7
|
@@key = key
|
7
8
|
@@secret = secret
|
8
9
|
end
|
9
|
-
|
10
|
+
|
11
|
+
def self.get_client(session_request_token=nil, session_access_token_key=nil, session_access_token_secret=nil,
|
12
|
+
callback=nil, params=nil)
|
13
|
+
# If we don't have a client, or we are changing a token, initialize a new client
|
14
|
+
if !@@client || session_request_token || session_access_token_key || session_access_token_secret
|
15
|
+
@@client = Client.new(session_request_token, session_access_token_key,
|
16
|
+
session_access_token_secret, callback, params)
|
17
|
+
end
|
18
|
+
@@client
|
19
|
+
end
|
20
|
+
|
10
21
|
def initialize(session_request_token=nil, session_access_token_key=nil, session_access_token_secret=nil,
|
11
22
|
callback=nil, params=nil)
|
12
23
|
@request_token = session_request_token
|
@@ -47,5 +58,11 @@ module MageHand
|
|
47
58
|
def campaign(id)
|
48
59
|
MageHand::Campaign.new(JSON.parse(access_token.get("/v1/campaigns/#{id}.json").body))
|
49
60
|
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def self.reset_client
|
65
|
+
@@client = nil
|
66
|
+
end
|
50
67
|
end
|
51
68
|
end
|
data/lib/ob_port/user.rb
CHANGED
data/lib/ob_port/wiki_page.rb
CHANGED
@@ -10,7 +10,7 @@ module MageHand
|
|
10
10
|
inflate_if_nil :body, :body_html
|
11
11
|
|
12
12
|
# TODO Move these to the posts subclass when we have it.
|
13
|
-
attr_accessor :post_title, :
|
13
|
+
attr_accessor :post_title, :post_tagline, :post_time
|
14
14
|
|
15
15
|
# GM Only fields
|
16
16
|
attr_accessor :game_master_info, :game_master_info_markup
|
@@ -18,7 +18,7 @@ module MageHand
|
|
18
18
|
|
19
19
|
def self.load_wiki_pages(campaign_id)
|
20
20
|
wiki_hashes = JSON.parse(
|
21
|
-
MageHand::
|
21
|
+
MageHand::get_client.access_token.get(collection_url(campaign_id)).body)
|
22
22
|
wiki_hashes.map {|hash| WikiPage.new(hash)}
|
23
23
|
end
|
24
24
|
|
data/mage-hand.gemspec
CHANGED
@@ -5,16 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mage-hand}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
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-06-07}
|
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 = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
17
|
+
"README.rdoc",
|
18
|
+
"TODO"
|
18
19
|
]
|
19
20
|
s.files = [
|
20
21
|
".document",
|
@@ -23,6 +24,7 @@ Gem::Specification.new do |s|
|
|
23
24
|
"LICENSE.txt",
|
24
25
|
"README.rdoc",
|
25
26
|
"Rakefile",
|
27
|
+
"TODO",
|
26
28
|
"VERSION",
|
27
29
|
"lib/mage-hand.rb",
|
28
30
|
"lib/ob_port/base.rb",
|
@@ -32,6 +34,7 @@ Gem::Specification.new do |s|
|
|
32
34
|
"lib/ob_port/wiki_page.rb",
|
33
35
|
"mage-hand.gemspec",
|
34
36
|
"test/helper.rb",
|
37
|
+
"test/test_campaign.rb",
|
35
38
|
"test/test_client.rb",
|
36
39
|
"test/test_mage-hand.rb"
|
37
40
|
]
|
@@ -42,6 +45,7 @@ Gem::Specification.new do |s|
|
|
42
45
|
s.summary = %q{Ruby wrapper around the Obsidian Portal API}
|
43
46
|
s.test_files = [
|
44
47
|
"test/helper.rb",
|
48
|
+
"test/test_campaign.rb",
|
45
49
|
"test/test_client.rb",
|
46
50
|
"test/test_mage-hand.rb"
|
47
51
|
]
|
@@ -61,6 +65,7 @@ Gem::Specification.new do |s|
|
|
61
65
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
66
|
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
63
67
|
s.add_development_dependency(%q<redgreen>, [">= 0"])
|
68
|
+
s.add_development_dependency(%q<webmock>, [">= 1.6.2"])
|
64
69
|
s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
|
65
70
|
else
|
66
71
|
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
@@ -73,6 +78,7 @@ Gem::Specification.new do |s|
|
|
73
78
|
s.add_dependency(%q<rcov>, [">= 0"])
|
74
79
|
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
75
80
|
s.add_dependency(%q<redgreen>, [">= 0"])
|
81
|
+
s.add_dependency(%q<webmock>, [">= 1.6.2"])
|
76
82
|
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
77
83
|
end
|
78
84
|
else
|
@@ -86,6 +92,7 @@ Gem::Specification.new do |s|
|
|
86
92
|
s.add_dependency(%q<rcov>, [">= 0"])
|
87
93
|
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
88
94
|
s.add_dependency(%q<redgreen>, [">= 0"])
|
95
|
+
s.add_dependency(%q<webmock>, [">= 1.6.2"])
|
89
96
|
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
90
97
|
end
|
91
98
|
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test/helper'
|
2
|
+
|
3
|
+
class TestCampaign < Test::Unit::TestCase
|
4
|
+
context 'an instance of the Campaign class' do
|
5
|
+
should 'know its url' do
|
6
|
+
id_string = 'asdf12341asdf1234'
|
7
|
+
campaign = MageHand::Campaign.new(:id => id_string)
|
8
|
+
assert_equal "/v1/campaigns/#{id_string}.json", campaign.send(:individual_url)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'the Campaign class' do
|
13
|
+
setup do
|
14
|
+
@mini_fields = {
|
15
|
+
:id => 'asdf12341asdf1234',
|
16
|
+
:name => 'Fellowship of the Ring',
|
17
|
+
:campaign_url => 'http://www.obsidianportal.com/campaigns/fellowship-of-the-ring',
|
18
|
+
:visibility => 'public',
|
19
|
+
:role => 'player'
|
20
|
+
}
|
21
|
+
@full_fields = @mini_fields.merge(
|
22
|
+
:slug => 'FotR',
|
23
|
+
:play_status => 'active',
|
24
|
+
:looking_for_players => false
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'be able to initialize from a mini object' do
|
29
|
+
campaign = MageHand::Campaign.new(@mini_fields)
|
30
|
+
assert_not_nil campaign
|
31
|
+
@mini_fields.each do |key, value|
|
32
|
+
assert_equal campaign.send(key), value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'be able to initialize from a complete object' do
|
37
|
+
campaign = MageHand::Campaign.new(@full_fields)
|
38
|
+
assert_not_nil campaign
|
39
|
+
@full_fields.each do |key, value|
|
40
|
+
assert_equal campaign.send(key), value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -3,7 +3,7 @@ require 'helper'
|
|
3
3
|
class TestClient < Test::Unit::TestCase
|
4
4
|
context "The Obsidian Portal client" do
|
5
5
|
should "configure correctly with a key and secret" do
|
6
|
-
assert_nothing_raised {MageHand::Client.
|
6
|
+
assert_nothing_raised {MageHand::Client.set_app_keys('asdfasdf','asdfasdfasdfasdfasdf')}
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
@@ -19,29 +19,30 @@ class TestClient < Test::Unit::TestCase
|
|
19
19
|
OAuth::AccessToken.any_instance.stubs(:post).returns(response)
|
20
20
|
OAuth::Consumer.any_instance.stubs(:get_request_token).returns(@request_token)
|
21
21
|
|
22
|
-
MageHand::Client.
|
22
|
+
MageHand::Client.send(:reset_client)
|
23
|
+
MageHand::Client.set_app_keys('asdfasdf', 'asdfasdfasdfasdfasdf')
|
23
24
|
end
|
24
25
|
should "be configured to use different urls for authentication and api access" do
|
25
|
-
@client = MageHand::
|
26
|
+
@client = MageHand::get_client(nil, nil, nil)
|
26
27
|
assert @client.consumer.site =~ /api\.obsidianportal\.com/
|
27
28
|
assert @client.consumer.request_token_url =~ /https:\/\/www\.obsidianportal\.com/
|
28
29
|
assert @client.consumer.authorize_url =~ /https:\/\/www\.obsidianportal\.com/
|
29
30
|
assert @client.consumer.access_token_url =~ /https:\/\/www\.obsidianportal\.com/
|
30
31
|
end
|
31
32
|
should "have a request_token, and not an access token, when authorizing" do
|
32
|
-
@client = MageHand::
|
33
|
+
@client = MageHand::get_client(nil, nil, nil)
|
33
34
|
assert_not_nil @client
|
34
35
|
assert_equal @client.request_token, @request_token
|
35
36
|
assert_nil @client.access_token
|
36
37
|
end
|
37
38
|
should "create an access_token when an oauth_verifier and request_token is passed in" do
|
38
|
-
@client = MageHand::
|
39
|
+
@client = MageHand::get_client(@request_token, nil, nil, nil, {:oauth_verifier => 'asdfasdf'})
|
39
40
|
assert_not_nil @client
|
40
41
|
assert_not_nil @client.access_token
|
41
42
|
assert @client.logged_in?
|
42
43
|
end
|
43
44
|
should "be logged in if initialized with an access_key and access_secret" do
|
44
|
-
@client = MageHand::
|
45
|
+
@client = MageHand::get_client(nil, 'asdf', 'asdfasdfasdfasdf')
|
45
46
|
assert_not_nil @client
|
46
47
|
assert @client.logged_in?
|
47
48
|
assert_equal @client.access_token.token, 'asdf'
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
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-06-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -169,6 +169,22 @@ dependencies:
|
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
170
|
prerelease: false
|
171
171
|
version_requirements: &id011 !ruby/object:Gem::Requirement
|
172
|
+
none: false
|
173
|
+
requirements:
|
174
|
+
- - ">="
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
hash: 11
|
177
|
+
segments:
|
178
|
+
- 1
|
179
|
+
- 6
|
180
|
+
- 2
|
181
|
+
version: 1.6.2
|
182
|
+
name: webmock
|
183
|
+
requirement: *id011
|
184
|
+
type: :development
|
185
|
+
- !ruby/object:Gem::Dependency
|
186
|
+
prerelease: false
|
187
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
172
188
|
none: false
|
173
189
|
requirements:
|
174
190
|
- - ">="
|
@@ -180,7 +196,7 @@ dependencies:
|
|
180
196
|
- 4
|
181
197
|
version: 0.4.4
|
182
198
|
name: oauth
|
183
|
-
requirement: *
|
199
|
+
requirement: *id012
|
184
200
|
type: :runtime
|
185
201
|
description: mage-hand is a ghostly hand that reaches across the internet to access the Obsidian Portal API.
|
186
202
|
email: shammond@northpub.com
|
@@ -191,6 +207,7 @@ extensions: []
|
|
191
207
|
extra_rdoc_files:
|
192
208
|
- LICENSE.txt
|
193
209
|
- README.rdoc
|
210
|
+
- TODO
|
194
211
|
files:
|
195
212
|
- .document
|
196
213
|
- Gemfile
|
@@ -198,6 +215,7 @@ files:
|
|
198
215
|
- LICENSE.txt
|
199
216
|
- README.rdoc
|
200
217
|
- Rakefile
|
218
|
+
- TODO
|
201
219
|
- VERSION
|
202
220
|
- lib/mage-hand.rb
|
203
221
|
- lib/ob_port/base.rb
|
@@ -207,6 +225,7 @@ files:
|
|
207
225
|
- lib/ob_port/wiki_page.rb
|
208
226
|
- mage-hand.gemspec
|
209
227
|
- test/helper.rb
|
228
|
+
- test/test_campaign.rb
|
210
229
|
- test/test_client.rb
|
211
230
|
- test/test_mage-hand.rb
|
212
231
|
has_rdoc: true
|
@@ -245,5 +264,6 @@ specification_version: 3
|
|
245
264
|
summary: Ruby wrapper around the Obsidian Portal API
|
246
265
|
test_files:
|
247
266
|
- test/helper.rb
|
267
|
+
- test/test_campaign.rb
|
248
268
|
- test/test_client.rb
|
249
269
|
- test/test_mage-hand.rb
|