diff --git a/lib/twitter/client.rb b/lib/twitter/client.rb index ef1308402..e229b142e 100644 --- a/lib/twitter/client.rb +++ b/lib/twitter/client.rb @@ -14,6 +14,7 @@ class Client < API require 'twitter/client/friendship' require 'twitter/client/friends_and_followers' require 'twitter/client/geo' + require 'twitter/client/help' require 'twitter/client/legal' require 'twitter/client/list' require 'twitter/client/list_members' @@ -39,6 +40,7 @@ class Client < API include Twitter::Client::Friendship include Twitter::Client::FriendsAndFollowers include Twitter::Client::Geo + include Twitter::Client::Help include Twitter::Client::Legal include Twitter::Client::List include Twitter::Client::ListMembers diff --git a/lib/twitter/client/help.rb b/lib/twitter/client/help.rb new file mode 100644 index 000000000..afecece4c --- /dev/null +++ b/lib/twitter/client/help.rb @@ -0,0 +1,34 @@ +module Twitter + class Client + # Defines methods related twitter's supported features and configuration + module Help + # Returns the current configuration used by Twitter + # + # @format :json, :xml + # @authenticated false + # @rate_limited true + # @return [Hashie::Mash] Twitter's configuration. + # @see http://dev.twitter.com/doc/get/help/configuration + # @example Return the current configuration used by Twitter + # Twitter.configuration + def configuration(options={}) + response = get('help/configuration', options) + format.to_s.downcase == 'xml' ? response['configuration'] : response + end + + # Returns the list of languages supported by Twitter + # + # @format :json, :xml + # @authenticated false + # @rate_limited true + # @return [Array] + # @see http://dev.twitter.com/doc/get/help/languages + # @example Return the list of languages Twitter supports + # Twitter.languages + def languages(options={}) + response = get('help/languages', options) + format.to_s.downcase == 'xml' ? response['languages']['language'] : response + end + end + end +end diff --git a/spec/fixtures/configuration.json b/spec/fixtures/configuration.json new file mode 100644 index 000000000..763151416 --- /dev/null +++ b/spec/fixtures/configuration.json @@ -0,0 +1 @@ +{"photo_sizes":{"medium":{"h":1200,"w":600,"resize":"fit"},"small":{"h":480,"w":340,"resize":"fit"},"large":{"h":2048,"w":1024,"resize":"fit"},"thumb":{"h":150,"w":150,"resize":"crop"}},"non_username_paths":["about","account","accounts","activity","all","announcements","anywhere","api_rules","api_terms","apirules","apps","auth","badges","blog","business","buttons","contacts","devices","direct_messages","download","downloads","edit_announcements","faq","favorites","find_sources","find_users","followers","following","friend_request","friendrequest","friends","goodies","help","home","im_account","inbox","invitations","invite","jobs","list","login","logout","me","mentions","messages","mockview","newtwitter","notifications","nudge","oauth","phoenix_search","positions","privacy","public_timeline","related_tweets","replies","retweeted_of_mine","retweets","retweets_by_others","rules","saved_searches","search","sent","settings","share","signup","signin","similar_to","statistics","terms","tos","translate","trends","tweetbutton","twttr","update_discoverability","users","welcome","who_to_follow","widgets","zendesk_auth","media_signup","t1_qunit_tests","phoenix_qunit_tests"],"photo_size_limit":3145728,"max_media_per_upload":1,"short_url_length":19,"short_url_length_https":20,"characters_reserved_per_media":20} \ No newline at end of file diff --git a/spec/fixtures/configuration.xml b/spec/fixtures/configuration.xml new file mode 100644 index 000000000..b20d862a9 --- /dev/null +++ b/spec/fixtures/configuration.xml @@ -0,0 +1,116 @@ + + + 19 + 20 + + about + account + accounts + activity + all + announcements + anywhere + api_rules + api_terms + apirules + apps + auth + badges + blog + business + buttons + contacts + devices + direct_messages + download + downloads + edit_announcements + faq + favorites + find_sources + find_users + followers + following + friend_request + friendrequest + friends + goodies + help + home + im_account + inbox + invitations + invite + jobs + list + login + logout + me + mentions + messages + mockview + newtwitter + notifications + nudge + oauth + phoenix_search + positions + privacy + public_timeline + related_tweets + replies + retweeted_of_mine + retweets + retweets_by_others + rules + saved_searches + search + sent + settings + share + signup + signin + similar_to + statistics + terms + tos + translate + trends + tweetbutton + twttr + update_discoverability + users + welcome + who_to_follow + widgets + zendesk_auth + media_signup + t1_qunit_tests + phoenix_qunit_tests + + 3145728 + 1 + 20 + + + 150 + 150 + crop + + + 340 + 480 + fit + + + 600 + 1200 + fit + + + 1024 + 2048 + fit + + + diff --git a/spec/fixtures/languages.json b/spec/fixtures/languages.json new file mode 100644 index 000000000..7ac22afa6 --- /dev/null +++ b/spec/fixtures/languages.json @@ -0,0 +1 @@ +[{"name":"Portuguese","status":"production","code":"pt"},{"name":"Indonesian","status":"production","code":"id"},{"name":"Italian","status":"production","code":"it"},{"name":"Spanish","status":"production","code":"es"},{"name":"Turkish","status":"production","code":"tr"},{"name":"English","status":"production","code":"en"},{"name":"Korean","status":"production","code":"ko"},{"name":"French","status":"production","code":"fr"},{"name":"Dutch","status":"production","code":"nl"},{"name":"Russian","status":"production","code":"ru"},{"name":"German","status":"production","code":"de"},{"name":"Japanese","status":"production","code":"ja"}] \ No newline at end of file diff --git a/spec/fixtures/languages.xml b/spec/fixtures/languages.xml new file mode 100644 index 000000000..59c178e4f --- /dev/null +++ b/spec/fixtures/languages.xml @@ -0,0 +1,63 @@ + + + + Portuguese + pt + production + + + Indonesian + id + production + + + Italian + it + production + + + Spanish + es + production + + + Turkish + tr + production + + + English + en + production + + + Korean + ko + production + + + French + fr + production + + + Dutch + nl + production + + + Russian + ru + production + + + German + de + production + + + Japanese + ja + production + + diff --git a/spec/twitter/client/help_spec.rb b/spec/twitter/client/help_spec.rb new file mode 100644 index 000000000..972f81753 --- /dev/null +++ b/spec/twitter/client/help_spec.rb @@ -0,0 +1,50 @@ +require 'helper' + +describe Twitter::Client do + %w(json xml).each do |format| + context ".new(:format => '#{format}')" do + before do + @client = Twitter::Client.new(:format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS') + end + + describe ".configuration" do + + before do + stub_get("help/configuration.#{format}"). + to_return(:body => fixture("configuration.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) + end + + it "should get the correct resource" do + @client.configuration + a_get("help/configuration.#{format}"). + should have_been_made + end + + it "should return Twitter's current configuration" do + configuration = @client.configuration + configuration.characters_reserved_per_media.to_s.should == '20' + end + + end + + describe ".languages" do + + before do + stub_get("help/languages.#{format}"). + to_return(:body => fixture("languages.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) + end + + it "should get the correct resource" do + @client.languages + a_get("help/languages.#{format}"). + should have_been_made + end + + it "should return the list of languages supported by Twitter" do + languages = @client.languages + languages.first.name.should == "Portuguese" + end + end + end + end +end