Skip to content

Commit

Permalink
Merge a51a90f into ca864cc
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotz committed Jun 9, 2020
2 parents ca864cc + a51a90f commit 6f855b2
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 114 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,7 @@ rvm:
- 2.0.0
- 2.1.0
- 2.2.0
- 2.6.0

addons:
code_climate:
Expand Down
2 changes: 1 addition & 1 deletion .yardopts
@@ -1 +1 @@
--title "Springboard Client"
--title "Heartland Retail Client"
6 changes: 3 additions & 3 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
springboard-retail (5.0.0.beta1)
heartland-retail (5.0.0.beta1)
faraday
hashie
json (>= 1.7.4)
Expand Down Expand Up @@ -74,11 +74,11 @@ PLATFORMS
DEPENDENCIES
codeclimate-test-reporter (~> 1.0.0)
coveralls
heartland-retail!
pry
rake
rspec (~> 3.2)
springboard-retail!
webmock

BUNDLED WITH
1.16.2
1.17.2
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Springboard Retail
Copyright (c) 2014 Heartland Retail

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
66 changes: 35 additions & 31 deletions README.md
@@ -1,11 +1,11 @@
# Springboard Retail Client
# Heartland Retail API Client

[![Gem Version](https://badge.fury.io/rb/springboard-retail.png)](http://badge.fury.io/rb/springboard-retail)
[![Build Status](https://travis-ci.org/springboardretail/springboard-client-ruby.png?branch=master)](https://travis-ci.org/springboardretail/springboard-client-ruby)
[![Code Climate](https://codeclimate.com/github/springboardretail/springboard-client-ruby.png)](https://codeclimate.com/github/springboardretail/springboard-client-ruby)
[![Coverage Status](https://coveralls.io/repos/github/springboardretail/springboard-client-ruby/badge.svg?branch=master)](https://coveralls.io/github/springboardretail/springboard-client-ruby?branch=master)

This is the [Springboard Retail](http://springboardretail.com/) (a point-of-sale/retail management system) client library for Ruby. It provides access to the Springboard Retail HTTP API.
This is the [Heartland Retail](http://heartlandretail.us/) (a point-of-sale/retail management system) client library for Ruby. It provides access to the Heartland Retail HTTP API.

It is a wrapper around the [Faraday](https://github.com/lostisland/faraday) HTTP client library.

Expand All @@ -17,30 +17,30 @@ You need a recent version of libcurl and a sane build environment.

Debian/Ubuntu:

```
```bash
sudo apt-get install build-essential libcurl4-openssl-dev
gem install springboard-retail
gem install heartland-retail
```

## Connecting

```ruby
require 'springboard-retail'
springboard = Springboard::Client.new(
'https://example.myspringboard.us/api',
require 'heartland-retail'
heartland = HeartlandRetail::Client.new(
'https://example.retail.heartland.us/api/',
token: 'secret_token'
)
```

## Resource oriented

```ruby
resource = springboard[:items][1234]
resource = heartland[:items][1234]
response = resource.get
response = resource.delete

# Query string generation:
resource1 = springboard[:items]
resource1 = heartland[:items]
resource2 = resource.query(:key1 => 'val1', 'key with spaces' => 'val with spaces')
resource2.uri.to_s
# => "/items?key%20with%20spaces=val%20with%20spaces&key1=val1"
Expand All @@ -49,47 +49,50 @@ resource2.uri.to_s
## URI oriented

```ruby
response = springboard.get '/items/1234'
response = springboard.delete '/items/1234'
item_count = springboard.count '/items'
response = heartland.get '/items/1234'
response = heartland.delete '/items/1234'
item_count = heartland.count '/items'
```

## Collection Resources

### Enumerable

Resources include Ruby's Enumerable module for easy iteration over collections:

```ruby
springboard[:items].each do |item|
heartland[:items].each do |item|
puts item['description']
end

item_count = springboard[:items].count
item_count = heartland[:items].count

usernames = springboard[:users].map {|user| user['login']}
usernames = heartland[:users].map {|user| user['login']}
```

### Filtering
Resources have a `filter` method that support's Springboard's advanced filter syntax:

Resources have a `filter` method that support's Heartland Retail's advanced filter syntax:

```ruby
active_users = springboard[:users].filter(:active => true)
active_users = heartland[:users].filter(:active => true)
active_users.each do |user|
# do something with each active user
end

# filter returns a new resource which allows for chaining:
items = springboard[:items]
items = heartland[:items]
active_items = items.filter(:active => true)
active_items.filter(:price => {'$gt' => 10}).each do |item|
# ...
end

# filtering custom fields:
springboard[:items].filter('custom@size'=> 'XL')
heartland[:items].filter('custom@size'=> 'XL')
```

### Sorting

Resources have a `sort` method that accepts any number of sort options. Note that each call to sort overwrites any previous sorts.

```ruby
Expand All @@ -103,6 +106,7 @@ end
```

### Returning select fields

Resources have a `only` method that accepts any number of field keys to return only the selected fields. Note that each call to `only` overwrites any previous fields.

```ruby
Expand Down Expand Up @@ -157,8 +161,8 @@ The `embed` method accepts one or more arguments as symbols or strings. It suppo

Issuing deletes while iterating over a collection resource can cause the pagination to shift resulting in unexpected behavior. Use `while_results` when you want to:

* Consume messages from a queue, deleting each message after it has been processed.
* Delete all resources in a collection that doesn't support a top-level DELETE method.
- Consume messages from a queue, deleting each message after it has been processed.
- Delete all resources in a collection that doesn't support a top-level DELETE method.

For example:

Expand All @@ -177,20 +181,20 @@ passed through untouched:

```ruby
# this:
springboard[:some_collection].post :a => 1, :b => 2
heartland[:some_collection].post :a => 1, :b => 2

# is equivalent to this:
springboard[:some_collection].post '{"a":1,"b":2}'
heartland[:some_collection].post '{"a":1,"b":2}'
```

## Response

```ruby
response = springboard[:items][1].get
response = heartland[:items][1].get

response.status # Response status code as an Integer
response.success? # true/false depending on whether 'status' indicates non-error
response.body # Returns a Springboard::Client::Body object (see below)
response.body # Returns a HeartlandRetail::Client::Body object (see below)
response.raw_body # Returns the raw response body as a string
response[:some_key] # Returns the corresponding key from 'body'
response.headers # Response headers as a Hash
Expand Down Expand Up @@ -237,17 +241,17 @@ response.raw_body
All HTTP request methods have a bang variant that raises an exception on failure:

```ruby
response = springboard[:i_dont_exist].get
response = heartland[:i_dont_exist].get
response.status
# => 404

springboard[:i_dont_exist].get!
# Raises Springboard::Client::RequestFailed exception
heartland[:i_dont_exist].get!
# Raises HeartlandRetail::Client::RequestFailed exception

# To access the response from the exception:
begin
springboard[:i_dont_exist].get!
rescue Springboard::Client::RequestFailed => error
heartland[:i_dont_exist].get!
rescue HeartlandRetail::Client::RequestFailed => error
puts error.response.status
end
# => 404
Expand All @@ -264,5 +268,5 @@ client.debug = true
client.debug = '/path/to/file.log'

# Same values can be passed via :debug option to client constructor
client = Springboard::Client.new '<url>', :debug => true
client = HeartlandRetail::Client.new '<url>', :debug => true
```
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -8,11 +8,11 @@ RSpec::Core::RakeTask.new(:spec)

task :default => :spec

desc "Start a console with a Springboard::Client instance"
desc "Start a console with a HeartlandRetail::Client instance"
task :console do
require 'springboard/client'
require 'heartland/client'
require 'pry'
CLIENT = Springboard::Client.new(ENV['URI'])
CLIENT = HeartlandRetail::Client.new(ENV['URI'])
CLIENT.auth :username => ENV['USER'], :password => ENV['PASSWORD']
Pry.start
end
8 changes: 4 additions & 4 deletions springboard-retail.gemspec → heartland-retail.gemspec
@@ -1,9 +1,9 @@
Gem::Specification.new do |s|
s.name = 'springboard-retail'
s.version = '5.0.0.beta1'
s.name = 'heartland-retail'
s.version = '5.0.0'
s.platform = Gem::Platform::RUBY
s.authors = ['Jay Stotz']
s.summary = 'Springboard Retail API client library'
s.authors = ['Jay Stotz', 'Derek Stotz']
s.summary = 'Heartland Retail API client library'

s.required_rubygems_version = '>= 1.3.6'

Expand Down
1 change: 1 addition & 0 deletions lib/heartland-retail.rb
@@ -0,0 +1 @@
require_relative 'heartland/client'
41 changes: 28 additions & 13 deletions lib/springboard/client.rb → lib/heartland/client.rb
Expand Up @@ -3,13 +3,13 @@
require 'json'
require 'logger'

require 'springboard/client/errors'
require_relative 'client/errors'

##
# Springboard namespace
module Springboard
# HeartlandRetail namespace
module HeartlandRetail
##
# The main point of interaction for the Springboard Client library.
# The main point of interaction for the Heartland Retail Client library.
#
# Client code must successfully authenticate with the API via the {#auth}
# method before calling any HTTP methods or the API will return authorization
Expand Down Expand Up @@ -42,7 +42,7 @@ class Client
# @param [String] base_uri Base URI
# @option opts [Boolean, String] :debug Pass true to debug to stdout. Pass a String to debug to given filename.
# @option opts [Boolean] :insecure Disable SSL certificate verification
# @option opts [String] :token Springboard API Token
# @option opts [String] :token Heartland Retail API Token
def initialize(base_uri, opts={})
@base_uri = URI.parse(base_uri)
@opts = opts
Expand All @@ -69,10 +69,10 @@ def debug=(debug)
#
# @return [true]
#
# @option opts [String] :username Springboard username
# @option opts [String] :password Springboard password
# @option opts [String] :username Heartland Retail username
# @option opts [String] :password Heartland Retail password
def auth(opts={})
warn "[DEPRECATION] `auth` is deprecated. Please use `Springboard::Client.new '#{base_uri}', token: 'secret_token'` instead."
warn "[DEPRECATION] `auth` is deprecated. Please use `HeartlandRetail::Client.new '#{base_uri}', token: 'secret_token'` instead."

unless opts[:username] && opts[:password]
raise "Must specify :username and :password"
Expand All @@ -87,7 +87,7 @@ def auth(opts={})
@session_cookie = response.headers['set-cookie']
return true
else
raise AuthFailed, "Springboard auth failed"
raise AuthFailed, "Heartland Retail auth failed"
end
end

Expand Down Expand Up @@ -278,7 +278,22 @@ def debug_logger(debug)
end
end

require 'springboard/client/resource'
require 'springboard/client/response'
require 'springboard/client/body'
require 'springboard/client/uri'
##
# Springboard namespace as alias of HeartlandRetail namespace for backwards compatability
module Springboard
include HeartlandRetail

##
# HeartlandRetail::Client with added deprecation warning for Springboard namespace
class Client < HeartlandRetail::Client
def initialize(base_uri, opts={})
warn "[DEPRECATION] `Springboard::Client.new` is deprecated. Please use `HeartlandRetail::Client.new` instead."
super
end
end
end

require_relative 'client/resource'
require_relative 'client/response'
require_relative 'client/body'
require_relative 'client/uri'
@@ -1,6 +1,6 @@
require 'hashie'

module Springboard
module HeartlandRetail
class Client
##
# An indifferent Hash to represent parsed response bodies.
Expand Down
@@ -1,4 +1,4 @@
module Springboard
module HeartlandRetail
class Client
##
# Mixin provides {Resource} with special methods for convenient interaction
Expand Down Expand Up @@ -49,7 +49,7 @@ def empty?
##
# Returns a new resource with the given filters added to the query string.
#
# @see https://github.com/springboard/springboard-retail/blob/master/api/doc/filtering.md Springboard collection API filtering docs
# @see https://github.com/springboard/springboard-retail/blob/master/api/doc/filtering.md Heartland Retail collection API filtering docs
#
# @param [String, Hash] new_filters Hash or JSON string of new filters
#
Expand Down
@@ -1,4 +1,4 @@
module Springboard
module HeartlandRetail
class Client
##
# API request failure
Expand Down
@@ -1,6 +1,6 @@
require 'springboard/client/collection'
require_relative 'collection'

module Springboard
module HeartlandRetail
class Client
##
# An representation of an API resource identified by a URI. Allows
Expand All @@ -23,13 +23,13 @@ class Resource
attr_reader :uri

##
# The underlying Springboard Client.
# The underlying HeartlandRetail Client.
#
# @return [Client]
attr_reader :client

##
# @param [Springboard::Client] client
# @param [HeartlandRetail::Client] client
# @param [Addressable::URI, #to_s] uri
def initialize(client, uri_or_path)
@client = client
Expand Down

0 comments on commit 6f855b2

Please sign in to comment.