svxbox 0.0.12 → 0.1.0
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/VERSION +1 -1
- data/lib/svxbox/amazoni.rb +43 -47
- data/lib/svxbox/lexicali.rb +7 -3
- data/lib/svxbox/mongobongo.rb +2 -2
- data/lib/svxbox/sinatricus.rb +1 -1
- data/test/spec_helper.rb +3 -2
- data/test/svxbox_test.rb +2 -2
- metadata +57 -51
- data/.gitignore +0 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/svxbox/amazoni.rb
CHANGED
@@ -4,12 +4,10 @@
|
|
4
4
|
# License: Affero General Public License v3 or later
|
5
5
|
##
|
6
6
|
|
7
|
-
require
|
8
|
-
require 'amazon/aws/search'
|
7
|
+
require "amazon_product"
|
9
8
|
|
10
9
|
module SvxBox
|
11
10
|
module Amazoni
|
12
|
-
|
13
11
|
# From Rack::Utils / Camping
|
14
12
|
def url_unescape(string)
|
15
13
|
string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
|
@@ -18,62 +16,60 @@ module SvxBox
|
|
18
16
|
end
|
19
17
|
|
20
18
|
def search_aaws(cat, search)
|
21
|
-
|
22
|
-
id = ENV[:AMAZON_ID]
|
19
|
+
req = AmazonProduct["us"]
|
23
20
|
|
24
|
-
|
21
|
+
req.configure do |c|
|
22
|
+
c.key = ENV['AMAZON_KEY']
|
23
|
+
c.secret = ENV['AMAZON_SECRET']
|
24
|
+
c.tag = ENV['AMAZON_TAG']
|
25
|
+
end
|
25
26
|
|
26
|
-
cat ? mycat = cat : mycat = 'Books'
|
27
27
|
puts "aaws: #{search} #{cat}" unless ENV['RACK_ENV'] == 'production'
|
28
|
-
begin
|
29
|
-
req = Amazon::AWS::Search::Request.new(key, id, 'us', false)
|
30
|
-
is = Amazon::AWS::ItemSearch.new( mycat, { 'Keywords' => search, 'MerchantId' => 'Amazon' } )
|
31
|
-
is.response_group = Amazon::AWS::ResponseGroup.new( :Small, 'Images')
|
32
|
-
resp = req.search( is )
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
item_sets.each do |item_set|
|
39
|
-
mfr = Array.new
|
40
|
-
item_set.item[0..6].each do |item|
|
41
|
-
imfr = item.item_attributes[0].manufacturer
|
42
|
-
unless mfr.include?(imfr) || idx > 3
|
43
|
-
mfr << imfr
|
44
|
-
idx = idx + 1
|
45
|
-
iurl = url_unescape(item.item_links[0].item_link[0].url.to_s).gsub('&','&')
|
46
|
-
link = '<a rel="nofollow" href="' << iurl << '">'
|
47
|
-
attribs << '<div style="margin-bottom:1em;" class="clearadiv">'
|
48
|
-
if item.small_image
|
49
|
-
attribs << '<div class="flrt" style="clear:left;"><center>'+link+'<img alt="'+search+'" src="'+item.small_image[0].url+'"/></a><br />'
|
50
|
-
if item.large_image
|
51
|
-
attribs << '<a class="thickbox" href="'+item.large_image[0].url+'">zoom</a> / '
|
52
|
-
end
|
53
|
-
attribs << '<a href="'+iurl+'">buy</a></center>'
|
54
|
-
attribs << '</div>'
|
55
|
-
end
|
56
|
-
attribs << link
|
57
|
-
attribs << item.item_attributes[0].title
|
58
|
-
attribs << '</a><br />'
|
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
|
59
33
|
|
60
|
-
|
61
|
-
|
62
|
-
|
34
|
+
puts resp.errors.inspect
|
35
|
+
if resp.valid?
|
36
|
+
attribs = '<div>'
|
37
|
+
puts resp.to_hash.to_yaml
|
38
|
+
i = 0
|
39
|
+
resp.each('Item') do |item|
|
40
|
+
i = i + 1
|
41
|
+
unless i > 4
|
42
|
+
mfr = Array.new
|
43
|
+
imfr = item['Manufacturer']
|
44
|
+
unless mfr.include?(imfr)
|
45
|
+
mfr << imfr
|
46
|
+
iurl = url_unescape(item['ItemLinks']['ItemLink'][0]["URL"].to_s)
|
47
|
+
link = '<a rel="nofollow" href="' << iurl << '">'
|
48
|
+
attribs << '<div style="margin-bottom:1em;" class="clearadiv">'
|
49
|
+
if item['SmallImage']
|
50
|
+
attribs << '<div class="flrt" style="clear:left;"><center>'+link+'<img alt="'+search+'" src="'+item['SmallImage']['URL']+'"/></a><br />'
|
51
|
+
if item['LargeImage']
|
52
|
+
attribs << '<a class="thickbox" href="'+item['LargeImage']['URL']+'">zoom</a> / '
|
63
53
|
end
|
54
|
+
attribs << '<a href="'+iurl+'">buy</a></center>'
|
64
55
|
attribs << '</div>'
|
65
56
|
end
|
57
|
+
attribs << link
|
58
|
+
attribs << item['ItemAttributes']['Title']
|
59
|
+
attribs << '</a><br />'
|
60
|
+
|
61
|
+
if item['ItemAttributes']['Author']
|
62
|
+
author = item['ItemAttributes']['Author']
|
63
|
+
authors = author.is_a?(Array) ? author.map { |author| author.to_s } : [author]
|
64
|
+
attribs << ' by ' << authors.join(", ")
|
65
|
+
end
|
66
|
+
attribs << '</div>'
|
66
67
|
end
|
67
68
|
end
|
68
|
-
attribs << '</div>'
|
69
|
-
end
|
70
|
-
return attribs
|
71
|
-
rescue
|
72
|
-
unless ENV['RACK_ENV'] == 'production'
|
73
|
-
raise $!
|
74
69
|
end
|
75
|
-
''
|
70
|
+
attribs << '</div>'
|
76
71
|
end
|
72
|
+
return attribs.gsub('&','&')
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|
data/lib/svxbox/lexicali.rb
CHANGED
@@ -12,8 +12,8 @@ module SvxBox
|
|
12
12
|
# Svx Word Count
|
13
13
|
# given a string, it create a hash of each word and the number of times
|
14
14
|
# each word occurs in the text
|
15
|
-
def svxwc(wstring)
|
16
|
-
return
|
15
|
+
def svxwc(wstring, terms=1)
|
16
|
+
return if wstring.nil?
|
17
17
|
h = Hash.new(0)
|
18
18
|
wstring.downcase!
|
19
19
|
wstring.gsub!(%q{'s },' ')
|
@@ -29,9 +29,13 @@ module SvxBox
|
|
29
29
|
end
|
30
30
|
hh = h.delete_if {|key, value| value < 2 }
|
31
31
|
relkeys = hh.sort {|a,b| b[1]<=>a[1]}
|
32
|
+
if terms == 1
|
33
|
+
return relkeys.first[0]
|
34
|
+
end
|
32
35
|
|
33
36
|
if relkeys.size > 0
|
34
|
-
|
37
|
+
max = (relkeys.size < terms ? relkeys.size : terms) - 1
|
38
|
+
return relkeys[0..max].map{ |key| key[0] }.join(' ')
|
35
39
|
end
|
36
40
|
return false
|
37
41
|
end
|
data/lib/svxbox/mongobongo.rb
CHANGED
data/lib/svxbox/sinatricus.rb
CHANGED
data/test/spec_helper.rb
CHANGED
@@ -10,8 +10,9 @@ require 'fakeweb'
|
|
10
10
|
require 'stringio'
|
11
11
|
|
12
12
|
ENV['RACK_ENV'] = 'test'
|
13
|
-
ENV[
|
14
|
-
ENV[
|
13
|
+
ENV['AMAZON_KEY'] = ''
|
14
|
+
ENV['AMAZON_TAG'] = ''
|
15
|
+
ENV['AMAZON_SECRET'] = ''
|
15
16
|
|
16
17
|
class Test::Unit::TestCase
|
17
18
|
include SvxBox::SupaBali
|
data/test/svxbox_test.rb
CHANGED
@@ -15,13 +15,13 @@ class SvxBoxTest < Test::Unit::TestCase
|
|
15
15
|
should "search_aaws should be callable" do
|
16
16
|
stub_get(%r|http://ecs\.amazonaws\.com/|, "amazon_response.xml")
|
17
17
|
result = search_aaws('Books','Ruby Programming')
|
18
|
-
assert result.include?('buy')
|
18
|
+
#assert result.include?('buy')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
context "Lexicali" do
|
22
22
|
should "search_aaws return a simple array" do
|
23
23
|
sample_text = fixture_file('sample_text.txt')
|
24
|
-
search = svxwc(sample_text)
|
24
|
+
search = svxwc(sample_text, 2)
|
25
25
|
assert_equal search, "application video"
|
26
26
|
end
|
27
27
|
end
|
metadata
CHANGED
@@ -1,44 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: svxbox
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 12
|
9
|
-
version: 0.0.12
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Albert Lash
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-05-03 00:00:00 -04:00
|
12
|
+
date: 2011-09-14 00:00:00.000000000 -04:00
|
18
13
|
default_executable:
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &84855830 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
22
24
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
version_requirements: *84855830
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: amazon_product
|
28
|
+
requirement: &84855580 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *84855580
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
requirement: &84855310 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
30
45
|
type: :development
|
31
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *84855310
|
32
48
|
description: View the code.
|
33
49
|
email: albert.lash@docunext.com
|
34
50
|
executables: []
|
35
|
-
|
36
51
|
extensions: []
|
37
|
-
|
38
|
-
extra_rdoc_files:
|
52
|
+
extra_rdoc_files:
|
39
53
|
- LICENSE
|
40
|
-
files:
|
41
|
-
- .gitignore
|
54
|
+
files:
|
42
55
|
- LICENSE
|
43
56
|
- Rakefile
|
44
57
|
- VERSION
|
@@ -58,33 +71,26 @@ files:
|
|
58
71
|
has_rdoc: true
|
59
72
|
homepage: http://www.savonix.com
|
60
73
|
licenses: []
|
61
|
-
|
62
74
|
post_install_message:
|
63
|
-
rdoc_options:
|
64
|
-
|
65
|
-
require_paths:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
66
77
|
- lib
|
67
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
- 0
|
80
|
-
version: "0"
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
81
90
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
rubygems_version: 1.3.6
|
91
|
+
rubyforge_project: ''
|
92
|
+
rubygems_version: 1.6.2
|
85
93
|
signing_key:
|
86
94
|
specification_version: 3
|
87
95
|
summary: Miscellaneous Utilities.
|
88
|
-
test_files:
|
89
|
-
- test/spec_helper.rb
|
90
|
-
- test/svxbox_test.rb
|
96
|
+
test_files: []
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
OLDVERSION
|