powells 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c9bc301f76a4e6930e5aeb6590a038b0add6f881
4
+ data.tar.gz: 771df08d8a3f6cb816a56ad0cf23e3def01aa591
5
+ SHA512:
6
+ metadata.gz: dad222fd1f928c9e5abc68117fbaa7cdd1abae9ac08b394a26f08f9ca1abd04ed7e33197663f27d18a07c85331f90dd48cffe96cdf900c3ab0f97fc36adec95d
7
+ data.tar.gz: 28f3e58e4fb11c8a7185d56cc0924a6c7d89ffddd2cd841e74d0d924b763f54edd5074b03f727bf357e5c90ef51a5daccf6f4f0472191ba0c28f4b5f988f09fa
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2014 Hakan Ensari
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.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Ruby wrapper to the Powells API
2
+
3
+ It does what it says [on the tin][1].
4
+
5
+ [1]: http://api.powells.com/stable
@@ -0,0 +1,86 @@
1
+ require 'excon'
2
+ require 'powells/response'
3
+
4
+ module Powells
5
+ class Request
6
+ # Create a new request
7
+ def initialize(api_key: ENV['POWELLS_API_KEY'], api_version: 'v0c')
8
+ @api_key = api_key
9
+ @api_version = api_version
10
+ end
11
+
12
+ # Retrieve inventory data for a particular ISBN or SKU
13
+ def inventory(isbn_or_sku)
14
+ get('inventory', isbn_or_sku)
15
+ end
16
+
17
+ # Retrieve product data for a particular ISBN or SKU
18
+ def product(isbn_or_sku)
19
+ get('product', isbn_or_sku)
20
+ end
21
+
22
+ # Retrieve content about an ISBN or SKU
23
+ #
24
+ # This can include items like reviews and publisher descriptions.
25
+ def content(isbn_or_sku)
26
+ get('content', isbn_or_sku)
27
+ end
28
+
29
+ # Retrieve information about retail locations
30
+ def locations(slug = nil)
31
+ get('locations', slug)
32
+ end
33
+
34
+ # Retrieve product information by way of keywords
35
+ def search(keywords, options = {})
36
+ get('search', URI.encode(keywords), options: options)
37
+ end
38
+
39
+ # Retrieve product information for related products
40
+ def recommendation(isbn, options = {})
41
+ get('recommendation', isbn, options: options)
42
+ end
43
+
44
+ # A list of up to 50 of the bestselling titles from Powells's Portland
45
+ # locations, sorted most popular first
46
+ def pdxbestsellers(options = {})
47
+ get('pdxbestsellers', options: options)
48
+ end
49
+
50
+ # This feed is what Powell's will use to communicate any known issues with
51
+ # particular API calls or the API in general
52
+ def apistatus
53
+ get('apistatus')
54
+ end
55
+
56
+ # Switch to development environment
57
+ def sandbox
58
+ @api_key = 'testing'
59
+ self
60
+ end
61
+
62
+ # Debug requests
63
+ def debug
64
+ @debug = true
65
+ self
66
+ end
67
+
68
+ private
69
+
70
+ def get(*query, options: {})
71
+ path = build_path(query)
72
+ options.update(debug: 1) if @debug
73
+ res = http.get(path: path, query: options)
74
+
75
+ Response.new(res)
76
+ end
77
+
78
+ def http
79
+ Excon.new('http://api.powells.com', expects: 200)
80
+ end
81
+
82
+ def build_path(ary)
83
+ [@api_version, @api_key].concat(ary).compact.join('/')
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,10 @@
1
+ require 'delegate'
2
+ require 'json'
3
+
4
+ module Powells
5
+ class Response < SimpleDelegator
6
+ def to_h
7
+ JSON.parse(body)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Powells
2
+ VERSION = '0.0.1'
3
+ end
data/lib/powells.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'forwardable'
2
+ require 'powells/request'
3
+
4
+ module Powells
5
+ class << self
6
+ extend Forwardable
7
+
8
+ def_delegator Request, :new
9
+ end
10
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+ require 'vcr'
4
+
5
+ require_relative '../lib/powells'
6
+
7
+ VCR.configure do |c|
8
+ c.hook_into :excon
9
+ c.cassette_library_dir = 'test/vcr_cassettes'
10
+ c.default_cassette_options = { record: :new_episodes }
11
+ end
@@ -0,0 +1,83 @@
1
+ require_relative 'helper'
2
+
3
+ class TestPowells < Minitest::Unit::TestCase
4
+ def setup
5
+ VCR.insert_cassette('powells')
6
+ @powells = Powells.new.sandbox
7
+ end
8
+
9
+ def teardown
10
+ VCR.eject_cassette
11
+ end
12
+
13
+ def test_inventory_isbn
14
+ res = @powells.inventory('9780590353427')
15
+ refute_empty res.to_h
16
+ end
17
+
18
+ def test_inventory_sku
19
+ res = @powells.inventory('17-9780590353427-80')
20
+ refute_empty res.to_h
21
+ end
22
+
23
+ def test_product_isbn
24
+ res = @powells.product('9780590353427')
25
+ refute_empty res.to_h
26
+ end
27
+
28
+ def test_product_sku
29
+ res = @powells.product('17-9780590353427-80')
30
+ refute_empty res.to_h
31
+ end
32
+
33
+ def test_content_isbn
34
+ res = @powells.content('9780590353427')
35
+ refute_empty res.to_h
36
+ end
37
+
38
+ def test_content_sku
39
+ res = @powells.content('17-9780590353427-80')
40
+ refute_empty res.to_h
41
+ end
42
+
43
+ def test_locations
44
+ res = @powells.locations
45
+ refute_empty res.to_h
46
+ end
47
+
48
+ def test_locations_slug
49
+ res = @powells.locations('powells-city-of-books')
50
+ refute_empty res.to_h
51
+ end
52
+
53
+ def test_search
54
+ res = @powells.search('harry potter')
55
+ refute_empty res.to_h
56
+ end
57
+
58
+ def test_recommendation
59
+ res = @powells.recommendation('9780590353427')
60
+ refute_empty res.to_h
61
+ end
62
+
63
+ def test_pdxbestsellers
64
+ res = @powells.pdxbestsellers
65
+ refute_empty res.to_h
66
+ end
67
+
68
+ def test_apistatus
69
+ skip('Powells is not returning JSON')
70
+ res = @powells.apistatus
71
+ refute_empty res.to_h
72
+ end
73
+
74
+ def test_accepts_options
75
+ res = @powells.search('harry potter', per_page: 20)
76
+ assert_equal 20, res.to_h['results'].count
77
+ end
78
+
79
+ def test_debug
80
+ res = @powells.debug.search('harry potter')
81
+ assert_includes res.to_h.keys, 'input'
82
+ end
83
+ end