asin 0.0.6 → 0.0.7

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.
Files changed (5) hide show
  1. data/README.rdoc +41 -0
  2. data/lib/asin.rb +4 -2
  3. data/test/test_asin.rb +10 -0
  4. metadata +10 -11
  5. data/readme.textile +0 -32
data/README.rdoc ADDED
@@ -0,0 +1,41 @@
1
+ = Introduction
2
+
3
+ There is already a sophisticated amazon gem out there called ruby-aaws[http://raa.ruby-lang.org/project/ruby-aws/], but ASIN in comparison is _reaaaaaaaaaly_ easy to use!
4
+
5
+ It currently just supports the _ItemLookup_ via REST but is easy to extend and understand!
6
+
7
+ Have a look at the RDOC[http://rdoc.info/projects/phoet/asin] for this project, if you want further information.
8
+
9
+ For more information on the REST calls, have a look at the whole Amazon E-Commerce-API[http://docs.amazonwebservices.com/AWSEcommerceService/4-0/].
10
+
11
+ The code currently runs best on Ruby-1.9 due to encoding issues with the Amazon REST output (if *YOU* know how to backport this to 1.8.7, you are welcome!).
12
+
13
+ == Installation
14
+
15
+ The gem is tested against 1.9.1 (to be compatible with Heroku Bamboo Stack) and somewhat against 1.8.7.
16
+
17
+ rvm use 1.9.1
18
+ gem install asin
19
+
20
+ == Usage
21
+
22
+ require 'asin'
23
+ include ASIN
24
+
25
+ # use the configure method to setup your api credentials
26
+ configure :secret => 'your-secret', :key => 'your-key'
27
+
28
+ # lookup an item with the amazon standard identification number (asin)
29
+ item = lookup '1430218150'
30
+
31
+ # have a look at the title of the item
32
+ item.title
33
+ => Learn Objective-C on the Mac (Learn Series)
34
+
35
+ # access the internal data representation (Hashie::Mash)
36
+ item.raw.ItemAttributes.ListPrice.FormattedPrice
37
+ => $39.99
38
+
39
+ == TODO
40
+
41
+ * Logging
data/lib/asin.rb CHANGED
@@ -84,7 +84,7 @@ module ASIN
84
84
  :digest => OpenSSL::Digest::Digest.new('sha256'),
85
85
  :key => '',
86
86
  :secret => '',
87
- }
87
+ } if @options.nil?
88
88
  @options.merge! options
89
89
  end
90
90
 
@@ -112,7 +112,9 @@ module ASIN
112
112
  raise "you have to configure ASIN: 'configure :secret => 'your-secret', :key => 'your-key''" if @options.nil?
113
113
  signed = create_signed_query_string(params)
114
114
  resp = HTTPClient.new.get_content("http://#{@options[:host]}#{@options[:path]}?#{signed}")
115
- resp = resp.force_encoding('UTF-8') # shady workaround cause amazon returns bad utf-8 chars
115
+ if(resp.respond_to? :force_encoding)
116
+ resp = resp.force_encoding('UTF-8') # force utf-8 chars, works only on 1.9 string
117
+ end
116
118
  Crack::XML.parse(resp)
117
119
  end
118
120
 
data/test/test_asin.rb CHANGED
@@ -13,11 +13,21 @@ class TestAsin < Test::Unit::TestCase
13
13
  secret = ENV['ASIN_SECRET']
14
14
  key = ENV['ASIN_KEY']
15
15
  puts "configure #{secret} and #{key} for this test"
16
+
16
17
  @helper.configure :secret => secret, :key => key
17
18
  p item = @helper.lookup(ANY_ASIN)
18
19
  assert_match(/Learn Objective/, item.title)
19
20
  end
20
21
 
22
+ def test_configure_second_time_wont_get_overridden
23
+ config = @helper.configure :something => 'wont get overridden'
24
+ assert_not_nil(config[:something])
25
+
26
+ config = @helper.configure :different => 'is also set'
27
+ assert_not_nil(config[:something])
28
+ assert_not_nil(config[:different])
29
+ end
30
+
21
31
  def test_error_with_not_called_configure
22
32
  assert_raise(RuntimeError) { @helper.lookup ANY_ASIN }
23
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Peter Schr\xC3\xB6der"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-13 00:00:00 +02:00
18
+ date: 2010-07-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -72,13 +72,13 @@ executables: []
72
72
 
73
73
  extensions: []
74
74
 
75
- extra_rdoc_files:
76
- - readme.textile
75
+ extra_rdoc_files: []
76
+
77
77
  files:
78
78
  - lib/asin.rb
79
+ - README.rdoc
79
80
  - test/test_asin.rb
80
81
  - test/test_helper.rb
81
- - readme.textile
82
82
  has_rdoc: true
83
83
  homepage: http://github.com/phoet/asin
84
84
  licenses: []
@@ -95,11 +95,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="
97
97
  - !ruby/object:Gem::Version
98
- hash: 29
98
+ hash: 3
99
99
  segments:
100
- - 1
101
- - 9
102
- version: "1.9"
100
+ - 0
101
+ version: "0"
103
102
  required_rubygems_version: !ruby/object:Gem::Requirement
104
103
  none: false
105
104
  requirements:
data/readme.textile DELETED
@@ -1,32 +0,0 @@
1
- h1. Introduction
2
-
3
- There is already a sophisticated amazon gem out there called "ruby-aaws":http://raa.ruby-lang.org/project/ruby-aws/, but ASIN in comparison is __reaaaaaaaaaly easy to use!__
4
-
5
- It currently just supports the _ItemLookup_ via REST but is easy to extend and understand!
6
-
7
- If you want to have a look at "the whole Amazon E-Commerce-API go here":http://docs.amazonwebservices.com/AWSEcommerceService/4-0/.
8
-
9
- The code currently runs only on __Ruby 1.9__ due to encoding issues with the Amazon REST output (if YOU know how to backport this, you are welcome!).
10
-
11
- h2. Usage
12
-
13
- <pre lang="ruby">
14
- require 'asin'
15
- include ASIN
16
- # use the configure method to setup your api credentials
17
- configure :secret => 'your-secret', :key => 'your-key'
18
- # lookup an item with the amazon standard identification number (asin)
19
- item = lookup '1430218150'
20
- # have a look at the title of the item
21
- item.title
22
- => Learn Objective-C on the Mac (Learn Series)
23
- # access the internal data representation (Hashie::Mash)
24
- item.raw.ItemAttributes.ListPrice.FormattedPrice
25
- => $39.99
26
- </pre>
27
-
28
- h2. TODO
29
-
30
- * Logging
31
- * More Docs
32
- * More Tests