class Powells::Request

Public Class Methods

new(api_key: ENV['POWELLS_API_KEY']) click to toggle source

Create a new request

# File lib/powells/request.rb, line 7
def initialize(api_key: ENV['POWELLS_API_KEY'])
  @api_key = api_key
end

Public Instance Methods

content(isbn_or_sku) click to toggle source

Retrieve content about an ISBN or SKU

This can include items like reviews and publisher descriptions.

# File lib/powells/request.rb, line 24
def content(isbn_or_sku)
  get('content', isbn_or_sku)
end
debug() click to toggle source

Debug requests

# File lib/powells/request.rb, line 51
def debug
  @debug = true
  self
end
inventory(isbn_or_sku) click to toggle source

Retrieve inventory data for a particular ISBN or SKU

# File lib/powells/request.rb, line 12
def inventory(isbn_or_sku)
  get('Inventory', isbn_or_sku)
end
locations(slug = nil) click to toggle source

Retrieve information about retail locations

# File lib/powells/request.rb, line 29
def locations(slug = nil)
  get('locations', slug)
end
pdxbestsellers(options = {}) click to toggle source

A list of up to 50 of the bestselling titles from Powells’s Portland locations, sorted most popular first

# File lib/powells/request.rb, line 46
def pdxbestsellers(options = {})
  get('pdxbestsellers', options: options)
end
product(isbn_or_sku) click to toggle source

Retrieve product data for a particular ISBN or SKU

# File lib/powells/request.rb, line 17
def product(isbn_or_sku)
  get('product', isbn_or_sku)
end
recommendation(isbn, options = {}) click to toggle source

Retrieve product information for related products

# File lib/powells/request.rb, line 40
def recommendation(isbn, options = {})
  get('recommendation', isbn, options: options)
end

Private Instance Methods

api_key() click to toggle source
# File lib/powells/request.rb, line 74
def api_key
  @api_key or fail ArgumentError, 'Missing API key'
end
build_path(action, id = nil) click to toggle source
# File lib/powells/request.rb, line 70
def build_path(action, id = nil)
  ['PowellsApi.svc', action, api_key, id].compact.join('/')
end
get(*query, options: {}) click to toggle source
# File lib/powells/request.rb, line 58
def get(*query, options: {})
  path = build_path(*query)
  options.update(debug: 1) if @debug
  res = http.get(path: path, query: options)

  Response.new(res)
end
http() click to toggle source
# File lib/powells/request.rb, line 66
def http
  Excon.new('http://api.powells.com:8081', expects: 200)
end