Skip to content

Commit

Permalink
Swapped Mash for Hashie
Browse files Browse the repository at this point in the history
  • Loading branch information
pengwynn committed Apr 5, 2010
1 parent 54105e4 commit f60845c
Show file tree
Hide file tree
Showing 19 changed files with 5,360 additions and 49 deletions.
8 changes: 4 additions & 4 deletions Rakefile
Expand Up @@ -6,21 +6,21 @@ begin
Jeweler::Tasks.new do |gem|
gem.name = "twitterland"
gem.summary = %Q{wrappers for various twitter apis}
gem.email = "info@squeejee.com"
gem.homepage = "http://github.com/squeejee/twitterland"
gem.email = "wynn.netherland@gmail.com"
gem.homepage = "http://github.com/pengwynn/twitterland"
gem.authors = ["Wynn Netherland","Bradley Joyce", "Ron Evans"]
gem.rubyforge_project = "twitterland"
gem.files = FileList["[A-Z]*", "{examples,lib,test}/**/*"]

gem.add_dependency('mash', '0.0.3')
gem.add_dependency('hashie', '>= 0.2.0')
gem.add_dependency('httparty', '>= 0.4.3')
gem.add_dependency('one40_proof', '>= 0.0.3')

gem.add_development_dependency('thoughtbot-shoulda')
gem.add_development_dependency('jeremymcanally-matchy')
gem.add_development_dependency('mocha')
gem.add_development_dependency('fakeweb')
gem.add_development_dependency('mash')
gem.add_development_dependency('hashie')
end
Jeweler::GemcutterTasks.new
rescue LoadError
Expand Down
10 changes: 4 additions & 6 deletions lib/twitterland.rb
@@ -1,12 +1,10 @@
require 'forwardable'
require 'rubygems'

gem 'mash', '0.0.3'
require 'mash'

gem 'httparty', '>= 0.4.5'
require 'hashie'
require 'httparty'

Hash.send :include, Hashie::HashExtensions

module Twitterland
class TwitterError < StandardError
attr_reader :data
Expand Down Expand Up @@ -34,7 +32,7 @@ module TweetMeme
#
# Twitterland::TweetMeme.url_info('http://squeejee.com')
def self.url_info(url)
Mash.new get("/url_info.json", :query => {:url => url})
Hashie::Mash.new get("/url_info.json", :query => {:url => url})
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitterland/back_tweets.rb
Expand Up @@ -11,19 +11,19 @@ class BackTweets
# Twitterland::BackTweets.search('http://squeejee.com', 'OU812')
def self.search(q, api_key, options={})
options['itemsperpage'] = options.delete(:items_per_page) if options[:items_per_page]
rubyize_response(Mash.new(get("/search.json", :query => {:q => q, :key => api_key}.merge(options))))
rubyize_response(Hashie::Mash.new(get("/search.json", :query => {:q => q, :key => api_key}.merge(options))))
end


# Scrubs the response from Back Tweets to rubyize keys
def self.rubyize_response(response)
results = Mash.new
results = Hashie::Mash.new
raise BackTweets::Unauthenticated.new if response.has_key?('error')
results.total_results = response['totalresults'].to_i
results.start_index = response['startindex']
results.items_per_page = response['itemsperpage']
results.tweets = response['tweets'].map do |tweet|
new_tweet = Mash.new
new_tweet = Hashie::Mash.new
tweet.each do |key, value|
new_tweet[key.to_s.gsub('tweet_', '')] = value
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitterland/foller_me.rb
Expand Up @@ -54,7 +54,7 @@ def self.terms(username, options={})
options = options.to_hash.to_mash
terms = options.delete('terms')
terms ||= 'all'
result = Mash.new get("/#{username}/#{terms}.json", :query => options)
result = Hashie::Mash.new get("/#{username}/#{terms}.json", :query => options)
case terms
when 'all'
result.topics ||= result.delete('terms_topics')
Expand Down
2 changes: 1 addition & 1 deletion lib/twitterland/follow_cost.rb
Expand Up @@ -8,7 +8,7 @@ class FollowCost
#
# Twitterland::FollowCost.show('bradleyjoyce')
def self.show(username)
Mash.new get("/#{username}.json")
Hashie::Mash.new get("/#{username}.json")
end

end
Expand Down
10 changes: 5 additions & 5 deletions lib/twitterland/mrtweet.rb
Expand Up @@ -17,7 +17,7 @@ def initialize(api_key, username)
#
# Twitterland::Mrtweet.new(api_key,'bradleyjoyce').is_user
def is_user
Mash.new(self.class.get("/is_user/#{@username}/#{@api_key}.json")).is_user
Hashie::Mash.new(self.class.get("/is_user/#{@username}/#{@api_key}.json")).is_user
end

# Check whether the given user is a MrTweet user (caches first request)
Expand All @@ -32,7 +32,7 @@ def is_user?
# Twitterland::Mrtweet.new(api_key,'bradleyjoyce').profile
def profile
if is_user?
@profile ||= Mash.new(self.class.get("/profile/#{@username}/#{@api_key}.json")).profile
@profile ||= Hashie::Mash.new(self.class.get("/profile/#{@username}/#{@api_key}.json")).profile
end
end

Expand All @@ -41,7 +41,7 @@ def profile
# Twitterland::Mrtweet.new(api_key,'bradleyjoyce').recommendations
def recommendations
if is_user?
@recommendations ||= Mash.new(self.class.get("/recommendations/#{@username}/#{@api_key}.json")).recommendations
@recommendations ||= Hashie::Mash.new(self.class.get("/recommendations/#{@username}/#{@api_key}.json")).recommendations
end
end

Expand All @@ -51,7 +51,7 @@ def recommendations
# Twitterland::Mrtweet.new(api_key,'bradleyjoyce').most_attention_towards
def most_attention_towards
if is_user?
@most_attention_towards ||= Mash.new(self.class.get("/most_attention_towards/#{@username}/#{@api_key}.json")).most_attention_towards
@most_attention_towards ||= Hashie::Mash.new(self.class.get("/most_attention_towards/#{@username}/#{@api_key}.json")).most_attention_towards
end
end

Expand All @@ -62,7 +62,7 @@ def most_attention_towards
# Twitterland::Mrtweet.new(api_key,'bradleyjoyce').recommend(reason,friend_name)
def recommend(reason, friend_name)
if is_user?
Mash.new(self.class.post("/recommend/#{@username}/#{@api_key}.json", :body => { :reason => reason, :friend_name => friend_name})).status == "success"
Hashie::Mash.new(self.class.post("/recommend/#{@username}/#{@api_key}.json", :body => { :reason => reason, :friend_name => friend_name})).status == "success"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/twitterland/thumbfight.rb
Expand Up @@ -11,7 +11,7 @@ def self.fight(*args)
params = {}
params[:challenger1] = args[0] if args[0]
params[:challenger2] = args[1] if args[1]
Mash.new get("/fight.json", :query => params)
Hashie::Mash.new get("/fight.json", :query => params)
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitterland/tweet_blocker.rb
Expand Up @@ -8,14 +8,14 @@ class TweetBlocker
#
# Twitterland::TweetBlocker.user('bradleyjoyce')
def self.user(username)
Mash.new(self.get("/username/#{username}.json")).user
Hashie::Mash.new(self.get("/username/#{username}.json")).user
end

# Report user as spammer
#
# Twitterland::TweetBlocker.spam('leetspeeker39203959230390235')
def self.report_spam(username)
status = Mash.new(self.get("/spam/#{username}.json"))
status = Hashie::Mash.new(self.get("/spam/#{username}.json"))
status['error'].blank? ? status : status['error']
end

Expand All @@ -24,7 +24,7 @@ def self.report_spam(username)
#
# Twitterland::TweetBlocker.rate_limit
def self.rate_limit
@rate_limit = Mash.new(self.get("/user/rate_limit_status.json"))
@rate_limit = Hashie::Mash.new(self.get("/user/rate_limit_status.json"))
end
end
end
6 changes: 3 additions & 3 deletions lib/twitterland/tweet_meme/analytics.rb
Expand Up @@ -11,7 +11,7 @@ class Analytics
#
# Twitterland::TweetMeme::Analytics.build(1234, 'OU812', 'http://tweetcongress.org')
def self.build(app_id, api_key, url)
Mash.new(get("/build.json", :query => {:appid => app_id, :apikey => api_key, :url => url})).uid
Hashie::Mash.new(get("/build.json", :query => {:appid => app_id, :apikey => api_key, :url => url})).uid
end

# Returns a list of all Analytics that you have built, optionally filtered by domain. Accessible to anyone with an App ID and App Key.
Expand All @@ -20,7 +20,7 @@ def self.build(app_id, api_key, url)
def self.built(app_id, api_key, url=nil)
options = {:appid => app_id, :apikey => api_key}
options.merge({:url => url}) unless url.blank?
Mash.new get("/built.json", :query => options)
Hashie::Mash.new get("/built.json", :query => options)
end

# Returns the HTML to display the built Analytics to the user.
Expand All @@ -29,7 +29,7 @@ def self.built(app_id, api_key, url=nil)
#
# Twitterland::TweetMeme::Analytics.get(1234, 'OU812', '37758bd44025edb222022dcd1491c29g')
def self.get_data(app_id, api_key, uid)
Mash.new get("/get.json", :query => {:appid => app_id, :apikey => api_key, :uid => uid})
Hashie::Mash.new get("/get.json", :query => {:appid => app_id, :apikey => api_key, :uid => uid})
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitterland/tweet_meme/comments.rb
Expand Up @@ -9,14 +9,14 @@ class Comments
#
# Twitterland::TweetMeme::Comments.firehose
def self.firehose(options={})
Mash.new get("/firehose.json")
Hashie::Mash.new get("/firehose.json")
end

# Returns comments posted on a particular URL
#
# Twitterland::TweetMeme.get_url('http://squeejee.com')
def self.get_url(url)
Mash.new get("/get_url.json", :query => {:url => url})
Hashie::Mash.new get("/get_url.json", :query => {:url => url})
end

end
Expand Down
8 changes: 4 additions & 4 deletions lib/twitterland/tweet_meme/stories.rb
Expand Up @@ -14,7 +14,7 @@ class Stories
#
# Twitterland::TweetMeme::Stories.popular(options)
def self.popular(options={})
Mash.new get("/popular.json", :query => options)
Hashie::Mash.new get("/popular.json", :query => options)
end

# Returns the most recent stories found by TweetMeme.
Expand All @@ -26,7 +26,7 @@ def self.popular(options={})
#
# Twitterland::TweetMeme::Stories.recent(options)
def self.recent(options={})
Mash.new get("/recent.json", :query => options)
Hashie::Mash.new get("/recent.json", :query => options)
end

# Returns a list of categories down to the specified depth, optionally filtered by a parent category.
Expand All @@ -36,7 +36,7 @@ def self.recent(options={})
#
# Twitterland::TweetMeme::Stories.categories(options)
def self.categories(options={})
Mash.new get("/categories.json", :query => options)
Hashie::Mash.new get("/categories.json", :query => options)
end

# Returns 10 tweets for the specified URL.
Expand All @@ -46,7 +46,7 @@ def self.categories(options={})
#
# Twitterland::TweetMeme::Stories.tweets(url, from_id)
def self.tweets(url, from_id=0)
Mash.new get("/tweets.json", :query => {:url => url, :from_id => from_id})
Hashie::Mash.new get("/tweets.json", :query => {:url => url, :from_id => from_id})
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitterland/twinfluence.rb
Expand Up @@ -13,7 +13,7 @@ def initialize(username, password)
#
# Twitterland::Twinfluence.new(username,password)
def user(id, cacheonly=true)
Mash.new Twinfluence.post("/api_user.php", :body => {:id => id, :user => @username, :pwd => @password, :cacheonly => cacheonly})
Hashie::Mash.new Twinfluence.post("/api_user.php", :body => {:id => id, :user => @username, :pwd => @password, :cacheonly => cacheonly})
end

# Search Twinfluence users
Expand All @@ -25,7 +25,7 @@ def user(id, cacheonly=true)
#
# Twitterland::Twinfluence.search(username,password)
def search(id, options={})
Mash.new Twinfluence.post("/api_search.php", :body => {:user => @username, :pwd => @password}.merge(options))
Hashie::Mash.new Twinfluence.post("/api_search.php", :body => {:user => @username, :pwd => @password}.merge(options))
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitterland/twitter_counter.rb
Expand Up @@ -29,7 +29,7 @@ class TwitterCounter
def self.show(username, results=365)
stats = get("/", :query => {:username => username, :output => 'json', :results => results})
totals = stats.delete('followersperdate')
stats = Mash.new stats
stats = Hashie::Mash.new stats
# map values to integers because strings are a PIA for stats
[
"tomorrow_2w",
Expand Down
2 changes: 1 addition & 1 deletion lib/twitterland/zutual.rb
Expand Up @@ -5,7 +5,7 @@ class Zutual
format :json

def self.match(first_user, second_user)
Mash.new(get("/twitter/match/#{first_user}+#{second_user}.json")).matches
Hashie::Mash.new(get("/twitter/match/#{first_user}+#{second_user}.json")).matches
end
end
end
2,854 changes: 2,853 additions & 1 deletion test/fixtures/foller_me_all.json

Large diffs are not rendered by default.

2,466 changes: 2,465 additions & 1 deletion test/fixtures/foller_me_topics.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -3,6 +3,7 @@
require 'shoulda'
require 'mocha'
require 'fakeweb'
require 'redgreen'

gem 'jnunemaker-matchy', '0.4.0'
require 'matchy'
Expand Down
13 changes: 5 additions & 8 deletions test/twitterland/foller_me_test.rb
Expand Up @@ -8,9 +8,8 @@ class FollerMeTest < Test::Unit::TestCase
should "should display all terms for a user" do
stub_get('http://api.foller.me/pengwynn/all.json', 'foller_me_all.json')
result = Twitterland::FollerMe.terms('pengwynn')
result.topics.keys.size.should == 51
result.topics.keys.first.should == 'saints'
result.topics.values.first.popularity.should == 2
result.topics.keys.size.should == 818
result.topics.firefox.popularity.should == 2
end

should "should allow options" do
Expand All @@ -22,9 +21,8 @@ class FollerMeTest < Test::Unit::TestCase
should "should display topics for a user" do
stub_get('http://api.foller.me/pengwynn/topics.json', 'foller_me_topics.json')
result = Twitterland::FollerMe.topics('pengwynn')
result.topics.keys.size.should == 51
result.topics.keys.first.should == 'saints'
result.topics.values.first.popularity.should == 2
result.topics.keys.size.should == 818
result.topics.firefox.popularity.should == 2
end

should "should display mentions for a user" do
Expand All @@ -39,8 +37,7 @@ class FollerMeTest < Test::Unit::TestCase
stub_get('http://api.foller.me/pengwynn/hashtags.json', 'foller_me_hashtags.json')
result = Twitterland::FollerMe.hashtags('pengwynn')
result.hashtags.keys.size.should == 25
result.hashtags.keys.first.should == '#typos'
result.hashtags.values.first.popularity.should == 1
result.hashtags['#typos'].popularity.should == 1
end
end

Expand Down
3 changes: 1 addition & 2 deletions test/twitterland/tweet_meme_test.rb
@@ -1,6 +1,5 @@
class TweetMemeTest < Test::Unit::TestCase
include Twitterland


context "When hitting the Core API" do

should "display details for a url" do
Expand Down

0 comments on commit f60845c

Please sign in to comment.