svxbox 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ bundler_args: --path=vendor
2
+ gemfile: Gemfile
3
+ script: "bundle exec rake test"
4
+ rvm:
5
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source :gemcutter
2
+
3
+ gem 'nokogiri'
4
+ gem 'amazon_product'
5
+ gem 'rake'
6
+ gem 'jeweler'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'shoulda'
11
+ gem 'mocha'
12
+ gem 'fakeweb'
13
+ gem 'jnunemaker-matchy', :require => 'matchy'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ amazon_product (3.0.1)
5
+ nokogiri (~> 1.4)
6
+ diff-lcs (1.1.3)
7
+ fakeweb (1.3.0)
8
+ git (1.2.5)
9
+ jeweler (1.6.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ jnunemaker-matchy (0.4.0)
14
+ mocha (0.9.12)
15
+ nokogiri (1.5.0)
16
+ rake (0.9.2)
17
+ rspec (2.7.0)
18
+ rspec-core (~> 2.7.0)
19
+ rspec-expectations (~> 2.7.0)
20
+ rspec-mocks (~> 2.7.0)
21
+ rspec-core (2.7.1)
22
+ rspec-expectations (2.7.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.7.0)
25
+ shoulda (2.11.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ amazon_product
32
+ fakeweb
33
+ jeweler
34
+ jnunemaker-matchy
35
+ mocha
36
+ nokogiri
37
+ rake
38
+ rspec
39
+ shoulda
data/README.mkdn ADDED
@@ -0,0 +1,8 @@
1
+ These are some generic utility wrappers I use. They might not be useful to
2
+ others, but possibly.
3
+
4
+ I plan to keep maintaining them, at least.
5
+
6
+ The license is the Affero GPL v3.
7
+
8
+ [Docunext](http://www.docunext.com/)
data/Rakefile CHANGED
@@ -2,44 +2,6 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'shoulda/tasks'
4
4
 
5
-
6
- task :pushit do
7
- system('git commit -m "pushing" -a && git push origin master')
8
- end
9
- task :pullgit do
10
- system('git pull origin master')
11
- end
12
- task :pulltest => [:pullgit, :test]
13
-
14
- task :testroll => [:versioncheck, :gemspec]
15
- task :rollgem => [:testroll, :buildgem, :pushgem]
16
-
17
- task :versioncheck do
18
- @nv = File.open('VERSION') {|f| f.read }.chop
19
- @ov = File.open('OLDVERSION') {|f| f.read }.chop
20
- raise if @nv == @ov
21
- end
22
-
23
- task :buildgem do
24
- system('gem1.9.1 build svxbox.gemspec')
25
- end
26
-
27
- task :pushgem do
28
- cmd = 'gem1.8 push svxbox-' << @nv + '.gem'
29
- system(cmd)
30
- cmd = 'sudo gem1.9.1 install svxbox-' << @nv + '.gem'
31
- system(cmd)
32
- system('cp VERSION OLDVERSION')
33
- cmd = 'rm svxbox-' << @nv + '.gem'
34
- system(cmd)
35
- end
36
-
37
- task :pushgem => [:versioncheck]
38
-
39
- task :frankup do
40
- system('ssh 192.168.8.103 "sudo gem1.9.1 install svxbox"')
41
- end
42
-
43
5
  begin
44
6
  require 'jeweler'
45
7
  Jeweler::Tasks.new do |gem|
@@ -51,51 +13,11 @@ begin
51
13
  gem.authors = ['Albert Lash']
52
14
  gem.rubyforge_project = ''
53
15
  gem.add_development_dependency 'shoulda'
54
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
55
16
  end
56
17
  Jeweler::GemcutterTasks.new
57
- Jeweler::RubyforgeTasks.new do |rubyforge|
58
- rubyforge.doc_task = 'rdoc'
59
- end
60
18
  rescue LoadError
61
19
  puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
62
20
  end
63
21
 
64
22
 
65
- require 'rake/testtask'
66
- Rake::TestTask.new(:test) do |test|
67
- test.ruby_opts = ['-rubygems'] if defined? Gem
68
- test.libs << 'lib' << 'test'
69
- test.pattern = 'test/**/*_test.rb'
70
- end
71
-
72
- begin
73
- require 'rcov/rcovtask'
74
- Rcov::RcovTask.new do |test|
75
- test.libs << 'test'
76
- test.pattern = 'test/**/test_*.rb'
77
- test.verbose = true
78
- end
79
- rescue LoadError
80
- task :rcov do
81
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
82
- end
83
- end
84
-
85
-
86
- task :default => :test
87
- task :spec => :test
88
-
89
- require 'rake/rdoctask'
90
- Rake::RDocTask.new do |rdoc|
91
- if File.exist?('VERSION')
92
- version = File.read('VERSION')
93
- else
94
- version = ""
95
- end
96
-
97
- rdoc.rdoc_dir = 'rdoc'
98
- rdoc.title = "svxbox #{version}"
99
- rdoc.rdoc_files.include('README*')
100
- rdoc.rdoc_files.include('lib/**/*.rb')
101
- end
23
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.1
data/lib/svxbox.rb CHANGED
@@ -1,11 +1,2 @@
1
1
  require File.dirname(__FILE__) + '/svxbox/lexicali'
2
2
  require File.dirname(__FILE__) + '/svxbox/amazoni'
3
- require File.dirname(__FILE__) + '/svxbox/markupguppy'
4
-
5
- # Not included by default
6
- require File.dirname(__FILE__) + '/svxbox/sinatricus'
7
- require File.dirname(__FILE__) + '/svxbox/mongobongo'
8
- require File.dirname(__FILE__) + '/svxbox/ponyboy'
9
-
10
- # Must come last
11
- require File.dirname(__FILE__) + '/svxbox/supabali'
@@ -15,7 +15,7 @@ module SvxBox
15
15
  end
16
16
  end
17
17
 
18
- def search_aaws(cat, search)
18
+ def get_response(cat, search)
19
19
  req = AmazonProduct["us"]
20
20
 
21
21
  req.configure do |c|
@@ -24,17 +24,58 @@ module SvxBox
24
24
  c.tag = ENV['AMAZON_TAG']
25
25
  end
26
26
 
27
- puts "aaws: #{search} #{cat}" unless ENV['RACK_ENV'] == 'production'
27
+ puts "aaws: #{search} #{cat}" if ENV['RACK_ENV'] == 'development'
28
+
29
+ req.search(cat, :operation => 'ItemSearch', :response_group => ['Small','Images'], :keywords => search, :total_results => 5 )
30
+ end
31
+
32
+ def new_search_aaws(cat, search)
33
+ resp = get_response(cat, search)
34
+ if resp.valid?
35
+ products = []
36
+ i = 0
37
+ resp.each('Item') do |item|
38
+ i = i + 1
39
+ unless i > 4
40
+ mfr = Array.new
41
+ imfr = item['Manufacturer']
42
+ product = {}
43
+ unless mfr.include?(imfr)
44
+ mfr << imfr
45
+ product[:url] = url_unescape(item['ItemLinks']['ItemLink'][0]["URL"].to_s).force_encoding('UTF-8')
46
+ if item['SmallImage']
47
+ product[:small_image] = item['SmallImage']['URL']
48
+ if item['LargeImage']
49
+ product[:large_image] = item['LargeImage']['URL']
50
+ end
51
+ end
52
+ product[:title] = item['ItemAttributes']['Title']
53
+
54
+ if item['ItemAttributes']['Author']
55
+ author = item['ItemAttributes']['Author']
56
+ authors = author.is_a?(Array) ? author.map { |author| author.to_s } : [author]
57
+ product[:authors] = authors.join(", ")
58
+ end
59
+
60
+ products << product
61
+ end
62
+ end
63
+ end
64
+ products
65
+ end
66
+
67
+ end
68
+
69
+ def search_aaws(cat, search)
70
+
71
+ resp = get_response(cat, search)
28
72
 
29
- req << {:search_index => 'Books', :operation => 'ItemSearch', :response_group => ['Small','Images'], :keywords => search, :total_results => 5 }
30
- #req.search(search)
31
- resp = req.get
32
- puts resp.to_hash.to_yaml
73
+ #puts resp.to_hash.to_yaml if ENV['RACK_ENV'] == 'development'
33
74
 
34
- puts resp.errors.inspect
75
+ #puts resp.errors.inspect if ENV['RACK_ENV'] == 'development'
35
76
  if resp.valid?
36
77
  attribs = '<div>'
37
- puts resp.to_hash.to_yaml
78
+ puts resp.to_hash.to_yaml if ENV['RACK_ENV'] == 'development'
38
79
  i = 0
39
80
  resp.each('Item') do |item|
40
81
  i = i + 1
@@ -43,17 +84,19 @@ module SvxBox
43
84
  imfr = item['Manufacturer']
44
85
  unless mfr.include?(imfr)
45
86
  mfr << imfr
46
- iurl = url_unescape(item['ItemLinks']['ItemLink'][0]["URL"].to_s)
47
- link = '<a rel="nofollow" href="' << iurl << '">'
87
+ iurl = url_unescape(item['ItemLinks']['ItemLink'][0]["URL"].to_s).force_encoding('UTF-8')
88
+ link = "<a rel='nofollow' href='#{iurl}'>"
48
89
  attribs << '<div style="margin-bottom:1em;" class="clearadiv">'
49
90
  if item['SmallImage']
50
- attribs << '<div class="flrt" style="clear:left;"><center>'+link+'<img alt="'+search+'" src="'+item['SmallImage']['URL']+'"/></a><br />'
91
+ attribs << %Q{<div class="flrt" style="clear:left;">#{link}<img alt="#{search}" src="#{item['SmallImage']['URL']}"/></a><br />'}
51
92
  if item['LargeImage']
52
- attribs << '<a class="thickbox" href="'+item['LargeImage']['URL']+'">zoom</a> / '
93
+ attribs << %Q{<a class="thickbox" href="#{item['LargeImage']['URL']}">zoom</a> / }
53
94
  end
54
- attribs << '<a href="'+iurl+'">buy</a></center>'
95
+ attribs << "<a href='#{iurl}'>buy</a>"
55
96
  attribs << '</div>'
56
97
  end
98
+ puts attribs
99
+ puts attribs.encoding.name
57
100
  attribs << link
58
101
  attribs << item['ItemAttributes']['Title']
59
102
  attribs << '</a><br />'
File without changes
File without changes
File without changes
@@ -1,47 +1,25 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'lib/svxbox.rb')
2
2
 
3
- require 'test/unit'
4
- require 'pathname'
3
+ require 'rspec'
4
+ require 'rspec-expectations'
5
5
 
6
6
  require 'shoulda'
7
7
  require 'matchy'
8
- require 'mocha'
9
8
  require 'fakeweb'
10
- require 'stringio'
11
9
 
12
10
  ENV['RACK_ENV'] = 'test'
13
11
  ENV['AMAZON_KEY'] = ''
14
12
  ENV['AMAZON_TAG'] = ''
15
13
  ENV['AMAZON_SECRET'] = ''
16
14
 
17
- class Test::Unit::TestCase
18
- include SvxBox::SupaBali
19
- include SvxBox::Amazoni
20
- include SvxBox::Sinatricus
21
- end
22
-
23
-
24
-
25
- def copy_stdout(&block)
26
- o = StringIO.new
27
- $stdout = o
28
- block.call
29
- o.close
30
- o
31
- ensure
32
- $stdout = STDOUT
33
- end
34
-
35
15
  FakeWeb.allow_net_connect = false
36
16
 
37
-
38
17
  def fixture_file(filename)
39
18
  return '' if filename == ''
40
19
  file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
41
20
  File.read(file_path)
42
21
  end
43
22
 
44
-
45
23
  def stub_request(method, url, filename, status=nil)
46
24
  options = {:body => ""}
47
25
  options.merge!({:body => fixture_file(filename)}) if filename
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe SvxBox do
4
+ include SvxBox::Amazoni
5
+ include SvxBox::Lexicali
6
+
7
+ context "Amazoni" do
8
+ it "search_aaws should be callable" do
9
+ stub_get(%r|http://ecs\.amazonaws\.com/|, "amazon_response.xml")
10
+ result = search_aaws('Books','Ruby Programming')
11
+ #assert result.include?('buy')
12
+ end
13
+ end
14
+ context "Lexicali" do
15
+ it "search_aaws return a simple array" do
16
+ sample_text = fixture_file('sample_text.txt')
17
+ search = svxwc(sample_text, 2)
18
+ search.should == "application video"
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svxbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-11-19 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: nokogiri
17
- requirement: &76161000 !ruby/object:Gem::Requirement
16
+ requirement: &73080400 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *76161000
24
+ version_requirements: *73080400
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: amazon_product
28
- requirement: &76160760 !ruby/object:Gem::Requirement
27
+ requirement: &73079770 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,32 @@ dependencies:
33
32
  version: '0'
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *76160760
35
+ version_requirements: *73079770
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &73079220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *73079220
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &73078350 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *73078350
37
58
  - !ruby/object:Gem::Dependency
38
59
  name: shoulda
39
- requirement: &76160520 !ruby/object:Gem::Requirement
60
+ requirement: &73077680 !ruby/object:Gem::Requirement
40
61
  none: false
41
62
  requirements:
42
63
  - - ! '>='
@@ -44,31 +65,30 @@ dependencies:
44
65
  version: '0'
45
66
  type: :development
46
67
  prerelease: false
47
- version_requirements: *76160520
68
+ version_requirements: *73077680
48
69
  description: View the code.
49
70
  email: albert.lash@docunext.com
50
71
  executables: []
51
72
  extensions: []
52
73
  extra_rdoc_files:
53
74
  - LICENSE
75
+ - README.mkdn
54
76
  files:
77
+ - .travis.yml
78
+ - Gemfile
79
+ - Gemfile.lock
55
80
  - LICENSE
81
+ - README.mkdn
56
82
  - Rakefile
57
83
  - VERSION
58
84
  - lib/svxbox.rb
59
85
  - lib/svxbox/amazoni.rb
60
86
  - lib/svxbox/lexicali.rb
61
- - lib/svxbox/markupguppy.rb
62
- - lib/svxbox/mongobongo.rb
63
- - lib/svxbox/ponyboy.rb
64
- - lib/svxbox/sinatricus.rb
65
- - lib/svxbox/supabali.rb
66
- - test/fixtures/amazon_response.xml
67
- - test/fixtures/sample_text.txt
68
- - test/spec.opts
69
- - test/spec_helper.rb
70
- - test/svxbox_test.rb
71
- has_rdoc: true
87
+ - spec/fixtures/amazon_response.xml
88
+ - spec/fixtures/sample_text.txt
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ - spec/svxbox_spec.rb
72
92
  homepage: http://www.savonix.com
73
93
  licenses: []
74
94
  post_install_message:
@@ -89,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
109
  version: '0'
90
110
  requirements: []
91
111
  rubyforge_project: ''
92
- rubygems_version: 1.6.2
112
+ rubygems_version: 1.8.11
93
113
  signing_key:
94
114
  specification_version: 3
95
115
  summary: Miscellaneous Utilities.
@@ -1,40 +0,0 @@
1
- ###
2
- # Copyright: Savonix Corporation
3
- # Author: Albert Lash
4
- # License: Affero General Public License v3 or later
5
- ##
6
-
7
- module SvxBox
8
- module MarkupGuppy
9
-
10
- def goback
11
- '<input type="button" onclick="history.go(-1);" value="Go Back" />'
12
- end
13
-
14
- def pagetitle(string)
15
- '<h3 id="page-title">' << string << '</h3>' << "\n\n"
16
- end
17
-
18
- def mdlistlink(label,href)
19
- "* [#{label}](#{href})"
20
- end
21
-
22
- def humanize(text)
23
- return text.gsub('_',' ').gsub(/\b\w/){$&.upcase}
24
- end
25
-
26
- def svxbasename(text)
27
- return text.downcase.gsub(' ','_').gsub(/[^a-z0-9_]/,'')
28
- end
29
-
30
- def svxprevnext(svxprev,svxnext)
31
- npkg = ''
32
- npkg << "<span class=\"flrt\"><a href=\"#{svxnext}\">Next &#8250;</a></span>"
33
- npkg << "<a href=\"#{svxprev}\">&#8249; Previous</a>\n\n"
34
- end
35
-
36
- alias :svxbn :svxbasename
37
- alias :svxpn :svxprevnext
38
-
39
- end
40
- end
@@ -1,19 +0,0 @@
1
- ###
2
- # Copyright: Savonix Corporation
3
- # Author: Albert Lash
4
- # License: Affero General Public License v3 or later
5
- ##
6
-
7
- module SvxBox
8
- module MongoBongo
9
-
10
- def make_oid(oid)
11
- begin
12
- obj = BSON::ObjectId.from_string(oid)
13
- rescue
14
- halt 404
15
- end
16
- end
17
-
18
- end
19
- end
@@ -1,16 +0,0 @@
1
- ###
2
- # Copyright: Savonix Corporation
3
- # Author: Albert Lash
4
- # License: Affero General Public License v3 or later
5
- ##
6
- require 'pony'
7
-
8
- module SvxBox
9
- module PonyBoy
10
-
11
- def svx_email(to=nil,from='',subject='',text='')
12
- Pony.mail(:to => to, :from => from, :subject => subject, :body => text) unless to.nil?
13
- end
14
-
15
- end
16
- end
@@ -1,26 +0,0 @@
1
- ###
2
- # Copyright: Savonix Corporation
3
- # Author: Albert Lash
4
- # License: Affero General Public License v3 or later
5
- ##
6
-
7
- module SvxBox
8
- module Sinatricus
9
-
10
- # Just the usual Sinatra redirect with App prefix
11
- def mredirect(uri)
12
- redirect settings.uripfx+uri, 301
13
- end
14
-
15
- def svx_debug(msg=nil)
16
- unless ENV['RACK_ENV'] == 'production'
17
- puts msg unless msg.nil?
18
- puts yield if block_given?
19
- end
20
- end
21
- def svx_debug_t(msg=nil)
22
- svx_debug(msg) unless msg.nil?
23
- svx_debug { yield } if block_given?
24
- end
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- ###
2
- # Copyright: Savonix Corporation
3
- # Author: Albert Lash
4
- # License: Affero General Public License v3 or later
5
- ##
6
-
7
- module SvxBox
8
- module SupaBali
9
- include Lexicali
10
- include MarkupGuppy
11
-
12
- end
13
- end
data/test/svxbox_test.rb DELETED
@@ -1,60 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
2
-
3
- class SvxBoxTest < Test::Unit::TestCase
4
- context "MarkupGuppy" do
5
- setup do
6
- @huh = "ok"
7
- end
8
- should "goback should be callable" do
9
- result = goback
10
- result.should == '<input type="button" onclick="history.go(-1);" value="Go Back" />'
11
- end
12
- end
13
-
14
- context "Amazoni" do
15
- should "search_aaws should be callable" do
16
- stub_get(%r|http://ecs\.amazonaws\.com/|, "amazon_response.xml")
17
- result = search_aaws('Books','Ruby Programming')
18
- #assert result.include?('buy')
19
- end
20
- end
21
- context "Lexicali" do
22
- should "search_aaws return a simple array" do
23
- sample_text = fixture_file('sample_text.txt')
24
- search = svxwc(sample_text, 2)
25
- assert_equal search, "application video"
26
- end
27
- end
28
- context "Sinatricus" do
29
- should "put msg when in development mode" do
30
- ENV['RACK_ENV'] = 'development'
31
- result = copy_stdout do
32
- svx_debug('testing')
33
- end
34
- assert_equal "testing\n", result.string
35
- end
36
-
37
- should "process block as debug output" do
38
- ENV['RACK_ENV'] = 'development'
39
- result = copy_stdout do
40
- svx_debug { 'testing' }
41
- end
42
- assert_equal "testing\n", result.string
43
- end
44
- should "process block as debug output via chain" do
45
- ENV['RACK_ENV'] = 'development'
46
- result = copy_stdout do
47
- svx_debug_t { 'testing' }
48
- end
49
- assert_equal "testing\n", result.string
50
- end
51
-
52
- should "not put msg when in production mode" do
53
- ENV['RACK_ENV'] = 'production'
54
- result = copy_stdout do
55
- svx_debug('testing')
56
- end
57
- assert_equal '', result.string
58
- end
59
- end
60
- end