heartland-retail 5.0.0

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +16 -0
  5. data/.yardopts +1 -0
  6. data/Gemfile +15 -0
  7. data/Gemfile.lock +84 -0
  8. data/LICENSE +21 -0
  9. data/README.md +272 -0
  10. data/Rakefile +18 -0
  11. data/heartland-retail.gemspec +17 -0
  12. data/lib/heartland-retail.rb +1 -0
  13. data/lib/heartland/client.rb +299 -0
  14. data/lib/heartland/client/body.rb +13 -0
  15. data/lib/heartland/client/collection.rb +121 -0
  16. data/lib/heartland/client/errors.rb +17 -0
  17. data/lib/heartland/client/resource.rb +215 -0
  18. data/lib/heartland/client/response.rb +84 -0
  19. data/lib/heartland/client/uri.rb +117 -0
  20. data/spec/heartland/client/body_spec.rb +31 -0
  21. data/spec/heartland/client/resource_spec.rb +318 -0
  22. data/spec/heartland/client/response_spec.rb +105 -0
  23. data/spec/heartland/client/uri_spec.rb +157 -0
  24. data/spec/heartland/client_spec.rb +361 -0
  25. data/spec/shared_client_context.rb +5 -0
  26. data/spec/spec_helper.rb +17 -0
  27. data/vendor/cache/addressable-2.2.8.gem +0 -0
  28. data/vendor/cache/codeclimate-test-reporter-1.0.8.gem +0 -0
  29. data/vendor/cache/coderay-1.1.0.gem +0 -0
  30. data/vendor/cache/coveralls-0.7.11.gem +0 -0
  31. data/vendor/cache/crack-0.4.2.gem +0 -0
  32. data/vendor/cache/diff-lcs-1.2.5.gem +0 -0
  33. data/vendor/cache/docile-1.1.5.gem +0 -0
  34. data/vendor/cache/faraday-0.17.3.gem +0 -0
  35. data/vendor/cache/hashie-4.1.0.gem +0 -0
  36. data/vendor/cache/json-2.3.0.gem +0 -0
  37. data/vendor/cache/method_source-0.8.2.gem +0 -0
  38. data/vendor/cache/mime-types-2.4.3.gem +0 -0
  39. data/vendor/cache/multi_json-1.11.0.gem +0 -0
  40. data/vendor/cache/multipart-post-2.1.1.gem +0 -0
  41. data/vendor/cache/netrc-0.10.3.gem +0 -0
  42. data/vendor/cache/pry-0.10.1.gem +0 -0
  43. data/vendor/cache/rake-10.4.2.gem +0 -0
  44. data/vendor/cache/rest-client-1.7.3.gem +0 -0
  45. data/vendor/cache/rspec-3.2.0.gem +0 -0
  46. data/vendor/cache/rspec-core-3.2.2.gem +0 -0
  47. data/vendor/cache/rspec-expectations-3.2.0.gem +0 -0
  48. data/vendor/cache/rspec-mocks-3.2.1.gem +0 -0
  49. data/vendor/cache/rspec-support-3.2.2.gem +0 -0
  50. data/vendor/cache/safe_yaml-1.0.4.gem +0 -0
  51. data/vendor/cache/simplecov-0.9.2.gem +0 -0
  52. data/vendor/cache/simplecov-html-0.9.0.gem +0 -0
  53. data/vendor/cache/slop-3.6.0.gem +0 -0
  54. data/vendor/cache/term-ansicolor-1.3.0.gem +0 -0
  55. data/vendor/cache/thor-0.19.1.gem +0 -0
  56. data/vendor/cache/tins-1.3.5.gem +0 -0
  57. data/vendor/cache/webmock-1.17.4.gem +0 -0
  58. metadata +140 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1bdee96767c0beb69e567edbce236959ce1305d420bc940586ac2732a6a27c5
4
+ data.tar.gz: de52df85cb38b7e011854862c49d6314bb065d3057fcb871624951057e537383
5
+ SHA512:
6
+ metadata.gz: 86c7a3652a47396e2c9dc88cdc9697fdaf29cb7fcca32bf924dce5c230b773f31123cdc7e703455872bda24631aba5e7e03b2207cfa2310f2ac442f4dc7827ce
7
+ data.tar.gz: 92650387b74f3e380519d3c15d481c81f176714a1c01412158e877e2818cd0f913ded6256ff0de4d223de690b37acbbfe503a23c366b248104e9fb5019929810
@@ -0,0 +1,4 @@
1
+ pkg
2
+ .yardoc
3
+ doc
4
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,16 @@
1
+ sudo: false
2
+ language: ruby
3
+ bundler_args: --without development
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.2.0
9
+ - 2.6.0
10
+
11
+ addons:
12
+ code_climate:
13
+ repo_token: 6963f51029c0c9bf6406bd1cc69ae951bc53f9bf7751b16035515b5f764c58fe
14
+
15
+ after_success:
16
+ - bundle exec codeclimate-test-reporter
@@ -0,0 +1 @@
1
+ --title "Heartland Retail Client"
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'rspec', '~> 3.2'
8
+ gem 'webmock', :require => false
9
+ gem 'coveralls', :require => false
10
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
11
+ end
12
+
13
+ group :development do
14
+ gem 'pry'
15
+ end
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ heartland-retail (5.0.0)
5
+ faraday (< 1.0)
6
+ hashie
7
+ json (>= 1.7.4)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.2.8)
13
+ codeclimate-test-reporter (1.0.8)
14
+ simplecov (<= 0.13)
15
+ coderay (1.1.0)
16
+ coveralls (0.7.11)
17
+ multi_json (~> 1.10)
18
+ rest-client (>= 1.6.8, < 2)
19
+ simplecov (~> 0.9.1)
20
+ term-ansicolor (~> 1.3)
21
+ thor (~> 0.19.1)
22
+ crack (0.4.2)
23
+ safe_yaml (~> 1.0.0)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ faraday (0.17.3)
27
+ multipart-post (>= 1.2, < 3)
28
+ hashie (4.1.0)
29
+ json (2.3.0)
30
+ method_source (0.8.2)
31
+ mime-types (2.4.3)
32
+ multi_json (1.11.0)
33
+ multipart-post (2.1.1)
34
+ netrc (0.10.3)
35
+ pry (0.10.1)
36
+ coderay (~> 1.1.0)
37
+ method_source (~> 0.8.1)
38
+ slop (~> 3.4)
39
+ rake (10.4.2)
40
+ rest-client (1.7.3)
41
+ mime-types (>= 1.16, < 3.0)
42
+ netrc (~> 0.7)
43
+ rspec (3.2.0)
44
+ rspec-core (~> 3.2.0)
45
+ rspec-expectations (~> 3.2.0)
46
+ rspec-mocks (~> 3.2.0)
47
+ rspec-core (3.2.2)
48
+ rspec-support (~> 3.2.0)
49
+ rspec-expectations (3.2.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.2.0)
52
+ rspec-mocks (3.2.1)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.2.0)
55
+ rspec-support (3.2.2)
56
+ safe_yaml (1.0.4)
57
+ simplecov (0.9.2)
58
+ docile (~> 1.1.0)
59
+ multi_json (~> 1.0)
60
+ simplecov-html (~> 0.9.0)
61
+ simplecov-html (0.9.0)
62
+ slop (3.6.0)
63
+ term-ansicolor (1.3.0)
64
+ tins (~> 1.0)
65
+ thor (0.19.1)
66
+ tins (1.3.5)
67
+ webmock (1.17.4)
68
+ addressable (>= 2.2.7)
69
+ crack (>= 0.3.2)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ codeclimate-test-reporter (~> 1.0.0)
76
+ coveralls
77
+ heartland-retail!
78
+ pry
79
+ rake
80
+ rspec (~> 3.2)
81
+ webmock
82
+
83
+ BUNDLED WITH
84
+ 1.17.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Heartland Retail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,272 @@
1
+ # Heartland Retail API Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/springboard-retail.png)](http://badge.fury.io/rb/springboard-retail)
4
+ [![Build Status](https://travis-ci.org/springboardretail/springboard-client-ruby.png?branch=master)](https://travis-ci.org/springboardretail/springboard-client-ruby)
5
+ [![Code Climate](https://codeclimate.com/github/springboardretail/springboard-client-ruby.png)](https://codeclimate.com/github/springboardretail/springboard-client-ruby)
6
+ [![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)
7
+
8
+ 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.
9
+
10
+ It is a wrapper around the [Faraday](https://github.com/lostisland/faraday) HTTP client library.
11
+
12
+ You can find [documentation here](http://rdoc.info/github/springboardretail/springboard-client-ruby).
13
+
14
+ ## Installation
15
+
16
+ You need a recent version of libcurl and a sane build environment.
17
+
18
+ Debian/Ubuntu:
19
+
20
+ ```bash
21
+ sudo apt-get install build-essential libcurl4-openssl-dev
22
+ gem install heartland-retail
23
+ ```
24
+
25
+ ## Connecting
26
+
27
+ ```ruby
28
+ require 'heartland-retail'
29
+ heartland = HeartlandRetail::Client.new(
30
+ 'https://example.retail.heartland.us/api/',
31
+ token: 'secret_token'
32
+ )
33
+ ```
34
+
35
+ ## Resource oriented
36
+
37
+ ```ruby
38
+ resource = heartland[:items][1234]
39
+ response = resource.get
40
+ response = resource.delete
41
+
42
+ # Query string generation:
43
+ resource1 = heartland[:items]
44
+ resource2 = resource.query(:key1 => 'val1', 'key with spaces' => 'val with spaces')
45
+ resource2.uri.to_s
46
+ # => "/items?key%20with%20spaces=val%20with%20spaces&key1=val1"
47
+ ```
48
+
49
+ ## URI oriented
50
+
51
+ ```ruby
52
+ response = heartland.get '/items/1234'
53
+ response = heartland.delete '/items/1234'
54
+ item_count = heartland.count '/items'
55
+ ```
56
+
57
+ ## Collection Resources
58
+
59
+ ### Enumerable
60
+
61
+ Resources include Ruby's Enumerable module for easy iteration over collections:
62
+
63
+ ```ruby
64
+ heartland[:items].each do |item|
65
+ puts item['description']
66
+ end
67
+
68
+ item_count = heartland[:items].count
69
+
70
+ usernames = heartland[:users].map {|user| user['login']}
71
+ ```
72
+
73
+ ### Filtering
74
+
75
+ Resources have a `filter` method that support's Heartland Retail's advanced filter syntax:
76
+
77
+ ```ruby
78
+ active_users = heartland[:users].filter(:active => true)
79
+ active_users.each do |user|
80
+ # do something with each active user
81
+ end
82
+
83
+ # filter returns a new resource which allows for chaining:
84
+ items = heartland[:items]
85
+ active_items = items.filter(:active => true)
86
+ active_items.filter(:price => {'$gt' => 10}).each do |item|
87
+ # ...
88
+ end
89
+
90
+ # filtering custom fields:
91
+ heartland[:items].filter('custom@size'=> 'XL')
92
+ ```
93
+
94
+ ### Sorting
95
+
96
+ Resources have a `sort` method that accepts any number of sort options. Note that each call to sort overwrites any previous sorts.
97
+
98
+ ```ruby
99
+ resource.sort(:id, :price)
100
+ resource.sort('created_at,desc')
101
+
102
+ # returns a new resource for chaining:
103
+ resource.sort(:description, :created_at).filter(:active => true).each do |item|
104
+ # ...
105
+ end
106
+ ```
107
+
108
+ ### Returning select fields
109
+
110
+ 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.
111
+
112
+ ```ruby
113
+ resource.only(:id)
114
+ resource.only(:public_id, :updated_at)
115
+
116
+ # returns a new resource for chaining:
117
+ resource.only(:public_id, :updated_at).filter(:active => true).each do |item|
118
+ # ...
119
+ end
120
+ ```
121
+
122
+ ### Creating Resources
123
+
124
+ Create a new resource via POST:
125
+
126
+ ```ruby
127
+ collection = client[:items]
128
+ response = collection.post! :description => 'Some New Item'
129
+ response.status_line
130
+ # => "HTTP/1.1 201 Created"
131
+
132
+ # To fetch the newly created resource:
133
+ new_item_response = response.resource.get!
134
+ new_item_response[:description]
135
+ # => "Some New Item"
136
+ ```
137
+
138
+ ### Embedding Related Resources
139
+
140
+ Use the `embed` method to include the contents of related resource in the response body of each item in the collection:
141
+
142
+ ```ruby
143
+ collection = client[:sales][:orders].embed(:customer, :location)
144
+ collection.first.to_hash
145
+ # => {
146
+ "id" => 1,
147
+ "customer_id" => 2,
148
+ "customer" => {
149
+ # customer data
150
+ },
151
+ "location_id" => 3,
152
+ "location" => {
153
+ # location data
154
+ }
155
+ }
156
+ ```
157
+
158
+ The `embed` method accepts one or more arguments as symbols or strings. It supports chaining and will merge the results of multiple calls.
159
+
160
+ ### Looping while results exist
161
+
162
+ 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:
163
+
164
+ - Consume messages from a queue, deleting each message after it has been processed.
165
+ - Delete all resources in a collection that doesn't support a top-level DELETE method.
166
+
167
+ For example:
168
+
169
+ ```ruby
170
+ collection = client[:system][:messages]
171
+ collection.while_results do |message|
172
+ # process message here...
173
+ collection[message['id']].delete!
174
+ end
175
+ ```
176
+
177
+ ## Request body
178
+
179
+ If the request body is a Hash, it will automatically be serialized as JSON. Otherwise, it is
180
+ passed through untouched:
181
+
182
+ ```ruby
183
+ # this:
184
+ heartland[:some_collection].post :a => 1, :b => 2
185
+
186
+ # is equivalent to this:
187
+ heartland[:some_collection].post '{"a":1,"b":2}'
188
+ ```
189
+
190
+ ## Response
191
+
192
+ ```ruby
193
+ response = heartland[:items][1].get
194
+
195
+ response.status # Response status code as an Integer
196
+ response.success? # true/false depending on whether 'status' indicates non-error
197
+ response.body # Returns a HeartlandRetail::Client::Body object (see below)
198
+ response.raw_body # Returns the raw response body as a string
199
+ response[:some_key] # Returns the corresponding key from 'body'
200
+ response.headers # Response headers as a Hash
201
+ response.resource # Returns a Resource if the response included a "Location" header, else nil
202
+ ```
203
+
204
+ ### Response Body
205
+
206
+ Given the following JSON response from the server:
207
+
208
+ ```javascript
209
+ {
210
+ "id": 1234,
211
+ "custom": {
212
+ "color": "Blue"
213
+ }
214
+ }
215
+ ```
216
+
217
+ Here are the various ways you can access the data:
218
+
219
+ ```ruby
220
+ body = response.body
221
+
222
+ # Symbols and strings can be used interchangeably for keys
223
+ body[:id]
224
+ # => 1234
225
+
226
+ body[:custom][:color]
227
+ # => "Blue"
228
+
229
+ body['custom']['color']
230
+ # => "Blue"
231
+
232
+ body.to_hash
233
+ # => {"id"=>1234, "custom"=>{"color"=>"Blue"}}
234
+
235
+ response.raw_body
236
+ # => "{\"id\":1234,\"custom\":{\"color\":\"Blue\"}}"
237
+ ```
238
+
239
+ ## Bang variants
240
+
241
+ All HTTP request methods have a bang variant that raises an exception on failure:
242
+
243
+ ```ruby
244
+ response = heartland[:i_dont_exist].get
245
+ response.status
246
+ # => 404
247
+
248
+ heartland[:i_dont_exist].get!
249
+ # Raises HeartlandRetail::Client::RequestFailed exception
250
+
251
+ # To access the response from the exception:
252
+ begin
253
+ heartland[:i_dont_exist].get!
254
+ rescue HeartlandRetail::Client::RequestFailed => error
255
+ puts error.response.status
256
+ end
257
+ # => 404
258
+
259
+ ```
260
+
261
+ ## Debugging
262
+
263
+ ```ruby
264
+ # Log request/response trace to stdout
265
+ client.debug = true
266
+
267
+ # Or, log to a file
268
+ client.debug = '/path/to/file.log'
269
+
270
+ # Same values can be passed via :debug option to client constructor
271
+ client = HeartlandRetail::Client.new '<url>', :debug => true
272
+ ```
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ Bundler.require(:default, :development)
4
+
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+
11
+ desc "Start a console with a HeartlandRetail::Client instance"
12
+ task :console do
13
+ require 'heartland/client'
14
+ require 'pry'
15
+ CLIENT = HeartlandRetail::Client.new(ENV['URI'])
16
+ CLIENT.auth :username => ENV['USER'], :password => ENV['PASSWORD']
17
+ Pry.start
18
+ end