svxbox 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.1.0
@@ -4,12 +4,10 @@
4
4
  # License: Affero General Public License v3 or later
5
5
  ##
6
6
 
7
- require 'amazon/aws'
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
- key = ENV[:AMAZON_KEY]
22
- id = ENV[:AMAZON_ID]
19
+ req = AmazonProduct["us"]
23
20
 
24
- return unless (key && id)
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
- if resp.item_search_response[0]
35
- idx = 0
36
- item_sets = resp.item_search_response[0].items
37
- attribs = '<div>'
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('&','&amp;')
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
- if item.item_attributes[0].author
61
- authors = item.item_attributes[0].author.map { |author| author.to_s }
62
- attribs << ' by ' << authors.join(", ")
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('&','&amp;')
77
73
  end
78
74
  end
79
75
  end
@@ -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 unless wstring.is_a?(String)
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
- return relkeys[0..1].map{ |key| key[0] }.join(' ')
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
@@ -9,8 +9,8 @@ module SvxBox
9
9
 
10
10
  def make_oid(oid)
11
11
  begin
12
- obj = Mongo::ObjectID.from_string(oid)
13
- rescue Mongo::InvalidObjectID
12
+ obj = BSON::ObjectId.from_string(oid)
13
+ rescue
14
14
  halt 404
15
15
  end
16
16
  end
@@ -13,7 +13,7 @@ module SvxBox
13
13
  end
14
14
 
15
15
  def svx_debug(msg=nil)
16
- unless settings.environment == 'production'
16
+ unless ENV['RACK_ENV'] == 'production'
17
17
  puts msg unless msg.nil?
18
18
  puts yield if block_given?
19
19
  end
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[:AMAZON_KEY] = ''
14
- ENV[:AMAZON_ID] = ''
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
- prerelease: false
5
- segments:
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: shoulda
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
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
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
- version_requirements: *id001
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
- - --charset=UTF-8
65
- require_paths:
75
+ rdoc_options: []
76
+ require_paths:
66
77
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- segments:
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
- rubyforge_project: ""
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