allyourbase 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,48 @@
1
+ Copyright (c) 2009 Logan Bowers
2
+
3
+ Open Software License ("OSL") v. 3.0
4
+ This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
5
+
6
+ Licensed under the Open Software License version 3.0
7
+
8
+ 1) Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
9
+
10
+ a) to reproduce the Original Work in copies, either alone or as part of a collective work;
11
+
12
+ b) to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
13
+
14
+ c) to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
15
+
16
+ d) to perform the Original Work publicly; and
17
+
18
+ e) to display the Original Work publicly.
19
+
20
+ 2) Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
21
+
22
+ 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
23
+
24
+ 4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
25
+
26
+ 5) External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
27
+
28
+ 6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
29
+
30
+ 7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
31
+
32
+ 8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
33
+
34
+ 9) Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
35
+
36
+ 10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
37
+
38
+ 11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
39
+
40
+ 12) Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
41
+
42
+ 13) Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
43
+
44
+ 14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
45
+
46
+ 15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
47
+
48
+ 16) Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
@@ -0,0 +1,27 @@
1
+ = allyourbase
2
+
3
+ ActiveRecord-inspired library to consume (and eventually publish to) Google's Base APIs. The Atom feed is parse and conversed to intuitive Object representations.
4
+
5
+ == TODO
6
+
7
+ * Almost everything
8
+ * Tests
9
+ * Authentication
10
+ * Create/Update/Delete methods
11
+ * Extension classes for smart handling of common google attributes
12
+ * Dynamic getter generattion and/or passthrough of getters to Atom feed entry to automatically get access to custom attributes
13
+
14
+ == Note on Patches/Pull Requests
15
+
16
+ * Fork the project.
17
+ * Make your feature addition or bug fix.
18
+ * Add tests for it. This is important so I don't break it in a
19
+ future version unintentionally.
20
+ * Commit, do not mess with rakefile, version, or history.
21
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
22
+ * Send me a pull request. Bonus points for topic branches.
23
+ * Break large pull requests into small digestible pieces
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010 Logan Bowers. See LICENSE for details.
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "allyourbase"
8
+ gem.summary = %Q{ActiveRecord-esque interface to Google Base APIs}
9
+ gem.description = %Q{Provides access to Google's Base Base data feed. Currently read-only, public API; full CRUD is the goal. }
10
+ gem.email = "logan@datacurrent.com"
11
+ gem.homepage = "http://github.com/loganb/allyourbase"
12
+ gem.authors = ["Logan Bowers"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ gem.add_dependency "httparty",">= 0.5.0"
15
+ gem.add_dependency "ratom",">= 0.6.3"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "allyourbase #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,115 @@
1
+ require 'httparty'
2
+ require 'atom'
3
+
4
+ module GoogleBase
5
+ include HTTParty
6
+
7
+ base_uri 'http://www.google.com/base/feeds/snippets'
8
+ parser Proc.new { |b,format|
9
+ Atom::Feed.load_feed(b)
10
+ }
11
+
12
+ GOOGLENS = "http://base.google.com/ns/1.0"
13
+ OPENSEARCHNS = "http://a9.com/-/spec/opensearchrss/1.0/"
14
+
15
+
16
+ # Finds Items in Google Base using the "snippets" Atom feed.
17
+ #
18
+ # ===Options:
19
+ #
20
+ # * :limit => <Max number of results to return>
21
+ # * :offset => <0-based, starting offset of result set>
22
+ #
23
+ # All other options are passed as structured terms (e.g. part of the 'bq' param).
24
+ # **Options param will be mutated
25
+ #
26
+ def self.find(terms = [],options = {})
27
+ #Max Number of results
28
+ limit = options.delete(:limit) || 10
29
+ #Starting offset (zero based)
30
+ offset = (options.delete(:offset) || 0) + 1
31
+
32
+ bq = structure(options)
33
+
34
+ q = terms.collect { |t|
35
+ t = "\"#{t}\"" if(t =~ /[^\w\d\-\.\_]/)
36
+ t
37
+ }.join(' ')
38
+
39
+ atom = get('',:query => {:q => q, :bq => bq, :'max-results' => limit, :'start-index' => offset})
40
+
41
+ res = SearchResponse.new({
42
+ :terms => terms,
43
+ :limit => limit,
44
+ :offset => atom[OPENSEARCHNS,'startIndex'].first.to_i - 1,
45
+ :count => atom[OPENSEARCHNS,'totalResults'].first.to_i,
46
+ :options => options
47
+ })
48
+ res.results = atom.entries.collect { |e|
49
+ Item.new(e)
50
+ }
51
+ res
52
+ end
53
+
54
+
55
+ #
56
+ #
57
+ #
58
+ class Item
59
+ attr_accessor :author, :title, :image_url, :description, :price
60
+
61
+ #
62
+ # Constructs an item from
63
+ #
64
+ #
65
+ def initialize(ae)
66
+ @author = ae.authors.first.name
67
+ @title = ae.title
68
+ @description = ae.content
69
+ @image_url = ae[GOOGLENS,"image_link"].first
70
+ @price = ae[GOOGLENS,"price"].first.split(/\s+/).first.to_f
71
+ end
72
+ end
73
+
74
+ class SearchResponse
75
+ attr_accessor :limit, :offset, :terms, :options, :results, :count
76
+
77
+ def initialize(attrs = nil)
78
+ attrs.each_pair do |k,v|
79
+ send "#{k}=", v
80
+ end if(attrs)
81
+ end
82
+
83
+ def next_page
84
+ raise "TODO"
85
+ end
86
+
87
+ def prev_page
88
+ raise "TODO"
89
+ end
90
+ end
91
+
92
+ protected
93
+
94
+ #
95
+ # Turns a set of queries into a santized parametric search string
96
+ #
97
+ def self.structure(query)
98
+ bq = "" #Strcutured query
99
+ query.each_pair { |k,v|
100
+ bq << case
101
+ when (v.is_a? String)
102
+ "[#{k}:\"#{v}\"]"
103
+ when (v.is_a? Fixnum) || (v.is_a? Float)
104
+ "[#{k}:#{v}]"
105
+ when (v.is_a? Array) #OR the terms together
106
+ "[#{k}:" << v.collect {|e| "\"#{e}\""}.join('|') << "]"
107
+ when (v.is_a? Range)
108
+ raise "TODO"
109
+ else
110
+ raise "Don't know how to convert #{v.class} to a query value (#{v.inspect})"
111
+ end
112
+ }
113
+ bq
114
+ end
115
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'allyourbase'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'helper'
2
+
3
+ class TestAllyourbase < Test::Unit::TestCase
4
+ should "should not crash" do
5
+ results = GoogleBase.find('vase',:'item type' => 'products',:link => '1000markets.com')
6
+ end
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allyourbase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Logan Bowers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: httparty
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: ratom
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.6.3
44
+ version:
45
+ description: "Provides access to Google's Base Base data feed. Currently read-only, public API; full CRUD is the goal. "
46
+ email: logan@datacurrent.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/allyourbase.rb
62
+ - test/helper.rb
63
+ - test/test_allyourbase.rb
64
+ has_rdoc: true
65
+ homepage: http://github.com/loganb/allyourbase
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.5
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: ActiveRecord-esque interface to Google Base APIs
92
+ test_files:
93
+ - test/helper.rb
94
+ - test/test_allyourbase.rb