16. #!/usr/bin/env ruby -wKU
require "open-uri"
OPENURI
open(__FILE__) do |f|
p f.gets
# >> "#!/usr/bin/env ruby -wKUn"
end
The Web as just another IO open("http://blog.grayproductions.net") do |u|
p u.gets
# >> "<!DOCTYPE HTML PUBLIC …"
p u.content_type
# >> "text/html"
end
39. !!! DEPRECATION WARNING !!!
Hey Champ! I see you're using Ruby 1.8.6! While I applaud you for sticking to
your guns and using The One True Ruby, I have to let you know that we're going
FOG
to stop supporting 1.8.6. I know, it's sad. But, we just don't have time to
support every version of Ruby out there. Whether we like it or not, time moves
forward and so does our software.
On August 1, 2010, we will no longer support Ruby 1.8.6. If nokogiri happens to
Warnings galore work on 1.8.6 after that date, then great! We will hownever, no longer test,
use, or endorse 1.8.6 as a supported platform.
Thanks,
Team Nokogiri
40. (eval):1: warning: method redefined; discarding old reject
(eval):1: warning: method redefined; discarding old select
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/collection.rb:40: warning:
method redefined; discarding old clear
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/collection.rb:55: warning:
method redefined; discarding old inspect
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws.rb:95: warning: redefine
image_id
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/terremark/parser.rb:6:
warning: method redefined; discarding old parse
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/s3.rb:7: warning:
instance variable @required not initialized
FOG
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/models/s3/file.rb:20:
warning: method redefined; discarding old body
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/models/s3/file.rb:53:
warning: method redefined; discarding old owner=
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/models/s3/files.rb:80:
warning: method redefined; discarding old directory=
Warnings galore /usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/parsers/s3/
get_bucket_logging.rb:8: warning: method redefined; discarding old reset
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog/aws/parsers/s3/
get_bucket_logging.rb:13: warning: method redefined; discarding old end_element
/usr/local/lib/ruby/gems/1.8/gems/fog-0.1.8/lib/fog.rb:77: warning: instance
variable @mocking not initialized
/usr/local/lib/ruby/gems/1.8/gems/excon-0.0.26/lib/excon/connection.rb:90:
warning: using default DH parameters.
<Fog::AWS::S3::Directories
[
<Fog::AWS::S3::Directory
key="graysoftinc",
creation_date=Wed Jun 09 03:10:07 UTC 2010
>
]
>
41. PERL WHIPS
RUBY IN
ONE AREA
Perl programmers
use warnings!
42. PERL WHIPS
RUBY IN
ONE AREA
Perl programmers
use warnings!
44. #!/usr/bin/env ruby -wKU
FREE
class Name
def initialize(first, last)
@first = first
DEBUGGING @last = last
end
Who hates free bug finding? def full
"#{@firt} #{@last}".strip
end
end
name = Name.new("James", "Gray")
puts name.full
45. #!/usr/bin/env ruby -KU
class Name
def initialize(first, last)
@first = first
FREE @last = last
end
DEBUGGING def first
@firt
end
Who hates free bug finding? end
name = Name.new("James", "Gray")
Thread.new(name.first) do |first|
sleep 3
puts first.capitalize
end
sleep
46. LESS HOOPS
TO JUGGLE
In programming,
that’s always a win
47. LESS HOOPS
TO JUGGLE
In programming,
that’s always a win
49. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
50. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
51. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
52. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
53. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
54. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
55. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
56. RANDOM COMPARISONS
AWS Fog S3 AWS::S3
Not just no, Present,
Docs Good Good
but hell no! but weird
Works Not for me Yes Yes Yes
Streaming With pain Yes No Yes
Logs and
Features Logs Basics only Fancy logs
versions
Thread-safe Don’t do it! Yes No No
Warnings Yes Uh, yeah! Yes Yes, a lot
Command-
Extras No Shell No
line tool
57. DO WE HAVE A WINNER?
None of them feel ribbon worthy to me
58. DO WE HAVE A WINNER?
None of them feel ribbon worthy to me
63. #!/usr/bin/env ruby -wKU
require "rubygems"
THE
require "twitter"
oauth = Twitter::OAuth.new( "consumer token",
"consumer secret" )
TWITTER GEM
oauth.authorize_from_access( "access token",
"access secret" )
client = Twitter::Base.new(oauth)
client.friends_timeline.each do |tweet|
A typical object oriented API p tweet
end
client.user_timeline.each do |tweet|
p tweet
end
client.replies.each do |tweet|
p tweet
end
client.update("Heeeyyyyoooo from Twitter Gem!")
77. #!/usr/bin/env ruby -wKU
require "rubygems"
require "candy"
class Person
include Candy::Piece
end
me = Person.new
me.last_name = "Eley" # New record created and saved to Mongo
me.id # => ObjectID(4bb606f9609c8417cf00004b)
me[:height] = 67 # Or me.height = 67
me.favorites = { composer: "Yoko Kanno",
seafood: "Maryland blue crabs",
scotch: ["Glenmorangie Port Wood Finish",
"Balvenie Single Barrel"]}
me.spouse = Person.piece(first_name: "Anna", eyes: :blue)
me.spouse.eyes # => :blue
me.favorites.scotch[1] # => "Balvenie Single Barrel"
Person.last_name("Smith") # Returns the first Smith
Person.age(21) # Returns the first legal drinker (in the U.S.)
Person(12345) # Returns the person with an _id of 12345
CANDY
A very different approach
78. #!/usr/bin/env ruby -wKU
require "rubygems"
require "candy"
class People
include Candy::Collection
collects :person # Declares the Mongo collection is 'Person'
end # (and so is the Candy::Piece class)
People.last_name('Smith') # Returns an enumeration of all Smiths
People.age(19).sort(:birthdate, :down).limit(10) # We can chain options
People(limit: 47, occupation: :ronin) # Or People.all(params) or People.new(params)
People.each(|p| p.shout = 'Norm!') # Where everybody knows your name...
CANDY
A very different approach
82. THIS ENDS THE TOUR
• It’s
hard to know what’s
good or bad in an API
83. THIS ENDS THE TOUR
• It’s
hard to know what’s
good or bad in an API
• They definitely seem to have
a “feel” to them though
84. THIS ENDS THE TOUR
• It’s
hard to know what’s
good or bad in an API
• They definitely seem to have
a “feel” to them though
• Aim for the natural feel, if
you can find it