spacer 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/MIT-LICENSE +21 -0
- data/Manifest.txt +34 -0
- data/README.txt +54 -0
- data/Rakefile +20 -0
- data/bin/spacer +8 -0
- data/lib/spacer.rb +63 -0
- data/lib/spacer/auth.rb +23 -0
- data/lib/spacer/client.rb +141 -0
- data/lib/spacer/model.rb +124 -0
- data/lib/spacer/models/album.rb +6 -0
- data/lib/spacer/models/details.rb +6 -0
- data/lib/spacer/models/group.rb +6 -0
- data/lib/spacer/models/interest.rb +6 -0
- data/lib/spacer/models/mood.rb +6 -0
- data/lib/spacer/models/photo.rb +6 -0
- data/lib/spacer/models/profile.rb +6 -0
- data/lib/spacer/models/status.rb +6 -0
- data/lib/spacer/models/user.rb +77 -0
- data/lib/spacer/models/video.rb +6 -0
- data/tasks/annotations.rake +30 -0
- data/tasks/doc.rake +49 -0
- data/tasks/gem.rake +89 -0
- data/tasks/manifest.rake +55 -0
- data/tasks/post_load.rake +18 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +191 -0
- data/tasks/spec.rake +43 -0
- data/tasks/svn.rake +44 -0
- data/tasks/test.rake +40 -0
- data/test/test_client.rb +144 -0
- data/test/test_helper.rb +82 -0
- data/test/test_spacer.rb +0 -0
- data/test/test_user.rb +33 -0
- metadata +85 -0
data/tasks/setup.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
ENV['VERSION'] = "0.5.0"
|
9
|
+
|
10
|
+
PROJ = OpenStruct.new
|
11
|
+
|
12
|
+
PROJ.name = nil
|
13
|
+
PROJ.summary = nil
|
14
|
+
PROJ.description = nil
|
15
|
+
PROJ.changes = nil
|
16
|
+
PROJ.authors = nil
|
17
|
+
PROJ.email = nil
|
18
|
+
PROJ.url = nil
|
19
|
+
PROJ.version = ENV['VERSION'] || '0.0.0'
|
20
|
+
PROJ.rubyforge_name = nil
|
21
|
+
PROJ.exclude = %w(tmp$ bak$ ~$ CVS .svn/ ^pkg/ ^doc/)
|
22
|
+
|
23
|
+
# Rspec
|
24
|
+
PROJ.specs = FileList['spec/**/*_spec.rb']
|
25
|
+
PROJ.spec_opts = []
|
26
|
+
|
27
|
+
# Test::Unit
|
28
|
+
PROJ.tests = FileList['test/**/test_*.rb']
|
29
|
+
PROJ.test_file = 'test/all.rb'
|
30
|
+
PROJ.test_opts = []
|
31
|
+
|
32
|
+
# Rcov
|
33
|
+
PROJ.rcov_opts = ['--sort', 'coverage', '-T']
|
34
|
+
|
35
|
+
# Rdoc
|
36
|
+
PROJ.rdoc_opts = []
|
37
|
+
PROJ.rdoc_include = %w(^lib/ ^bin/ ^ext/ .txt$)
|
38
|
+
PROJ.rdoc_exclude = %w(extconf.rb$ ^Manifest.txt$)
|
39
|
+
PROJ.rdoc_main = 'README.txt'
|
40
|
+
PROJ.rdoc_dir = 'doc'
|
41
|
+
PROJ.rdoc_remote_dir = nil
|
42
|
+
|
43
|
+
# Extensions
|
44
|
+
PROJ.extensions = FileList['ext/**/extconf.rb']
|
45
|
+
PROJ.ruby_opts = %w(-w)
|
46
|
+
PROJ.libs = []
|
47
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
48
|
+
|
49
|
+
# Gem Packaging
|
50
|
+
PROJ.files =
|
51
|
+
if test ?f, 'Manifest.txt'
|
52
|
+
files = File.readlines('Manifest.txt').map {|fn| fn.chomp.strip}
|
53
|
+
files.delete ''
|
54
|
+
files
|
55
|
+
else [] end
|
56
|
+
PROJ.executables = PROJ.files.find_all {|fn| fn =~ %r/^bin/}
|
57
|
+
PROJ.dependencies = []
|
58
|
+
PROJ.need_tar = true
|
59
|
+
PROJ.need_zip = false
|
60
|
+
|
61
|
+
# File Annotations
|
62
|
+
PROJ.annotation_exclude = []
|
63
|
+
PROJ.annotation_extensions = %w(.txt .rb .erb) << ''
|
64
|
+
|
65
|
+
# Subversion Repository
|
66
|
+
PROJ.svn = false
|
67
|
+
PROJ.svn_root = nil
|
68
|
+
PROJ.svn_trunk = 'trunk'
|
69
|
+
PROJ.svn_tags = 'tags'
|
70
|
+
PROJ.svn_branches = 'branches'
|
71
|
+
|
72
|
+
# Load the other rake files in the tasks folder
|
73
|
+
rakefiles = Dir.glob('tasks/*.rake').sort
|
74
|
+
rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
|
75
|
+
import(*rakefiles)
|
76
|
+
|
77
|
+
# Setup some constants
|
78
|
+
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
|
79
|
+
|
80
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
81
|
+
|
82
|
+
def quiet( &block )
|
83
|
+
io = [STDOUT.dup, STDERR.dup]
|
84
|
+
STDOUT.reopen DEV_NULL
|
85
|
+
STDERR.reopen DEV_NULL
|
86
|
+
block.call
|
87
|
+
ensure
|
88
|
+
STDOUT.reopen io.first
|
89
|
+
STDERR.reopen io.last
|
90
|
+
end
|
91
|
+
|
92
|
+
DIFF = if WIN32 then 'diff.exe'
|
93
|
+
else
|
94
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
95
|
+
else 'diff' end
|
96
|
+
end unless defined? DIFF
|
97
|
+
|
98
|
+
SUDO = if WIN32 then ''
|
99
|
+
else
|
100
|
+
if quiet {system 'which sudo'} then 'sudo'
|
101
|
+
else '' end
|
102
|
+
end
|
103
|
+
|
104
|
+
RCOV = WIN32 ? 'rcov.cmd' : 'rcov'
|
105
|
+
GEM = WIN32 ? 'gem.cmd' : 'gem'
|
106
|
+
|
107
|
+
%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
|
108
|
+
begin
|
109
|
+
require lib
|
110
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
|
111
|
+
rescue LoadError
|
112
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
117
|
+
# specified.
|
118
|
+
#
|
119
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
120
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
121
|
+
#
|
122
|
+
def paragraphs_of( path, *paragraphs )
|
123
|
+
title = String === paragraphs.first ? paragraphs.shift : nil
|
124
|
+
ary = File.read(path).delete("\r").split(/\n\n+/)
|
125
|
+
|
126
|
+
result = if title
|
127
|
+
tmp, matching = [], false
|
128
|
+
rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
|
129
|
+
paragraphs << (0..-1) if paragraphs.empty?
|
130
|
+
|
131
|
+
ary.each do |val|
|
132
|
+
if val =~ rgxp
|
133
|
+
break if matching
|
134
|
+
matching = true
|
135
|
+
rgxp = %r/^=+/i
|
136
|
+
elsif matching
|
137
|
+
tmp << val
|
138
|
+
end
|
139
|
+
end
|
140
|
+
tmp
|
141
|
+
else ary end
|
142
|
+
|
143
|
+
result.values_at(*paragraphs)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
147
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
148
|
+
# will be used.
|
149
|
+
#
|
150
|
+
def depend_on( name, version = nil )
|
151
|
+
spec = Gem.source_index.find_name(name).last
|
152
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
153
|
+
|
154
|
+
PROJ.dependencies << (version.nil? ? [name] : [name, ">= #{version}"])
|
155
|
+
end
|
156
|
+
|
157
|
+
# Adds the given arguments to the include path if they are not already there
|
158
|
+
#
|
159
|
+
def ensure_in_path( *args )
|
160
|
+
args.each do |path|
|
161
|
+
path = File.expand_path(path)
|
162
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Find a rake task using the task name and remove any description text. This
|
167
|
+
# will prevent the task from being displayed in the list of available tasks.
|
168
|
+
#
|
169
|
+
def remove_desc_for_task( names )
|
170
|
+
Array(names).each do |task_name|
|
171
|
+
task = Rake.application.tasks.find {|t| t.name == task_name}
|
172
|
+
next if task.nil?
|
173
|
+
task.instance_variable_set :@comment, nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Change working directories to _dir_, call the _block_ of code, and then
|
178
|
+
# change back to the original working directory (the current directory when
|
179
|
+
# this method was called).
|
180
|
+
#
|
181
|
+
def in_directory( dir, &block )
|
182
|
+
curdir = pwd
|
183
|
+
begin
|
184
|
+
cd dir
|
185
|
+
return block.call
|
186
|
+
ensure
|
187
|
+
cd curdir
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# EOF
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SPEC_RAKE_SPECTASK
|
4
|
+
|
5
|
+
namespace :spec do
|
6
|
+
|
7
|
+
desc 'Run all specs with basic output'
|
8
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
9
|
+
t.spec_opts = PROJ.spec_opts
|
10
|
+
t.spec_files = PROJ.specs
|
11
|
+
t.libs += PROJ.libs
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Run all specs with text output'
|
15
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
16
|
+
t.spec_opts = PROJ.spec_opts + ['--format', 'specdoc']
|
17
|
+
t.spec_files = PROJ.specs
|
18
|
+
t.libs += PROJ.libs
|
19
|
+
end
|
20
|
+
|
21
|
+
if HAVE_RCOV
|
22
|
+
desc 'Run all specs with RCov'
|
23
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
24
|
+
t.spec_opts = PROJ.spec_opts
|
25
|
+
t.spec_files = PROJ.specs
|
26
|
+
t.libs += PROJ.libs
|
27
|
+
t.rcov = true
|
28
|
+
t.rcov_opts = PROJ.rcov_opts + ['--exclude', 'spec']
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end # namespace :spec
|
33
|
+
|
34
|
+
desc 'Alias to spec:run'
|
35
|
+
task :spec => 'spec:run'
|
36
|
+
|
37
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
38
|
+
|
39
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
40
|
+
|
41
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
42
|
+
|
43
|
+
# EOF
|
data/tasks/svn.rake
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
|
4
|
+
if PROJ.svn and system("svn --version 2>&1 > #{DEV_NULL}")
|
5
|
+
|
6
|
+
unless PROJ.svn_root
|
7
|
+
info = %x/svn info ./
|
8
|
+
m = %r/^Repository Root:\s+(.*)$/.match(info)
|
9
|
+
PROJ.svn_root = (m.nil? ? '' : m[1])
|
10
|
+
end
|
11
|
+
PROJ.svn_root = File.join(PROJ.svn_root, PROJ.svn) if String === PROJ.svn
|
12
|
+
|
13
|
+
namespace :svn do
|
14
|
+
|
15
|
+
desc 'Show tags from the SVN repository'
|
16
|
+
task :show_tags do |t|
|
17
|
+
tags = %x/svn list #{File.join(PROJ.svn_root, PROJ.svn_tags)}/
|
18
|
+
tags.gsub!(%r/\/$/, '')
|
19
|
+
puts tags
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Create a new tag in the SVN repository'
|
23
|
+
task :create_tag do |t|
|
24
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
25
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
26
|
+
|
27
|
+
trunk = File.join(PROJ.svn_root, PROJ.svn_trunk)
|
28
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
29
|
+
tag = File.join(PROJ.svn_root, PROJ.svn_tags, tag)
|
30
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
31
|
+
|
32
|
+
puts "Creating SVN tag '#{tag}'"
|
33
|
+
unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
|
34
|
+
abort "Tag creation failed"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end # namespace :svn
|
39
|
+
|
40
|
+
task 'gem:release' => 'svn:create_tag'
|
41
|
+
|
42
|
+
end # if PROJ.svn
|
43
|
+
|
44
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
10
|
+
else PROJ.tests end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test_opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov_opts.join(' ')
|
19
|
+
files = if test ?f, PROJ.test_file then [PROJ.test_file]
|
20
|
+
else PROJ.tests end
|
21
|
+
files = files.join(' ')
|
22
|
+
sh "#{RCOV} #{files} #{opts}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Remove rcov products'
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
remove_desc_for_task %w(test:clobber_rcov)
|
39
|
+
|
40
|
+
# EOF
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
STUB_NETWORK = true
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), %w[test_helper])
|
6
|
+
require 'test/unit'
|
7
|
+
require 'mocha'
|
8
|
+
|
9
|
+
class TestClient < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
api_key = 'http://www.myspace.com/appname'
|
13
|
+
secret_key = 'secretkey'
|
14
|
+
@myspace = Spacer::Client.new(api_key, secret_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_get_user_info
|
18
|
+
stubbing_http_response_with example_user_response_json do
|
19
|
+
user = @myspace.user('107265345')
|
20
|
+
assert_equal "BrownPunk!", user.name
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_get_profile
|
25
|
+
stubbing_http_response_with example_profile_response_json do
|
26
|
+
profile = @myspace.profile('107265345')
|
27
|
+
assert_equal "CHICAGO", profile.city
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_get_friends
|
32
|
+
stubbing_http_response_with example_friends_response_json do
|
33
|
+
friends = @myspace.friends('107265345')
|
34
|
+
assert_equal 2, friends.size
|
35
|
+
assert_equal 'Tom', friends.first.name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_get_albums
|
40
|
+
stubbing_http_response_with example_albums_response_json do
|
41
|
+
albums = @myspace.albums('107265345')
|
42
|
+
assert_equal 1, albums.size
|
43
|
+
assert_equal 'My Photos', albums.first.title
|
44
|
+
assert_equal 1580520, albums.first.id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_get_album_by_id
|
49
|
+
stubbing_http_response_with example_album_by_id_response_json do
|
50
|
+
album = @myspace.album('107265345', 1580520)
|
51
|
+
assert_equal 'My Photos', album.title
|
52
|
+
assert_equal 1580520, album.id
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_photos_by_album_id
|
57
|
+
stubbing_http_response_with example_photos_for_album_response_json do
|
58
|
+
photos = @myspace.photos_for_album('107265345', 1580520)
|
59
|
+
assert_equal '', photos.first.caption
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_get_photos
|
64
|
+
stubbing_http_response_with example_photos_response_json do
|
65
|
+
photos = @myspace.photos(107265345)
|
66
|
+
assert_equal '', photos.first.caption
|
67
|
+
assert_equal 19071328, photos.first.id
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_get_interests
|
72
|
+
stubbing_http_response_with example_interests_response_json do
|
73
|
+
interests = @myspace.interests(107265345)
|
74
|
+
assert_equal 'Stewart Copeland', interests.heroes
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_get_details
|
79
|
+
stubbing_http_response_with example_details_response_json do
|
80
|
+
details = @myspace.details(107265345)
|
81
|
+
assert_equal 'Single', details.status # <--- see ladies!!!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_get_videos
|
86
|
+
stubbing_http_response_with example_videos_response_json do
|
87
|
+
videos = @myspace.videos(107265345)
|
88
|
+
assert_equal 'Keechu', videos.first.title
|
89
|
+
assert_equal 27953679, videos.first.id
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_get_videos
|
94
|
+
stubbing_http_response_with example_video_response_json do
|
95
|
+
video = @myspace.video(107265345, 27953679)
|
96
|
+
assert_equal 'Keechu', video.title
|
97
|
+
assert_equal 27953679, video.id
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_get_photo
|
102
|
+
stubbing_http_response_with example_photo_response_json do
|
103
|
+
photo = @myspace.photo(107265345, 19071328)
|
104
|
+
assert_equal 'hi mom', photo.caption
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_get_status
|
109
|
+
stubbing_http_response_with example_status_response_json do
|
110
|
+
status = @myspace.status(107265345)
|
111
|
+
assert_equal 'none', status.status
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_get_mood
|
116
|
+
stubbing_http_response_with example_mood_response_json do
|
117
|
+
mood = @myspace.mood(107265345)
|
118
|
+
assert_equal 'none', mood.mood
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_get_friendship_for_one_person
|
123
|
+
stubbing_http_response_with example_friendship_response_for_one_friend_json do
|
124
|
+
friendship = @myspace.friendship?(107265345, 107265345)
|
125
|
+
assert_equal true, friendship
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_get_friendship_for_multiple_people
|
130
|
+
stubbing_http_response_with example_friendship_response_for_multiple_friends_json do
|
131
|
+
friendships = @myspace.friendship?(107265345, [107265345, 107265346])
|
132
|
+
assert_equal true, friendships.first
|
133
|
+
assert_equal false, friendships.last
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_get_groups
|
138
|
+
stubbing_http_response_with example_groups_response_json do
|
139
|
+
groups = @myspace.groups(107265345)
|
140
|
+
assert_equal 'Tom Morello etc.', groups.first.groupName
|
141
|
+
assert_equal 'XOC', groups.last.groupName
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|