Permalink
Browse files

Merge commit 'marcandre/master'

Conflicts:
	Rakefile
	lib/googleajax/version.rb
  • Loading branch information...
2 parents 997ca57 + a1d67d4 commit ff14d208730b8d4e29e0295bbdb0a26fa007409c Wesley Beary committed Nov 18, 2009
View
@@ -1,6 +1,22 @@
-=== 1.0.0 / 2008-05-19
+=== 0.2.0 / 2009-11-17
-* 1 major enhancement
+* New features:
+ * results can use [] and []= for lookup and seting
+ * allows results to be open structs (default) or hash (by requiring 'googleajax/as_hash' instead)
- * Birthday!
+* bug fixes:
+ * Search.web(...).count now returns an int, not a string
+ * many calls were not passing the args argument to #get
+ * Feed.load used to return an open struct with only one method called 'feed' that was a hash. It now returns the feed correctly.
+* Behind the scene changes:
+ * specs
+ * shorter, cleaner code
+ * links to google api doc in rdoc
+ * most classes are now modules
+ * small optimizations
+ * All #get now requires arg (see bug fix)
+
+=== 0.1.0 / 2008-05-19
+
+* Initial Release
View
@@ -1,11 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-lib/googleajax.rb
-lib/googleajax/feed.rb
-lib/googleajax/language.rb
-lib/googleajax/parser.rb
-lib/googleajax/search.rb
-lib/googleajax/version.rb
-test/test_googleajax.rb
View
@@ -55,11 +55,11 @@ Ruby wrapper for Google AJAX API REST interfaces(Feeds, Language and Search).
== REQUIREMENTS:
-* JSON gem to parse responses
+* JSON gem to parse responses, or rails
== INSTALL:
- sudo gem install googleajax --include-dependencies
+ sudo gem install googleajax
== LICENSE:
View
@@ -1,17 +1,46 @@
-# -*- ruby -*-
-
require 'rubygems'
-require 'hoe'
-$: << File.dirname(__FILE__) + '/lib'
-require './lib/googleajax.rb'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "googleajax"
+ gem.summary = %Q{Ruby wrapper to the Google AJAX API REST interfaces(Feeds, Language and Search).}
+ #gem.description = %Q{TODO: longer description of your gem}
+ gem.email = "me@geemus.com"
+ gem.homepage = "http://github.com/geemus/googleajax"
+ gem.authors = ["geemus(Wesley Beary)", "Marc-Andre Lafortune"]
+ gem.add_development_dependency "rspec", ">= 1.2.9"
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ gem.add_dependency 'json', '>= 1.0.0'
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
+
+require 'spec/rake/spectask'
+Spec::Rake::SpecTask.new(:spec) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.spec_files = FileList['spec/**/*_spec.rb']
+end
-Hoe.spec('googleajax') do
- rubyforge_name = 'googleajax'
- developer('monki(Wesley Beary)', 'monki@geemus.com')
- summary = 'Ruby wrapper to the Google AJAX API REST interfaces(Feeds, Language and Search).'
- url = 'http://googleajax.rubyforge.com'
- remote_rdoc_dir = ''
- extra_deps << ['json', '>= 1.0.0']
+Spec::Rake::SpecTask.new(:rcov) do |spec|
+ spec.libs << 'lib' << 'spec'
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
end
-# vim: syntax=Ruby
+task :spec => :check_dependencies
+
+task :default => :spec
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "googleajax #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
@@ -0,0 +1 @@
+0.2.0
View
@@ -1,25 +0,0 @@
-Gem::Specification.new do |s|
- s.name = %q{GoogleAjax}
- s.version = "0.1.0"
-
- s.specification_version = 2 if s.respond_to? :specification_version=
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["monki(Wesley Beary)"]
- s.date = %q{2008-05-19}
- s.description = %q{Ruby wrapper to the Google AJAX API REST interfaces(Feeds, Language and Search).}
- s.email = ["monki@geemus.com"]
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/googleajax.rb", "lib/googleajax/feed.rb", "lib/googleajax/language.rb", "lib/googleajax/parser.rb", "lib/googleajax/search.rb", "lib/googleajax/version.rb", "test/test_googleajax.rb"]
- s.has_rdoc = true
- s.homepage = %q{http://googleajax.rubyforge.com}
- s.rdoc_options = ["--main", "README.txt"]
- s.require_paths = ["lib"]
- s.rubyforge_project = %q{googleajax}
- s.rubygems_version = %q{1.1.1}
- s.summary = %q{Ruby wrapper to the Google AJAX API REST interfaces(Feeds, Language and Search).}
- s.test_files = ["test/test_googleajax.rb"]
-
- s.add_dependency(%q<json>, [">= 1.0.0"])
- s.add_dependency(%q<hoe>, [">= 1.5.1"])
-end
View
@@ -4,37 +4,28 @@
require 'rubygems'
require 'json' unless defined?(Rails)
-require 'googleajax/feed'
-require 'googleajax/language'
-require 'googleajax/parser'
-require 'googleajax/search'
-require 'googleajax/version'
+module GoogleAjax
+ require 'googleajax/base' unless const_defined?("Base")
+ require 'googleajax/feed'
+ require 'googleajax/language'
+ require 'googleajax/search'
+ require 'googleajax/parser'
-class GoogleAjax
API_BASE = 'http://ajax.googleapis.com/ajax/services/'
- @@api_key = @@referer = nil
+ class << self
+ attr_accessor :api_key
+ attr_accessor :referer
- def self.api_key
- @@api_key
- end
- def self.api_key=(key)
- @@api_key = key
- end
- def self.referer
- @@referer
- end
- def self.referer=(referer)
- @@referer = referer
- end
-
- def self.get(api, method, query, args = nil)
- raise "You must assign a value to GoogleAjax.referer" unless @@referer
- url = "#{API_BASE}#{api}/"
- url += "#{method}?"
- url += "&q=#{CGI::escape(query)}"
- url += "&key=#{api_key}" if api_key
- url += "&" + args.collect {|key, value| "#{key}=#{value}"}.join('&') if args && !args.empty?
- data = open(url, "Referer" => @@referer).read
- Parser.parse(api, method, data)
+ # Api doc is at http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
+ def get(api, method, query, args = nil)
+ raise "You must assign a value to GoogleAjax.referer" unless referer
+ url = "#{API_BASE}#{api}/"
+ url += "#{method}?"
+ url += "&q=#{CGI::escape(query)}"
+ url += "&key=#{api_key}" if api_key
+ url += "&" + args.collect {|key, value| "#{key}=#{value}"}.join('&') if args && !args.empty?
+ data = open(url, "Referer" => referer).read
+ Parser.parse(api, method, data)
+ end
end
end
View
@@ -0,0 +1,15 @@
+# Include this file instead of googleajax so that results are simply hashes
+
+module GoogleAjax
+ class Base < Hash
+ def initialize(h)
+ super()
+ replace(h)
+ end
+
+ def self.remap(h)
+ end
+ end
+end
+
+require 'googleajax'
View
@@ -0,0 +1,25 @@
+module GoogleAjax
+ class Base < OpenStruct
+ def [](key)
+ send(key)
+ end
+
+ def []=(key, value)
+ send("#{key}=", value)
+ end
+
+ def self.remap(h)
+ define_method(:initialize) do |arg|
+ super(arg)
+ h.each do |key, klass|
+ case self[key]
+ when Array
+ self[key] = self[key].map(&klass.method(:new))
+ when Hash
+ self[key] = klass.new(self[key])
+ end
+ end
+ end
+ end
+ end
+end
View
@@ -1,38 +1,35 @@
-class GoogleAjax
- class Feed
+module GoogleAjax
+ module Feed
FEED_VERSION = 1.0
- def self.get(method, query, args = {})
- args = { :v => FEED_VERSION }.merge!(args)
+ # Arguments: http://code.google.com/apis/ajaxfeeds/documentation/reference.html#_intro_fonje
+ def self.get(method, query, args)
+ args = { :v => FEED_VERSION }.merge(args)
GoogleAjax::get(:feed, method, query, args)
end
-
+
# will return a list of feeds that match the given query
+ # Arguments: http://code.google.com/apis/ajaxfeeds/documentation/reference.html#_fonje_find
def self.find(query, args = {})
- self.get(:find, query)
+ self.get(:find, query, args)
end
# downloads this feed from Google's servers
- # Optional: args { :num => number of entries to download(default is 4, maximum is 100) }
- def self.load(query, args = {})
- self.get(:load, query, args)
+ # Arguments: http://code.google.com/apis/ajaxfeeds/documentation/reference.html#_fonje_load
+ def self.load(url, args = {})
+ self.get(:load, url, args)
end
-
+
# will return the associated feed if it exists for a given url
- def self.lookup(query, args = {})
- self.get(:lookup, query)
+ # Arguments: http://code.google.com/apis/ajaxfeeds/documentation/reference.html#_intro_fonje
+ def self.lookup(url, args = {})
+ self.get(:lookup, url, args)
end
-
- class Entry < OpenStruct
- def initialize(data)
- super(data)
- end
+
+ class Entry < Base
end
-
- class Feed < OpenStruct
- def initialize(data)
- super(data)
- self.entries = entries.collect {|data| Entry.new(data)} if entries
- end
+
+ class Feed < Base
+ remap :entries => Entry
end
end
end
View
@@ -1,36 +1,29 @@
-class GoogleAjax
- class Language
+module GoogleAjax
+ module Language
LANGUAGE_VERSION = 1.0
- def self.get(method, query, args = {})
- args = { :v => LANGUAGE_VERSION }.merge!(args)
+ def self.get(method, query, args)
+ args = { :v => LANGUAGE_VERSION }.merge(args)
GoogleAjax::get(:language, method, query, args)
end
# will return the language code that describes the language of the given text
def self.detect(query, args = {})
- self.get(:detect, query)
+ self.get(:detect, query, args)
end
# will return translated text for the given text supplied, matching the destination language.
def self.translate(query, source, destination, args = {})
- args = { :langpair => "#{source}%7C#{destination}"}.merge!(args)
+ args = { :langpair => "#{source}%7C#{destination}"}.merge(args)
self.get(:translate, query, args)
end
- class Language < OpenStruct
- def initialize(data)
- super(data)
- end
-
+ class Language < Base
def name
- LANGUAGES.invert[self.language]
+ (@@lang_cache ||= LANGUAGES.invert)[self.language]
end
end
- class Translation < OpenStruct
- def initialize(data)
- super(data)
- end
+ class Translation < Base
end
LANGUAGES =
@@ -77,6 +70,6 @@ def initialize(data)
'UKRAINIAN' => 'uk',
'VIETNAMESE' => 'vi',
'UNKNOWN' => ''
- }
+ }
end
end
Oops, something went wrong.

0 comments on commit ff14d20

Please sign in to comment.