Permalink
Browse files

Add new Configuration class

  • Loading branch information...
1 parent aea645f commit 19bebb87cbee7bf4958b3c121619f66d4f828aea @sferik sferik committed Oct 14, 2011
View
35 README.md
@@ -32,23 +32,24 @@ wiki][apps]!
[ci]: http://travis-ci.org/jnunemaker/twitter
## <a name="2.0"></a>What new in version 2?
-This version introduces 15 new classes:
-
-1. `Twitter::Cursor`
-2. `Twitter::DirectMessage`
-3. `Twitter::Language`
-4. `Twitter::List`
-5. `Twitter::Photo`
-6. `Twitter::Place`
-7. `Twitter::Point`
-8. `Twitter::Polygon`
-9. `Twitter::RateLimitStatus`
-10. `Twitter::Relationship`
-11. `Twitter::SavedSearch`
-12. `Twitter::Settings`
-13. `Twitter::Size`
-14. `Twitter::Status`
-15. `Twitter::User`
+This version introduces 16 new classes:
+
+1. `Twitter::Configuration`
+2. `Twitter::Cursor`
+3. `Twitter::DirectMessage`
+4. `Twitter::Language`
+5. `Twitter::List`
+6. `Twitter::Photo`
+7. `Twitter::Place`
+8. `Twitter::Point`
+9. `Twitter::Polygon`
+10. `Twitter::RateLimitStatus`
+11. `Twitter::Relationship`
+12. `Twitter::SavedSearch`
+13. `Twitter::Settings`
+14. `Twitter::Size`
+15. `Twitter::Status`
+16. `Twitter::User`
These classes (plus Ruby primitives) have replaced all instances of
`Hashie::Mash`. This allows us to remove the gem's dependency on [hashie][] and
View
1 lib/twitter.rb
@@ -1,5 +1,6 @@
require 'twitter/client'
require 'twitter/config'
+require 'twitter/configuration'
require 'twitter/cursor'
require 'twitter/direct_message'
require 'twitter/language'
View
6 lib/twitter/client/help.rb
@@ -1,3 +1,4 @@
+require 'twitter/configuration'
require 'twitter/language'
module Twitter
@@ -9,11 +10,12 @@ module Help
# @see https://dev.twitter.com/docs/api/1/get/help/configuration
# @rate_limited Yes
# @requires_authentication No
- # @return [Hash] Twitter's configuration.
+ # @return [Twitter::Configuration] Twitter's configuration.
# @example Return the current configuration used by Twitter
# Twitter.configuration
def configuration(options={})
- get("/1/help/configuration.json", options)
+ configuration = get("/1/help/configuration.json", options)
+ Twitter::Configuration.new(configuration)
end
# Returns the list of languages supported by Twitter
View
23 lib/twitter/configuration.rb
@@ -0,0 +1,23 @@
+require 'active_support/core_ext/enumerable'
+require 'twitter/base'
+require 'twitter/size'
+
+module Twitter
+ class Configuration < Twitter::Base
+ attr_reader :characters_reserved_per_media, :max_media_per_upload,
+ :non_username_paths, :photo_size_limit, :photo_sizes, :short_url_length,
+ :short_url_length_https
+
+ def initialize(configuration={})
+ @characters_reserved_per_media = configuration['characters_reserved_per_media']
+ @max_media_per_upload = configuration['max_media_per_upload']
+ @non_username_paths = configuration['non_username_paths']
+ @photo_size_limit = configuration['photo_size_limit']
+ @photo_sizes = configuration['photo_sizes'].each_with_object({}) do |(key, value), object|
+ object[key] = Twitter::Size.new(value)
+ end unless configuration['photo_sizes'].nil?
+ @short_url_length = configuration['short_url_length']
+ @short_url_length_https = configuration['short_url_length_https']
+ end
+ end
+end
View
4 spec/twitter/client/help_spec.rb
@@ -20,8 +20,8 @@
it "should return Twitter's current configuration" do
configuration = @client.configuration
- configuration.should be_a Hash
- configuration['characters_reserved_per_media'].should == 20
+ configuration.should be_a Twitter::Configuration
+ configuration.characters_reserved_per_media.should == 20
end
end
View
20 spec/twitter/configuration_spec.rb
@@ -0,0 +1,20 @@
+require 'helper'
+
+describe Twitter::Configuration do
+
+ describe "#photo_sizes" do
+
+ it "should return a hash of sizes when photo_sizes is set" do
+ photo_sizes = Twitter::Configuration.new('photo_sizes' => {'small' => {'h' => 226, 'w' => 340, 'resize' => 'fit'}, 'large' => {'h' => 466, 'w' => 700, 'resize' => 'fit'}, 'medium' => {'h' => 399, 'w' => 600, 'resize' => 'fit'}, 'thumb' => {'h' => 150, 'w' => 150, 'resize' => 'crop'}}).photo_sizes
+ photo_sizes.should be_a Hash
+ photo_sizes['small'].should be_a Twitter::Size
+ end
+
+ it "should return nil when photo_sizes is not set" do
+ photo_sizes = Twitter::Configuration.new.photo_sizes
+ photo_sizes.should be_nil
+ end
+
+ end
+
+end
View
2 spec/twitter/photo_spec.rb
@@ -32,7 +32,7 @@
sizes['small'].should be_a Twitter::Size
end
- it "should return nil when status is not set" do
+ it "should return nil when sizes is not set" do
sizes = Twitter::Photo.new.sizes
sizes.should be_nil
end

0 comments on commit 19bebb8

Please sign in to comment.