barnesandnoble 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db17520069852a3d44e1208ba800034538fb7e9b
4
+ data.tar.gz: 6fc45725162b7ace4fc9d9bba491bf5242f72cd7
5
+ SHA512:
6
+ metadata.gz: dd37b7f8eb3d12a6ef43b90e230c05fbd37a192746aadf9d7a48c0d5ac0cccca440c0dc044931b4487e2c5b759c7d58116adc5a73dd837eca86c1e9d193299c6
7
+ data.tar.gz: 2915c69ff4529ae1567c271065f919ae00e38386021520be2949c1fbad98db13b109e94fba0caa0fb460775765977b123a2c15b0a9b614fe1950f708e7e92de5
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2014 Diego Marquez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
1
+ **BarnesAndNoble** is a Ruby wrapper to the Barnes and Noble Product Web Services
2
+
3
+ ## Usage
4
+
5
+ Set your API key in the environment variable BN_API_KEY
6
+
7
+ ### Create a request:
8
+
9
+ ```ruby
10
+ req = BarnesAndNoble.new
11
+ ```
12
+ #### Run a product lookup:
13
+
14
+ ```ruby
15
+ params = {
16
+ 'Ean' => 9781593083342,
17
+ 'ProductCode' => 'Book'
18
+ }
19
+ res = req.get('ProductLookup', params)
20
+ ```
21
+
22
+ #### Get categories for a product:
23
+
24
+ ```ruby
25
+ params = {
26
+ 'Ean' => 9781593083342,
27
+ 'ProductCode' => 'Book'
28
+ }
29
+ res = req.get('GetCategories', params)
30
+ ```
31
+
32
+ #### Get related bought products:
33
+
34
+ ```ruby
35
+ params = {
36
+ 'Ean' => 9781593083342,
37
+ 'ProductCode' => 'Book'
38
+ }
39
+ res = req.get('GetPwbab', params)
40
+ ```
41
+
42
+ #### Get Top10 :
43
+
44
+ ```ruby
45
+ params = {
46
+ 'Top10SearchDomain' => 'Book',
47
+ }
48
+ res = req.get('Top10', params)
49
+ ```
50
+
51
+ #### Run a products search by keywords:
52
+
53
+ ```ruby
54
+ params = {
55
+ 'SearchType': 'Book',
56
+ 'Start': 1,
57
+ 'Size': 5,
58
+ 'ProductSort': 'BestSelling'
59
+ 'Keyword': 'Foucault'
60
+ }
61
+ res = req.get('ProductSearch', params)
62
+ ```
63
+
64
+ Parse the response into a Ruby Hash:
65
+
66
+ ```ruby
67
+ res.to_h
68
+ ```
69
+
70
+ Or pass its body into a custom parser:
71
+
72
+ ```ruby
73
+ MyParser.new(res.body)
74
+ ```
@@ -0,0 +1,10 @@
1
+ require 'forwardable'
2
+ require 'barnesandnoble/request'
3
+
4
+ module BarnesAndNoble
5
+ class << self
6
+ extend Forwardable
7
+
8
+ def_delegator Request, :new
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require 'excon'
2
+ require 'barnesandnoble/response'
3
+ require 'uri'
4
+
5
+ module BarnesAndNoble
6
+ class Request
7
+ def initialize(app_id = ENV['BN_API_KEY'])
8
+ @app_id = app_id
9
+ end
10
+
11
+ def get(method, query, excon_options = {})
12
+ query['AppId'] = @app_id
13
+
14
+ Response.new(connection(method, query).get(excon_options))
15
+ end
16
+
17
+ private
18
+
19
+ def hash_to_query(hash)
20
+ '?' + URI.encode(hash.map{|k,v| "#{k}=#{v}"}.join("&"))
21
+ end
22
+
23
+ def connection(request_type, query)
24
+ Excon.new("http://services.barnesandnoble.com/v03_00/#{request_type}#{hash_to_query(query)}", expects: 200)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'delegate'
2
+ require 'multi_xml'
3
+
4
+ module BarnesAndNoble
5
+ class Response < SimpleDelegator
6
+ def to_h
7
+ MultiXml.parse(body)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module BarnesAndNoble
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,61 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'pry'
4
+ require_relative '../lib/barnesandnoble'
5
+
6
+ class TestBarnesAndNoble < Minitest::Unit::TestCase
7
+ def setup
8
+ @req = BarnesAndNoble::Request.new
9
+ end
10
+
11
+ def test_product_lookup
12
+ res = @req.get('ProductLookup', {
13
+ 'Ean' => '9781593083342',
14
+ 'ProductCode' => 'Book'
15
+ })
16
+
17
+ refute_empty res.to_h
18
+ end
19
+
20
+ def test_get_categories
21
+ res = @req.get('GetCategories', {
22
+ 'Ean' => '9781593083342',
23
+ 'ProductCode' => 'Book'
24
+ })
25
+
26
+ refute_empty res.to_h
27
+ end
28
+
29
+ def test_people_who_bought_also_bought
30
+ skip
31
+
32
+ # The query is correct, but this method doesn't seem to be working
33
+
34
+ res = @req.get('GetPwbab', {
35
+ 'Ean' => '9780345546883',
36
+ 'ProductCode' => 'Book'
37
+ })
38
+
39
+ refute_empty res.to_h
40
+ end
41
+
42
+ def test_top_10
43
+ res = @req.get('Top10', {
44
+ 'Top10SearchDomain' => 'Book'
45
+ })
46
+
47
+ refute_empty res.to_h
48
+ end
49
+
50
+ def test_product_search
51
+ res = @req.get('ProductSearch', {
52
+ 'SearchType' => 'Book',
53
+ 'Start' => 1,
54
+ 'Size' => 5,
55
+ 'ProductSort' => 'Bestselling',
56
+ 'Keyword' => 'Deleuze'
57
+ })
58
+
59
+ refute_empty res.to_h
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barnesandnoble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Diego Marquez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_xml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: excon
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dotenv-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - marquez.diego.e@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE
105
+ - README.md
106
+ - lib/barnesandnoble.rb
107
+ - lib/barnesandnoble/request.rb
108
+ - lib/barnesandnoble/response.rb
109
+ - lib/barnesandnoble/version.rb
110
+ - test/test_barnesandnoble.rb
111
+ homepage: https://github.com/diegomarquez/barnesandnoble
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '1.9'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.2.2
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: A Ruby wrapper for Barnes and Noble Product Web Services
135
+ test_files:
136
+ - test/test_barnesandnoble.rb
137
+ has_rdoc: