barnesandnoble 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -53
- data/lib/barnesandnoble.rb +3 -3
- data/lib/barnesandnoble/request.rb +38 -13
- data/lib/barnesandnoble/response.rb +4 -4
- data/lib/barnesandnoble/version.rb +2 -2
- data/test/test_barnesandnoble.rb +34 -36
- metadata +16 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cc2f0b5a0447a44bae1e893748b26a0ee9d635a
|
4
|
+
data.tar.gz: 7041259521e6cbe055e7aae5a9472412a17a2d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09bbf24da68e256f3b587ff0fc16e03b9936f83b029155b598195f0abe91b13f8e70a6a5ea50af4d75ed0f61caabe1fe03df5ab9ff693b796de106925ce6ffe4
|
7
|
+
data.tar.gz: 1e7dd5a7aed443de6b6403408c2c31f21a1f576e5e6c19f6fcf1e6b714f382ce4c7aafcc01461e74f0148148700c655bbdac4f556d56a96d6a549a16a7a65ff5
|
data/README.md
CHANGED
@@ -1,74 +1,35 @@
|
|
1
|
-
|
1
|
+
# Barnesandnoble
|
2
2
|
|
3
|
-
|
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:
|
3
|
+
**Barnesandnoble** is a Ruby wrapper to the Barnes and Noble Product Web Services.
|
23
4
|
|
24
|
-
|
25
|
-
params = {
|
26
|
-
'Ean' => 9781593083342,
|
27
|
-
'ProductCode' => 'Book'
|
28
|
-
}
|
29
|
-
res = req.get('GetCategories', params)
|
30
|
-
```
|
31
|
-
|
32
|
-
#### Get related bought products:
|
5
|
+
## Usage
|
33
6
|
|
34
|
-
|
35
|
-
params = {
|
36
|
-
'Ean' => 9781593083342,
|
37
|
-
'ProductCode' => 'Book'
|
38
|
-
}
|
39
|
-
res = req.get('GetPwbab', params)
|
40
|
-
```
|
7
|
+
Set your API key with the environment variable `BN_API_KEY`.
|
41
8
|
|
42
|
-
|
9
|
+
Create a request:
|
43
10
|
|
44
11
|
```ruby
|
45
|
-
|
46
|
-
'Top10SearchDomain' => 'Book',
|
47
|
-
}
|
48
|
-
res = req.get('Top10', params)
|
12
|
+
request = Barnesandnoble.new
|
49
13
|
```
|
50
14
|
|
51
|
-
|
15
|
+
Run a query:
|
52
16
|
|
53
17
|
```ruby
|
54
18
|
params = {
|
55
|
-
|
56
|
-
|
57
|
-
'Size': 5,
|
58
|
-
'ProductSort': 'BestSelling'
|
59
|
-
'Keyword': 'Foucault'
|
19
|
+
"Ean" => 9781593083342,
|
20
|
+
"ProductCode" => "Book"
|
60
21
|
}
|
61
|
-
|
22
|
+
response = request.product_lookup(query: params)
|
62
23
|
```
|
63
24
|
|
64
|
-
Parse the response into a
|
25
|
+
Parse the response into a Hash:
|
65
26
|
|
66
27
|
```ruby
|
67
|
-
|
28
|
+
response.to_h
|
68
29
|
```
|
69
30
|
|
70
|
-
Or pass
|
31
|
+
Or pass it to a custom parser:
|
71
32
|
|
72
33
|
```ruby
|
73
|
-
MyParser.new(
|
34
|
+
MyParser.new(response.body)
|
74
35
|
```
|
data/lib/barnesandnoble.rb
CHANGED
@@ -1,27 +1,52 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'uri'
|
1
|
+
require "excon"
|
2
|
+
require "barnesandnoble/response"
|
4
3
|
|
5
|
-
module
|
4
|
+
module Barnesandnoble
|
6
5
|
class Request
|
7
|
-
def initialize(app_id = ENV[
|
6
|
+
def initialize(app_id = ENV["BN_API_KEY"])
|
8
7
|
@app_id = app_id
|
9
8
|
end
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
underscore = ->(str) {
|
11
|
+
str.gsub(/(.)([A-Z\d])/,'\1_\2').downcase
|
12
|
+
}
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
%w(ProductLookup ProductSearch Top10 GetCategories GetPwbab)
|
15
|
+
.each do |operation|
|
16
|
+
define_method(underscore.(operation)) do |options|
|
17
|
+
get_product(operation, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
%w(GetTextBookRentalInfo)
|
22
|
+
.each do |operation|
|
23
|
+
define_method(underscore.(operation)) do |options|
|
24
|
+
get_textbook(operation, options)
|
25
|
+
end
|
26
|
+
end
|
16
27
|
|
17
28
|
private
|
18
29
|
|
19
|
-
def
|
20
|
-
|
30
|
+
def get_textbook(operation, options)
|
31
|
+
request(operation, options.merge(
|
32
|
+
path: "/TextBookService/v01_00/#{operation}"
|
33
|
+
))
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def get_product(operation, options)
|
38
|
+
request(operation, options.merge(
|
39
|
+
path: "/v03_00/#{operation}"
|
40
|
+
))
|
41
|
+
end
|
42
|
+
|
43
|
+
def request(operation, options)
|
44
|
+
options[:query]["AppId"] ||= @app_id
|
45
|
+
Response.new(http.get(options))
|
21
46
|
end
|
22
47
|
|
23
|
-
def
|
24
|
-
Excon.new("http://services.barnesandnoble.com
|
48
|
+
def http
|
49
|
+
Excon.new("http://services.barnesandnoble.com", expects: 200)
|
25
50
|
end
|
26
51
|
end
|
27
52
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "delegate"
|
2
|
+
require "multi_xml"
|
3
3
|
|
4
|
-
module
|
4
|
+
module Barnesandnoble
|
5
5
|
class Response < SimpleDelegator
|
6
6
|
def body
|
7
|
-
__getobj__.body.force_encoding(
|
7
|
+
__getobj__.body.force_encoding("ISO8859-1").encode("UTF-8")
|
8
8
|
end
|
9
9
|
|
10
10
|
def to_h
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION =
|
1
|
+
module Barnesandnoble
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
data/test/test_barnesandnoble.rb
CHANGED
@@ -1,71 +1,69 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "minitest/pride"
|
3
|
+
require "pry"
|
4
4
|
|
5
|
-
require_relative
|
5
|
+
require_relative "../lib/barnesandnoble"
|
6
6
|
|
7
|
-
class
|
7
|
+
class TestBarnesandnoble < Minitest::Test
|
8
8
|
def setup
|
9
|
-
@req =
|
9
|
+
@req = Barnesandnoble.new
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_product_lookup
|
13
|
-
res = @req.
|
14
|
-
|
15
|
-
|
13
|
+
res = @req.product_lookup(query: {
|
14
|
+
"Ean" => "9781593083342",
|
15
|
+
"ProductCode" => "Book"
|
16
16
|
})
|
17
|
-
|
18
17
|
refute_empty res.to_h
|
19
18
|
end
|
20
19
|
|
21
20
|
def test_get_categories
|
22
|
-
res = @req.
|
23
|
-
|
24
|
-
|
21
|
+
res = @req.get_categories(query: {
|
22
|
+
"Ean" => "9781593083342",
|
23
|
+
"ProductCode" => "Book"
|
25
24
|
})
|
26
|
-
|
27
25
|
refute_empty res.to_h
|
28
26
|
end
|
29
27
|
|
30
28
|
def test_people_who_bought_also_bought
|
31
|
-
skip
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
res = @req.get('GetPwbab', {
|
36
|
-
'Ean' => '9780345546883',
|
37
|
-
'ProductCode' => 'Book'
|
29
|
+
skip("Does not work")
|
30
|
+
res = @req.get_pwbab(query: {
|
31
|
+
"Ean" => "9780345546883",
|
32
|
+
"ProductCode" => "Book"
|
38
33
|
})
|
39
|
-
|
40
34
|
refute_empty res.to_h
|
41
35
|
end
|
42
36
|
|
43
37
|
def test_top_10
|
44
|
-
res = @req.
|
45
|
-
|
38
|
+
res = @req.top_10(query: {
|
39
|
+
"Top10SearchDomain" => "Book"
|
46
40
|
})
|
47
|
-
|
48
41
|
refute_empty res.to_h
|
49
42
|
end
|
50
43
|
|
51
44
|
def test_product_search
|
52
|
-
res = @req.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
45
|
+
res = @req.product_search(query: {
|
46
|
+
"SearchType" => "Book",
|
47
|
+
"Start" => 1,
|
48
|
+
"Size" => 5,
|
49
|
+
"ProductSort" => "Bestselling",
|
50
|
+
"Keyword" => "Deleuze"
|
58
51
|
})
|
52
|
+
refute_empty res.to_h
|
53
|
+
end
|
59
54
|
|
55
|
+
def test_get_text_book_rental_info
|
56
|
+
res = @req.get_text_book_rental_info(query: {
|
57
|
+
"Ean" => "9781118230718"
|
58
|
+
})
|
60
59
|
refute_empty res.to_h
|
61
60
|
end
|
62
61
|
|
63
62
|
def test_handles_unicode_characters
|
64
|
-
res = @req.
|
65
|
-
|
66
|
-
|
63
|
+
res = @req.product_lookup(query: {
|
64
|
+
"ProductCode" => "Book",
|
65
|
+
"Ean" => "0942299663"
|
67
66
|
})
|
68
|
-
|
69
|
-
assert_equal 'La Jetée', res.to_h['ProductLookupResponse']['ProductLookupResult']['Product']['Titles']['Title']['title']
|
67
|
+
assert_equal "La Jetée", res.to_h["ProductLookupResponse"]["ProductLookupResult"]["Product"]["Titles"]["Title"]["title"]
|
70
68
|
end
|
71
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barnesandnoble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Marquez
|
8
|
+
- Hakan Ensari
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: multi_xml
|
@@ -16,82 +17,68 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 0.5.5
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 0.5.5
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: excon
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - ">="
|
39
40
|
- !ruby/object:Gem::Version
|
40
41
|
version: '0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: minitest
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '0'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - ">="
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '0'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rake
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - ">="
|
67
68
|
- !ruby/object:Gem::Version
|
68
69
|
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
70
|
- !ruby/object:Gem::Dependency
|
84
71
|
name: pry
|
85
72
|
requirement: !ruby/object:Gem::Requirement
|
86
73
|
requirements:
|
87
|
-
- - "
|
74
|
+
- - ">="
|
88
75
|
- !ruby/object:Gem::Version
|
89
76
|
version: '0'
|
90
77
|
type: :development
|
91
78
|
prerelease: false
|
92
79
|
version_requirements: !ruby/object:Gem::Requirement
|
93
80
|
requirements:
|
94
|
-
- - "
|
81
|
+
- - ">="
|
95
82
|
- !ruby/object:Gem::Version
|
96
83
|
version: '0'
|
97
84
|
description:
|
@@ -128,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
115
|
version: '0'
|
129
116
|
requirements: []
|
130
117
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.3.0
|
132
119
|
signing_key:
|
133
120
|
specification_version: 4
|
134
121
|
summary: A Ruby wrapper for Barnes and Noble Product Web Services
|