barnesandnoble 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/barnesandnoble.rb +4 -2
- data/lib/barnesandnoble/request.rb +22 -21
- data/lib/barnesandnoble/response.rb +5 -3
- data/lib/barnesandnoble/version.rb +3 -1
- data/test/test_barnesandnoble.rb +27 -28
- metadata +8 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 844e3e17adb55bc5205785195d3f5c747d2b23ae610a68fdcd6612562c947e14
|
4
|
+
data.tar.gz: f42906761a5855573c8118bc0288bc1ba0232380a9592636c4bd1bc5f16c8fe2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0943217a0d1ff028fa566e7a1065077876706602894989f036bd3df562056234398ec700b955365a37082c3f69a0aaa4159d272c7fc020265c8d39a9540cfa45'
|
7
|
+
data.tar.gz: e816303077bf041614cf076b4a85f449bf806507f3edc6ea01264ff1290d61431f8a8a2d14402f0e87bb15da096fa65144e56588387beaa27c7ae3a5901051a0
|
data/lib/barnesandnoble.rb
CHANGED
@@ -1,52 +1,53 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'excon'
|
4
|
+
require 'barnesandnoble/response'
|
3
5
|
|
4
6
|
module Barnesandnoble
|
5
7
|
class Request
|
6
|
-
def initialize(app_id = ENV[
|
8
|
+
def initialize(app_id = ENV['BN_API_KEY'])
|
7
9
|
@app_id = app_id
|
8
10
|
end
|
9
11
|
|
10
|
-
underscore =
|
11
|
-
str.gsub(/(.)([A-Z\d])/,'\1_\2').downcase
|
12
|
+
underscore = lambda { |str|
|
13
|
+
str.gsub(/(.)([A-Z\d])/, '\1_\2').downcase
|
12
14
|
}
|
13
15
|
|
14
|
-
%w
|
16
|
+
%w[ProductLookup ProductSearch Top10 GetCategories GetPwbab]
|
15
17
|
.each do |operation|
|
16
|
-
define_method(underscore.(operation)) do |options|
|
17
|
-
|
18
|
+
define_method(underscore.call(operation)) do |options|
|
19
|
+
request_product(operation, options)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
%w
|
23
|
+
%w[GetTextBookRentalInfo]
|
22
24
|
.each do |operation|
|
23
|
-
define_method(underscore.(operation)) do |options|
|
24
|
-
|
25
|
+
define_method(underscore.call(operation)) do |options|
|
26
|
+
request_textbook(operation, options)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
private
|
29
31
|
|
30
|
-
def
|
32
|
+
def request_textbook(operation, options)
|
31
33
|
request(operation, options.merge(
|
32
|
-
|
33
|
-
|
34
|
+
path: "/TextBookService/v01_00/#{operation}"
|
35
|
+
))
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
def get_product(operation, options)
|
38
|
+
def request_product(operation, options)
|
38
39
|
request(operation, options.merge(
|
39
|
-
|
40
|
-
|
40
|
+
path: "/v03_00/#{operation}"
|
41
|
+
))
|
41
42
|
end
|
42
43
|
|
43
|
-
def request(
|
44
|
-
options[:query][
|
44
|
+
def request(_operation, options)
|
45
|
+
options[:query]['AppId'] ||= @app_id
|
45
46
|
Response.new(http.get(options))
|
46
47
|
end
|
47
48
|
|
48
49
|
def http
|
49
|
-
Excon.new(
|
50
|
+
Excon.new('http://services.barnesandnoble.com', expects: 200)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'delegate'
|
4
|
+
require 'multi_xml'
|
3
5
|
|
4
6
|
module Barnesandnoble
|
5
7
|
class Response < SimpleDelegator
|
6
8
|
def body
|
7
|
-
__getobj__.body.force_encoding(
|
9
|
+
__getobj__.body.force_encoding('ISO8859-1').encode('UTF-8')
|
8
10
|
end
|
9
11
|
|
10
12
|
def to_h
|
data/test/test_barnesandnoble.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
require "minitest/pride"
|
3
|
-
require "pry"
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative '../lib/barnesandnoble'
|
6
5
|
|
7
6
|
class TestBarnesandnoble < Minitest::Test
|
8
7
|
def setup
|
@@ -11,59 +10,59 @@ class TestBarnesandnoble < Minitest::Test
|
|
11
10
|
|
12
11
|
def test_product_lookup
|
13
12
|
res = @req.product_lookup(query: {
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
'Ean' => '9781593083342',
|
14
|
+
'ProductCode' => 'Book'
|
15
|
+
})
|
17
16
|
refute_empty res.to_h
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_get_categories
|
21
20
|
res = @req.get_categories(query: {
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
'Ean' => '9781593083342',
|
22
|
+
'ProductCode' => 'Book'
|
23
|
+
})
|
25
24
|
refute_empty res.to_h
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_people_who_bought_also_bought
|
29
|
-
skip(
|
28
|
+
skip('Does not work')
|
30
29
|
res = @req.get_pwbab(query: {
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
'Ean' => '9780345546883',
|
31
|
+
'ProductCode' => 'Book'
|
32
|
+
})
|
34
33
|
refute_empty res.to_h
|
35
34
|
end
|
36
35
|
|
37
36
|
def test_top_10
|
38
37
|
res = @req.top_10(query: {
|
39
|
-
|
40
|
-
|
38
|
+
'Top10SearchDomain' => 'Book'
|
39
|
+
})
|
41
40
|
refute_empty res.to_h
|
42
41
|
end
|
43
42
|
|
44
43
|
def test_product_search
|
45
44
|
res = @req.product_search(query: {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
'SearchType' => 'Book',
|
46
|
+
'Start' => 1,
|
47
|
+
'Size' => 5,
|
48
|
+
'ProductSort' => 'Bestselling',
|
49
|
+
'Keyword' => 'Deleuze'
|
50
|
+
})
|
52
51
|
refute_empty res.to_h
|
53
52
|
end
|
54
53
|
|
55
54
|
def test_get_text_book_rental_info
|
56
55
|
res = @req.get_text_book_rental_info(query: {
|
57
|
-
|
58
|
-
|
56
|
+
'Ean' => '9781118230718'
|
57
|
+
})
|
59
58
|
refute_empty res.to_h
|
60
59
|
end
|
61
60
|
|
62
61
|
def test_handles_unicode_characters
|
63
62
|
res = @req.product_lookup(query: {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
assert_equal
|
63
|
+
'ProductCode' => 'Book',
|
64
|
+
'Ean' => '0942299663'
|
65
|
+
})
|
66
|
+
assert_equal 'La Jetée', res.to_h['ProductLookupResponse']['ProductLookupResult']['Product']['Titles']['Title']['title']
|
68
67
|
end
|
69
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barnesandnoble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Marquez
|
@@ -9,22 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: multi_xml
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 0.5.5
|
21
|
-
type: :runtime
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: 0.5.5
|
28
14
|
- !ruby/object:Gem::Dependency
|
29
15
|
name: excon
|
30
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,13 +26,13 @@ dependencies:
|
|
40
26
|
- !ruby/object:Gem::Version
|
41
27
|
version: '0'
|
42
28
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
29
|
+
name: multi_xml
|
44
30
|
requirement: !ruby/object:Gem::Requirement
|
45
31
|
requirements:
|
46
32
|
- - ">="
|
47
33
|
- !ruby/object:Gem::Version
|
48
34
|
version: '0'
|
49
|
-
type: :
|
35
|
+
type: :runtime
|
50
36
|
prerelease: false
|
51
37
|
version_requirements: !ruby/object:Gem::Requirement
|
52
38
|
requirements:
|
@@ -54,7 +40,7 @@ dependencies:
|
|
54
40
|
- !ruby/object:Gem::Version
|
55
41
|
version: '0'
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
43
|
+
name: minitest
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
59
45
|
requirements:
|
60
46
|
- - ">="
|
@@ -68,7 +54,7 @@ dependencies:
|
|
68
54
|
- !ruby/object:Gem::Version
|
69
55
|
version: '0'
|
70
56
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
57
|
+
name: rake
|
72
58
|
requirement: !ruby/object:Gem::Requirement
|
73
59
|
requirements:
|
74
60
|
- - ">="
|
@@ -107,18 +93,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
93
|
requirements:
|
108
94
|
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '2.3'
|
111
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
98
|
requirements:
|
113
99
|
- - ">="
|
114
100
|
- !ruby/object:Gem::Version
|
115
101
|
version: '0'
|
116
102
|
requirements: []
|
117
|
-
|
118
|
-
rubygems_version: 2.3.0
|
103
|
+
rubygems_version: 3.1.2
|
119
104
|
signing_key:
|
120
105
|
specification_version: 4
|
121
106
|
summary: A Ruby wrapper for Barnes and Noble Product Web Services
|
122
107
|
test_files:
|
123
108
|
- test/test_barnesandnoble.rb
|
124
|
-
has_rdoc:
|