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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4991de82e91c44e37e5d91313334fe9dd421944
4
- data.tar.gz: 5db04af870e29db42b7cb005ced205bd7d198ced
3
+ metadata.gz: 1cc2f0b5a0447a44bae1e893748b26a0ee9d635a
4
+ data.tar.gz: 7041259521e6cbe055e7aae5a9472412a17a2d2b
5
5
  SHA512:
6
- metadata.gz: 5339753b11efab7306d4138d1eeee5dd02caf848a18685c2c4d25c866531d89dbe147bbd6ab6a4e86516452a608a59f4bbf3811efe6ba315db32e38d237a6366
7
- data.tar.gz: 48958577590bfb177a74f37d2cf5d35ab01e0991d40633e3249b0126e656e969282f75fe208634ff72cef88e93ee2c942d4f073ac6bb6f36d7ac1f53722a3b5b
6
+ metadata.gz: 09bbf24da68e256f3b587ff0fc16e03b9936f83b029155b598195f0abe91b13f8e70a6a5ea50af4d75ed0f61caabe1fe03df5ab9ff693b796de106925ce6ffe4
7
+ data.tar.gz: 1e7dd5a7aed443de6b6403408c2c31f21a1f576e5e6c19f6fcf1e6b714f382ce4c7aafcc01461e74f0148148700c655bbdac4f556d56a96d6a549a16a7a65ff5
data/README.md CHANGED
@@ -1,74 +1,35 @@
1
- **BarnesAndNoble** is a Ruby wrapper to the Barnes and Noble Product Web Services
1
+ # Barnesandnoble
2
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:
3
+ **Barnesandnoble** is a Ruby wrapper to the Barnes and Noble Product Web Services.
23
4
 
24
- ```ruby
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
- ```ruby
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
- #### Get Top10 :
9
+ Create a request:
43
10
 
44
11
  ```ruby
45
- params = {
46
- 'Top10SearchDomain' => 'Book',
47
- }
48
- res = req.get('Top10', params)
12
+ request = Barnesandnoble.new
49
13
  ```
50
14
 
51
- #### Run a products search by keywords:
15
+ Run a query:
52
16
 
53
17
  ```ruby
54
18
  params = {
55
- 'SearchType': 'Book',
56
- 'Start': 1,
57
- 'Size': 5,
58
- 'ProductSort': 'BestSelling'
59
- 'Keyword': 'Foucault'
19
+ "Ean" => 9781593083342,
20
+ "ProductCode" => "Book"
60
21
  }
61
- res = req.get('ProductSearch', params)
22
+ response = request.product_lookup(query: params)
62
23
  ```
63
24
 
64
- Parse the response into a Ruby Hash:
25
+ Parse the response into a Hash:
65
26
 
66
27
  ```ruby
67
- res.to_h
28
+ response.to_h
68
29
  ```
69
30
 
70
- Or pass its body into a custom parser:
31
+ Or pass it to a custom parser:
71
32
 
72
33
  ```ruby
73
- MyParser.new(res.body)
34
+ MyParser.new(response.body)
74
35
  ```
@@ -1,7 +1,7 @@
1
- require 'forwardable'
2
- require 'barnesandnoble/request'
1
+ require "forwardable"
2
+ require "barnesandnoble/request"
3
3
 
4
- module BarnesAndNoble
4
+ module Barnesandnoble
5
5
  class << self
6
6
  extend Forwardable
7
7
 
@@ -1,27 +1,52 @@
1
- require 'excon'
2
- require 'barnesandnoble/response'
3
- require 'uri'
1
+ require "excon"
2
+ require "barnesandnoble/response"
4
3
 
5
- module BarnesAndNoble
4
+ module Barnesandnoble
6
5
  class Request
7
- def initialize(app_id = ENV['BN_API_KEY'])
6
+ def initialize(app_id = ENV["BN_API_KEY"])
8
7
  @app_id = app_id
9
8
  end
10
9
 
11
- def get(method, query, excon_options = {})
12
- query['AppId'] = @app_id
10
+ underscore = ->(str) {
11
+ str.gsub(/(.)([A-Z\d])/,'\1_\2').downcase
12
+ }
13
13
 
14
- Response.new(connection(method, query).get(excon_options))
15
- end
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 hash_to_query(hash)
20
- '?' + URI.encode(hash.map{|k,v| "#{k}=#{v}"}.join("&"))
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 connection(request_type, query)
24
- Excon.new("http://services.barnesandnoble.com/v03_00/#{request_type}#{hash_to_query(query)}", expects: 200)
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 'delegate'
2
- require 'multi_xml'
1
+ require "delegate"
2
+ require "multi_xml"
3
3
 
4
- module BarnesAndNoble
4
+ module Barnesandnoble
5
5
  class Response < SimpleDelegator
6
6
  def body
7
- __getobj__.body.force_encoding('ISO8859-1').encode('UTF-8')
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 BarnesAndNoble
2
- VERSION = '0.1.1'
1
+ module Barnesandnoble
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,71 +1,69 @@
1
- require 'minitest/autorun'
2
- require 'minitest/pride'
3
- require 'pry'
1
+ require "minitest/autorun"
2
+ require "minitest/pride"
3
+ require "pry"
4
4
 
5
- require_relative '../lib/barnesandnoble'
5
+ require_relative "../lib/barnesandnoble"
6
6
 
7
- class TestBarnesAndNoble < Minitest::Unit::TestCase
7
+ class TestBarnesandnoble < Minitest::Test
8
8
  def setup
9
- @req = BarnesAndNoble::Request.new
9
+ @req = Barnesandnoble.new
10
10
  end
11
11
 
12
12
  def test_product_lookup
13
- res = @req.get('ProductLookup', {
14
- 'Ean' => '9781593083342',
15
- 'ProductCode' => 'Book'
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.get('GetCategories', {
23
- 'Ean' => '9781593083342',
24
- 'ProductCode' => 'Book'
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
- # The query is correct, but this method doesn't seem to be working
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.get('Top10', {
45
- 'Top10SearchDomain' => 'Book'
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.get('ProductSearch', {
53
- 'SearchType' => 'Book',
54
- 'Start' => 1,
55
- 'Size' => 5,
56
- 'ProductSort' => 'Bestselling',
57
- 'Keyword' => 'Deleuze'
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.get('ProductLookup', {
65
- 'ProductCode' => 'Book',
66
- 'Ean' => '0942299663'
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.1.1
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-06-09 00:00:00.000000000 Z
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: '0.5'
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: '0.5'
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: '5'
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: '5'
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.2.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