dribble 0.1.0 → 0.1.1
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/LICENSE +1 -1
- data/README.rdoc +89 -12
- data/Rakefile +8 -5
- data/VERSION +1 -1
- data/dribble.gemspec +28 -14
- data/examples/barebones/player.rb +10 -10
- data/examples/barebones/shot.rb +12 -12
- data/examples/player.rb +15 -15
- data/lib/dribble/request.rb +24 -7
- data/lib/dribble.rb +2 -3
- data/spec/core_ext/hash_spec.rb +94 -0
- data/spec/core_ext/object_spec.rb +44 -0
- data/spec/dribble/api/player_spec.rb +200 -0
- data/spec/dribble/api/shot_spec.rb +184 -0
- data/spec/dribble/version_spec.rb +19 -0
- data/spec/fake_data/player/player_draftees.json +1 -0
- data/spec/fake_data/player/player_find_shots.json +1 -0
- data/spec/fake_data/player/player_followers.json +1 -0
- data/spec/fake_data/player/player_following_shots.json +1 -0
- data/spec/fake_data/player/player_profile.json +1 -0
- data/spec/fake_data/shot/shot_debuts.json +1 -0
- data/spec/fake_data/shot/shot_everyones.json +1 -0
- data/spec/fake_data/shot/shot_for.json +1 -0
- data/spec/fake_data/shot/shot_popular.json +1 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fake_eventmachine_requests.rb +43 -0
- metadata +32 -18
- data/spec/dribble/core_ext/hash_spec.rb +0 -56
- data/spec/dribble/core_ext/object_spec.rb +0 -19
- data/spec/rcov.opts +0 -4
- data/spec/support/fakeweb_yajl.rb +0 -17
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010 Robert R Evans - The name '
|
1
|
+
Copyright (c) 2010 Robert R Evans - The name 'Dribbble' is owned by its respective owners.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.rdoc
CHANGED
@@ -1,26 +1,103 @@
|
|
1
1
|
= Dribble
|
2
2
|
|
3
|
-
This is the unofficial
|
3
|
+
This is the unofficial dribbble api. For more examples look in the examples/ directory. There are examples for the both styles (object notation and hash implementation.)
|
4
4
|
|
5
5
|
== Dribble::API
|
6
6
|
|
7
|
-
There is a very thin wrapper for the Dribble API that is
|
7
|
+
There is a very thin wrapper for the Dribble API that is called Dribble::API. This uses the bare minimum to get the desired data from Dribbble and returns a hash. This implementation is focused on simplicity and speed. However, I have yet to really work on the speed aspect.
|
8
8
|
|
9
|
-
Dribble::API::Player.profile('simplebits')
|
10
|
-
Dribble::API::Shot.popular
|
11
9
|
|
10
|
+
=== Dribble::API::Player
|
12
11
|
|
13
|
-
|
12
|
+
Dribble::API::Player.find_shots('simplebits') # => Finds all the shots by simplebits
|
14
13
|
|
15
|
-
Dribble::Player
|
14
|
+
Dribble::API::Player.profile('simplebits') # => Gets simplebits' profile
|
16
15
|
|
17
|
-
|
16
|
+
Dribble::API::Player.following_shots('simplebits') # => Gets the shots that simplebits is following
|
17
|
+
|
18
|
+
Dribble::API::Player.followers('simplebits') # => gets simplebits' followers
|
19
|
+
|
20
|
+
Dribble::API::Player.draftees('simplebits') # => gets simplebits' draftees
|
21
|
+
|
22
|
+
Each of the above (except the profile request) accepts a second parameter, a hash of options. This hash can consist of the following:
|
23
|
+
|
24
|
+
{:per_page => 30, :page => 1}
|
25
|
+
|
26
|
+
You can control the pagination yourself by doing the following:
|
27
|
+
|
28
|
+
Dribble::API::Player.followers('simplebits', {:per_page => 25, :page => 3})
|
29
|
+
|
30
|
+
30 is the max amount you can request per page. It is also the default set within this API implementation. Page 1 is the default page.
|
31
|
+
|
32
|
+
=== Dribble::API::Shot
|
33
|
+
|
34
|
+
|
35
|
+
Dribble::API::Shot.for(1) # => gets the shots for the user with the id of 1
|
36
|
+
|
37
|
+
Dribble::API::Shot.everyones # => Gets everyones shots
|
38
|
+
|
39
|
+
Dribble::API::Shot.debuts # => gets the debut shots
|
40
|
+
|
41
|
+
Dribble::API::Shot.popular # => gets the popular shots
|
42
|
+
|
43
|
+
Each of the above (except the profile request) accepts a second parameter, a hash of options. This hash can consist of the following:
|
44
|
+
|
45
|
+
{:per_page => 30, :page => 1}
|
46
|
+
|
47
|
+
You can control the pagination yourself by doing the following:
|
48
|
+
|
49
|
+
Dribble::API::Shot.popular({:per_page => 25, :page => 3})
|
50
|
+
|
51
|
+
30 is the max amount you can request per page. It is also the default set within this API implementation. Page 1 is the default page.
|
52
|
+
|
53
|
+
=== Options Defaults
|
54
|
+
|
55
|
+
* Per page : 30
|
56
|
+
* Page : 1
|
57
|
+
|
58
|
+
== A convenience layer
|
59
|
+
|
60
|
+
This is another layer of the API wrapper that sits on top of the Dribble::API to give an easier working interface.
|
61
|
+
|
62
|
+
=== Dribble::Player
|
63
|
+
|
64
|
+
@player = Dribble::Player.profile('simplebits')
|
65
|
+
@player.id # => 1
|
66
|
+
@player.name # => Dan Cederholm
|
67
|
+
@player.url # => http://dribbble.com/players/simplebits
|
68
|
+
@player.avatar_url # => http://dribbble.com/system/users/1/avatars/thumb/dancederholm-peek.jpg?1261060245
|
69
|
+
@player.location # => Salem, MA
|
70
|
+
@player.created_at # => 2009/07/07 21:51:22 -0400
|
71
|
+
@player.draftees_count # => 103
|
72
|
+
@player.following_count # => 378
|
73
|
+
@player.shots_count # => 148
|
74
|
+
@player.followers_count # => 2129
|
75
|
+
@player.following # => [] This makes a request to dribbble to get the shots that this user is following
|
76
|
+
@player.shots # => [] This makes a request to dribbble to get the shots that this user has put up
|
77
|
+
@player.drafted_by_palyer_id # => nil
|
18
78
|
|
19
|
-
Dribble::Shot.popular
|
20
79
|
|
21
|
-
|
22
|
-
|
23
|
-
|
80
|
+
More documentation coming soon.
|
81
|
+
|
82
|
+
=== Dribble::Shot
|
83
|
+
|
84
|
+
@shot = Dribble::Shot.for(1)
|
85
|
+
@shot.id # => 1
|
86
|
+
@shot.title # => Working on the new shop
|
87
|
+
@shot.url # => http://dribbble.com/shots/1-Working-on-the-new-shop
|
88
|
+
@shot.image_url # => http://dribbble.com/system/users/1/screenshots/1/Picture-2.png
|
89
|
+
@shot.image_teaser_url # => http://dribbble.com/system/users/1/screenshots/1/Picture-2_teaser.png
|
90
|
+
@shot.width # => 400
|
91
|
+
@shot.height # => 300
|
92
|
+
@shot.created_at # => 2009/07/08 06:08:35 -0400
|
93
|
+
@shot.player # => Dribble::Player Object (e.g. @shot.player.name, @shot.player.url, @shot.player.location)
|
94
|
+
@shot.views_count # => 838
|
95
|
+
@shot.likes_count # => 8
|
96
|
+
@shot.comments_count # => 3
|
97
|
+
@shot.rebounds_count # => 0
|
98
|
+
|
99
|
+
|
100
|
+
More documentation coming soon.
|
24
101
|
|
25
102
|
== Note on Patches/Pull Requests
|
26
103
|
|
@@ -34,6 +111,6 @@ This is meant for convenience and ease of use.
|
|
34
111
|
|
35
112
|
== Copyright
|
36
113
|
|
37
|
-
The name "
|
114
|
+
The name "Dribbble" belongs to http://www.dribbble.com
|
38
115
|
|
39
116
|
Copyright (c) 2010 Robert R Evans. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -5,15 +5,16 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "dribble"
|
8
|
-
gem.summary = %Q{API Wrapper for the awesome
|
9
|
-
gem.description = %Q{API Wrapper for the awesome
|
8
|
+
gem.summary = %Q{API Wrapper for the awesome Dribbble Site}
|
9
|
+
gem.description = %Q{API Wrapper for the awesome Dribbble Site}
|
10
10
|
gem.email = "robert@codewranglers.org"
|
11
11
|
gem.homepage = "http://github.com/revans/dribble"
|
12
12
|
gem.authors = ["Robert R Evans"]
|
13
|
-
gem.add_development_dependency "rspec", "= 1.3.0"
|
14
|
-
gem.add_development_dependency "yard", "= 0.5.8"
|
15
13
|
|
16
|
-
gem.
|
14
|
+
gem.add_development_dependency "rspec", '= 1.3.0'
|
15
|
+
gem.add_development_dependency "yard", '= 0.5.8'
|
16
|
+
|
17
|
+
gem.add_dependency 'em-http-request', '= 0.2.10'
|
17
18
|
|
18
19
|
end
|
19
20
|
Jeweler::GemcutterTasks.new
|
@@ -21,6 +22,7 @@ rescue LoadError
|
|
21
22
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
23
|
end
|
23
24
|
|
25
|
+
|
24
26
|
require 'spec/rake/spectask'
|
25
27
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
28
|
spec.libs << 'lib' << 'spec'
|
@@ -30,6 +32,7 @@ end
|
|
30
32
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
33
|
spec.libs << 'lib' << 'spec'
|
32
34
|
spec.pattern = 'spec/**/*_spec.rb'
|
35
|
+
spec.rcov_opts = ['--exclude', '^spec,/gems/,/Library/']
|
33
36
|
spec.rcov = true
|
34
37
|
end
|
35
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dribble.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dribble}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Robert R Evans"]
|
12
|
-
s.date = %q{2010-08-
|
13
|
-
s.description = %q{API Wrapper for the awesome
|
12
|
+
s.date = %q{2010-08-13}
|
13
|
+
s.description = %q{API Wrapper for the awesome Dribbble Site}
|
14
14
|
s.email = %q{robert@codewranglers.org}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
@@ -40,23 +40,37 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/dribble/shot.rb",
|
41
41
|
"lib/dribble/shots.rb",
|
42
42
|
"lib/dribble/version.rb",
|
43
|
-
"spec/
|
44
|
-
"spec/
|
45
|
-
"spec/
|
43
|
+
"spec/core_ext/hash_spec.rb",
|
44
|
+
"spec/core_ext/object_spec.rb",
|
45
|
+
"spec/dribble/api/player_spec.rb",
|
46
|
+
"spec/dribble/api/shot_spec.rb",
|
47
|
+
"spec/dribble/version_spec.rb",
|
48
|
+
"spec/fake_data/player/player_draftees.json",
|
49
|
+
"spec/fake_data/player/player_find_shots.json",
|
50
|
+
"spec/fake_data/player/player_followers.json",
|
51
|
+
"spec/fake_data/player/player_following_shots.json",
|
52
|
+
"spec/fake_data/player/player_profile.json",
|
53
|
+
"spec/fake_data/shot/shot_debuts.json",
|
54
|
+
"spec/fake_data/shot/shot_everyones.json",
|
55
|
+
"spec/fake_data/shot/shot_for.json",
|
56
|
+
"spec/fake_data/shot/shot_popular.json",
|
46
57
|
"spec/spec.opts",
|
47
58
|
"spec/spec_helper.rb",
|
48
|
-
"spec/support/
|
59
|
+
"spec/support/fake_eventmachine_requests.rb"
|
49
60
|
]
|
50
61
|
s.homepage = %q{http://github.com/revans/dribble}
|
51
62
|
s.rdoc_options = ["--charset=UTF-8"]
|
52
63
|
s.require_paths = ["lib"]
|
53
64
|
s.rubygems_version = %q{1.3.7}
|
54
|
-
s.summary = %q{API Wrapper for the awesome
|
65
|
+
s.summary = %q{API Wrapper for the awesome Dribbble Site}
|
55
66
|
s.test_files = [
|
56
|
-
"spec/
|
57
|
-
"spec/
|
67
|
+
"spec/core_ext/hash_spec.rb",
|
68
|
+
"spec/core_ext/object_spec.rb",
|
69
|
+
"spec/dribble/api/player_spec.rb",
|
70
|
+
"spec/dribble/api/shot_spec.rb",
|
71
|
+
"spec/dribble/version_spec.rb",
|
58
72
|
"spec/spec_helper.rb",
|
59
|
-
"spec/support/
|
73
|
+
"spec/support/fake_eventmachine_requests.rb",
|
60
74
|
"examples/barebones/player.rb",
|
61
75
|
"examples/barebones/shot.rb",
|
62
76
|
"examples/player.rb",
|
@@ -70,16 +84,16 @@ Gem::Specification.new do |s|
|
|
70
84
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
71
85
|
s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
|
72
86
|
s.add_development_dependency(%q<yard>, ["= 0.5.8"])
|
73
|
-
s.add_runtime_dependency(%q<
|
87
|
+
s.add_runtime_dependency(%q<em-http-request>, ["= 0.2.10"])
|
74
88
|
else
|
75
89
|
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
76
90
|
s.add_dependency(%q<yard>, ["= 0.5.8"])
|
77
|
-
s.add_dependency(%q<
|
91
|
+
s.add_dependency(%q<em-http-request>, ["= 0.2.10"])
|
78
92
|
end
|
79
93
|
else
|
80
94
|
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
81
95
|
s.add_dependency(%q<yard>, ["= 0.5.8"])
|
82
|
-
s.add_dependency(%q<
|
96
|
+
s.add_dependency(%q<em-http-request>, ["= 0.2.10"])
|
83
97
|
end
|
84
98
|
end
|
85
99
|
|
@@ -2,25 +2,25 @@ dir = File.expand_path(File.join(File.dirname(__FILE__), '../..', 'lib'))
|
|
2
2
|
require File.join(dir, 'dribble')
|
3
3
|
|
4
4
|
# puts "Find Player's Shots by name"
|
5
|
-
# puts Dribble::API::Player.
|
5
|
+
# puts Dribble::API::Player.find_shots('simplebits').inspect
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
puts
|
8
|
+
puts "Find Player's Profile"
|
9
|
+
player = Dribble::API::Player.profile('simplebits')
|
10
|
+
puts player.inspect
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
puts
|
13
|
+
puts "Find all the shots a player is following"
|
14
|
+
puts Dribble::API::Player.following_shots('simplebits')
|
15
15
|
|
16
16
|
|
17
17
|
puts
|
18
18
|
puts "Find Player's Followers"
|
19
19
|
player = Dribble::API::Player.followers('simplebits')
|
20
|
-
puts player
|
20
|
+
puts player
|
21
21
|
|
22
22
|
|
23
23
|
puts
|
24
24
|
puts "Find Player's Draftees"
|
25
25
|
player = Dribble::API::Player.draftees('simplebits')
|
26
|
-
puts player
|
26
|
+
puts player
|
data/examples/barebones/shot.rb
CHANGED
@@ -3,19 +3,19 @@ require File.join(dir, 'dribble')
|
|
3
3
|
|
4
4
|
# puts "Find a specific shot by ID"
|
5
5
|
# shot = Dribble::API::Shot.for(1)
|
6
|
-
# puts shot
|
7
|
-
|
6
|
+
# puts shot
|
7
|
+
#
|
8
8
|
# puts
|
9
9
|
# puts "Everyone's shots"
|
10
|
-
# puts Dribble::API::Shot.everyones
|
11
|
-
|
12
|
-
|
10
|
+
# puts Dribble::API::Shot.everyones
|
11
|
+
#
|
12
|
+
#
|
13
13
|
# puts
|
14
14
|
# puts "Debut shots"
|
15
|
-
# puts Dribble::API::Shot.debuts
|
16
|
-
|
17
|
-
|
18
|
-
puts
|
19
|
-
puts "Popular shots"
|
20
|
-
popular = Dribble::API::Shot.popular
|
21
|
-
puts popular
|
15
|
+
# puts Dribble::API::Shot.debuts
|
16
|
+
#
|
17
|
+
#
|
18
|
+
# puts
|
19
|
+
# puts "Popular shots"
|
20
|
+
# popular = Dribble::API::Shot.popular
|
21
|
+
# puts popular
|
data/examples/player.rb
CHANGED
@@ -6,10 +6,10 @@ require File.join(dir, 'dribble')
|
|
6
6
|
# puts player.inspect
|
7
7
|
#
|
8
8
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
puts
|
10
|
+
puts "Find Player's Profile"
|
11
|
+
player2 = Dribble::Player.profile('simplebits') # OR Dribble::Player.find('simplebits')
|
12
|
+
puts player2.inspect
|
13
13
|
|
14
14
|
|
15
15
|
# puts
|
@@ -17,17 +17,17 @@ require File.join(dir, 'dribble')
|
|
17
17
|
# player3 = Dribble::Player.following_shots('simplebits')
|
18
18
|
# puts player3.inspect
|
19
19
|
|
20
|
-
|
21
|
-
puts
|
22
|
-
puts "Find a players followers"
|
23
|
-
player4 = Dribble::Player.followers('simplebits')
|
24
|
-
puts player4.inspect
|
25
|
-
|
26
|
-
|
27
|
-
puts
|
28
|
-
puts "Find a players draftees"
|
29
|
-
player5 = Dribble::Player.draftees('simplebits')
|
30
|
-
puts player5.inspect
|
20
|
+
#
|
21
|
+
# puts
|
22
|
+
# puts "Find a players followers"
|
23
|
+
# player4 = Dribble::Player.followers('simplebits')
|
24
|
+
# puts player4.inspect
|
25
|
+
#
|
26
|
+
#
|
27
|
+
# puts
|
28
|
+
# puts "Find a players draftees"
|
29
|
+
# player5 = Dribble::Player.draftees('simplebits')
|
30
|
+
# puts player5.inspect
|
31
31
|
|
32
32
|
|
33
33
|
|
data/lib/dribble/request.rb
CHANGED
@@ -3,14 +3,31 @@ module Dribble
|
|
3
3
|
class << self
|
4
4
|
DRIBBLE_API = 'api.dribbble.com'
|
5
5
|
|
6
|
+
|
7
|
+
##
|
8
|
+
# Get
|
9
|
+
#
|
10
|
+
# @param [String, Hash]
|
11
|
+
# @return [Array/Hash]
|
12
|
+
# @api private
|
13
|
+
#
|
6
14
|
def get(query, options={})
|
7
|
-
meth
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
meth = options.delete(:api_endpoint)
|
16
|
+
::EventMachine.run do
|
17
|
+
http = ::EventMachine::HttpRequest.new("#{to_url}#{query}").get(:query => options, :timeout => 10)
|
18
|
+
http.callback do
|
19
|
+
@response = {
|
20
|
+
:status => http.response_header.status,
|
21
|
+
:header => http.response_header,
|
22
|
+
:body => http.response,
|
23
|
+
:data => ::Yajl::Parser.new(:symbolize_keys => true).parse(http.response)
|
24
|
+
}
|
25
|
+
::EventMachine.stop
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@response[:data][:api_endpoint] = meth if meth
|
29
|
+
@response[:data]
|
30
|
+
end
|
14
31
|
|
15
32
|
|
16
33
|
private
|
data/lib/dribble.rb
CHANGED
@@ -3,9 +3,8 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
|
-
require '
|
7
|
-
require 'yajl
|
8
|
-
require 'yajl/http_stream'
|
6
|
+
require 'em-http-request'
|
7
|
+
require 'yajl'
|
9
8
|
|
10
9
|
base = File.expand_path(File.dirname(__FILE__))
|
11
10
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
describe "To Query" do
|
6
|
+
before(:all) do
|
7
|
+
@query_hash = {:name => 'hilton', :postal => '92009'}
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create a standard query string" do
|
11
|
+
@query_hash.to_query.should == 'name=hilton&postal=92009'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create an encoded query string with a namespace" do
|
15
|
+
@query_hash.to_query('property').should == 'property%5Bname%5D=hilton&property%5Bpostal%5D=92009'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Symbolizing Keys" do
|
20
|
+
before(:all) do
|
21
|
+
@stringified_keys = {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
22
|
+
@recursive = {'name' => 'Hilton', 'address' => {'street' => '1200 Ave.', 'postal' => '92011', 'directions' => {'from' => 'here', 'to' => 'there', 'dive_in' => {'name' => 'something'}}}}
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create a new hash, keeping the old" do
|
26
|
+
a = @stringified_keys.symbolize_keys
|
27
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
28
|
+
@stringified_keys.should == {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should overwrite the existing hash making the keys symbols" do
|
32
|
+
a = @stringified_keys.symbolize_keys!
|
33
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
34
|
+
@stringified_keys.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should overwrite and recursively make all keys symbols" do
|
38
|
+
a = @recursive.recursive_symbolize_keys!
|
39
|
+
a.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
40
|
+
@recursive.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "Symbolizing Keys" do
|
45
|
+
before(:all) do
|
46
|
+
@stringified_keys = {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
47
|
+
@recursive = {'name' => 'Hilton', 'address' => {'street' => '1200 Ave.', 'postal' => '92011', 'directions' => {'from' => 'here', 'to' => 'there', 'dive_in' => {'name' => 'something'}}}}
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should create a new hash, keeping the old" do
|
51
|
+
a = @stringified_keys.symbolize_keys
|
52
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
53
|
+
@stringified_keys.should == {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should overwrite the existing hash making the keys symbols" do
|
57
|
+
a = @stringified_keys.symbolize_keys!
|
58
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
59
|
+
@stringified_keys.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should overwrite and recursively make all keys symbols" do
|
63
|
+
a = @recursive.recursive_symbolize_keys!
|
64
|
+
a.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
65
|
+
@recursive.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "Symbolizing Keys" do
|
70
|
+
before(:all) do
|
71
|
+
@stringified_keys = {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
72
|
+
@recursive = {'name' => 'Hilton', 'address' => {'street' => '1200 Ave.', 'postal' => '92011', 'directions' => {'from' => 'here', 'to' => 'there', 'dive_in' => {'name' => 'something'}}}}
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should create a new hash, keeping the old" do
|
76
|
+
a = @stringified_keys.symbolize_keys
|
77
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
78
|
+
@stringified_keys.should == {'name' => 'Hilton', 'address' => '1200 Ave.', 'postal' => '92011'}
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should overwrite the existing hash making the keys symbols" do
|
82
|
+
a = @stringified_keys.symbolize_keys!
|
83
|
+
a.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
84
|
+
@stringified_keys.should == {:name => 'Hilton', :address => '1200 Ave.', :postal => '92011'}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should overwrite and recursively make all keys symbols" do
|
88
|
+
a = @recursive.recursive_symbolize_keys!
|
89
|
+
a.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
90
|
+
@recursive.should == {:name => 'Hilton', :address => {:street => '1200 Ave.', :postal => '92011', :directions => {:from => 'here', :to => 'there', :dive_in => {:name => 'something'}}}}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
before(:all) do
|
5
|
+
@string = ''
|
6
|
+
@fixnum = 1
|
7
|
+
@float = 1.1
|
8
|
+
@hash = {}
|
9
|
+
@array = []
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should return true when testing if an empty string is blank" do
|
13
|
+
@string.blank?.should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return false when testing a fixnum for blank" do
|
17
|
+
@fixnum.blank?.should be_false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return false when testing a float for blank" do
|
21
|
+
@float.blank?.should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return true when testing if a hash is blank" do
|
25
|
+
@hash.blank?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true when testing if an array is blank" do
|
29
|
+
@array.blank?.should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return true when testing if nil is blank" do
|
33
|
+
nil.blank?.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return false when testing if true is blank" do
|
37
|
+
true.blank?.should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return false when testing if false is blank" do
|
41
|
+
false.blank?.should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|