loyaltylion 1.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.
- checksums.yaml +7 -0
- data/.gitignore +0 -0
- data/.rubocop.yml +69 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +58 -0
- data/Guardfile +11 -0
- data/LICENSE +22 -0
- data/README.md +88 -0
- data/Rakefile +1 -0
- data/lib/loyaltylion.rb +8 -0
- data/lib/loyaltylion/client.rb +57 -0
- data/lib/loyaltylion/errors.rb +4 -0
- data/lib/loyaltylion/models/activity.rb +29 -0
- data/lib/loyaltylion/models/order.rb +21 -0
- data/lib/loyaltylion/models/resource.rb +11 -0
- data/lib/loyaltylion/version.rb +3 -0
- data/loyaltylion.gemspec +20 -0
- data/spec/loyaltylion/client_spec.rb +196 -0
- data/spec/spec_helper.rb +17 -0
- metadata +77 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f1f2523ea7f0d1cd590a1edcb16c5f4ad43a323b
|
|
4
|
+
data.tar.gz: e9ba5e1d307bb89716aecc71fb453881bc40b1b9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bbb91a32da8895518684e14d9d01cfeacec798976c1471e60c75fcc9859108e4e8f7dc634ead3e624b48d4406011c1cdb5dff417cd9ccc7494e16ede7ce601da
|
|
7
|
+
data.tar.gz: 9115e5997422e8533fdbe9182b5cb071e6a8f7fb16e535c6b5c278d9b24ada5e5afd505ed63ebe6095b6a97ff010aab6ae29028c2088dabda0ae4f3f147e3b26
|
data/.gitignore
ADDED
|
File without changes
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.3
|
|
3
|
+
|
|
4
|
+
Metrics/LineLength:
|
|
5
|
+
Max: 100
|
|
6
|
+
|
|
7
|
+
Metrics/MethodLength:
|
|
8
|
+
Max: 25
|
|
9
|
+
|
|
10
|
+
Style/HashSyntax:
|
|
11
|
+
Enabled: true
|
|
12
|
+
EnforcedStyle: hash_rockets
|
|
13
|
+
|
|
14
|
+
Style/Documentation:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Style/EmptyLinesAroundClassBody:
|
|
18
|
+
Enabled: true
|
|
19
|
+
EnforcedStyle: no_empty_lines
|
|
20
|
+
|
|
21
|
+
Style/EmptyLinesAroundModuleBody:
|
|
22
|
+
Enabled: true
|
|
23
|
+
EnforcedStyle: no_empty_lines
|
|
24
|
+
|
|
25
|
+
Style/AlignParameters:
|
|
26
|
+
EnforcedStyle: with_fixed_indentation
|
|
27
|
+
|
|
28
|
+
Style/IndentHash:
|
|
29
|
+
EnforcedStyle: consistent
|
|
30
|
+
|
|
31
|
+
Style/DotPosition:
|
|
32
|
+
Enabled: true
|
|
33
|
+
EnforcedStyle: trailing
|
|
34
|
+
|
|
35
|
+
Style/MultilineOperationIndentation:
|
|
36
|
+
EnforcedStyle: indented
|
|
37
|
+
SupportedStyles:
|
|
38
|
+
- aligned
|
|
39
|
+
- indented
|
|
40
|
+
|
|
41
|
+
Style/StringLiterals:
|
|
42
|
+
EnforcedStyle: single_quotes
|
|
43
|
+
|
|
44
|
+
Style/Lambda:
|
|
45
|
+
Enabled: false
|
|
46
|
+
|
|
47
|
+
Style/DoubleNegation:
|
|
48
|
+
Enabled: false
|
|
49
|
+
|
|
50
|
+
Style/MultilineBlockChain:
|
|
51
|
+
Enabled: false
|
|
52
|
+
|
|
53
|
+
Style/NumericLiterals:
|
|
54
|
+
Enabled: false
|
|
55
|
+
|
|
56
|
+
Style/TrailingCommaInLiteral:
|
|
57
|
+
EnforcedStyleForMultiline: comma
|
|
58
|
+
|
|
59
|
+
Style/TrailingCommaInArguments:
|
|
60
|
+
EnforcedStyleForMultiline: comma
|
|
61
|
+
|
|
62
|
+
Style/FrozenStringLiteralComment:
|
|
63
|
+
Enabled: false
|
|
64
|
+
|
|
65
|
+
Style/ClosingParenthesisIndentation:
|
|
66
|
+
Enabled: false
|
|
67
|
+
|
|
68
|
+
Performance/Casecmp:
|
|
69
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
loyaltylion (1.0.0)
|
|
5
|
+
httparty (>= 0.8.1)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.4.0)
|
|
11
|
+
coderay (1.1.1)
|
|
12
|
+
crack (0.4.3)
|
|
13
|
+
safe_yaml (~> 1.0.0)
|
|
14
|
+
diff-lcs (1.2.5)
|
|
15
|
+
hashdiff (0.3.0)
|
|
16
|
+
httparty (0.13.7)
|
|
17
|
+
json (~> 1.8)
|
|
18
|
+
multi_xml (>= 0.5.2)
|
|
19
|
+
json (1.8.3)
|
|
20
|
+
method_source (0.8.2)
|
|
21
|
+
multi_xml (0.5.5)
|
|
22
|
+
pry (0.10.4)
|
|
23
|
+
coderay (~> 1.1.0)
|
|
24
|
+
method_source (~> 0.8.1)
|
|
25
|
+
slop (~> 3.4)
|
|
26
|
+
rake (11.3.0)
|
|
27
|
+
rspec (3.5.0)
|
|
28
|
+
rspec-core (~> 3.5.0)
|
|
29
|
+
rspec-expectations (~> 3.5.0)
|
|
30
|
+
rspec-mocks (~> 3.5.0)
|
|
31
|
+
rspec-core (3.5.3)
|
|
32
|
+
rspec-support (~> 3.5.0)
|
|
33
|
+
rspec-expectations (3.5.0)
|
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
+
rspec-support (~> 3.5.0)
|
|
36
|
+
rspec-mocks (3.5.0)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.5.0)
|
|
39
|
+
rspec-support (3.5.0)
|
|
40
|
+
safe_yaml (1.0.4)
|
|
41
|
+
slop (3.6.0)
|
|
42
|
+
webmock (2.1.0)
|
|
43
|
+
addressable (>= 2.3.6)
|
|
44
|
+
crack (>= 0.3.2)
|
|
45
|
+
hashdiff
|
|
46
|
+
|
|
47
|
+
PLATFORMS
|
|
48
|
+
ruby
|
|
49
|
+
|
|
50
|
+
DEPENDENCIES
|
|
51
|
+
loyaltylion!
|
|
52
|
+
pry
|
|
53
|
+
rake
|
|
54
|
+
rspec (~> 3.5.0)
|
|
55
|
+
webmock (~> 2.1.0)
|
|
56
|
+
|
|
57
|
+
BUNDLED WITH
|
|
58
|
+
1.13.2
|
data/Guardfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
|
5
|
+
directories %w(.)
|
|
6
|
+
|
|
7
|
+
guard :rspec, :cmd => 'bundle exec rspec --format documentation' do
|
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
9
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
10
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
11
|
+
end
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 LoyaltyLion
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
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
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# LoyaltyLion ruby-client
|
|
2
|
+
|
|
3
|
+
Use this to interact with the LoyaltyLion API from Ruby
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'loyaltylion'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install loyaltylion
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
* Ruby 1.9.3 or above
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Create a new instance of `LoyaltyLion` with your LoyaltyLion token and secret, which are available from your [dashboard](https://loyaltylion.com/login). You can then
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require 'loyaltylion'
|
|
29
|
+
|
|
30
|
+
loyaltylion = LoyaltyLion.new(:token => 'abc', :secret => '123')
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Send a new order to LoyaltyLion
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
loyaltylion.orders.create(
|
|
37
|
+
:merchant_id => '34b8c96a3b',
|
|
38
|
+
:customer_id => '71674',
|
|
39
|
+
:customer_email => 'alice@example.com',
|
|
40
|
+
:total => '59.95',
|
|
41
|
+
:total_shipping => '5.95',
|
|
42
|
+
:payment_status => 'unpaid',
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `orders.create` method accepts a hash containing all [supported fields](https://loyaltylion.com/docs/tracking-activities-and-orders#using-the-orders-api)
|
|
47
|
+
|
|
48
|
+
### Update an existing order
|
|
49
|
+
|
|
50
|
+
LoyaltyLion order updates are idempotent `PUT` operations. You can push an update to an existing order any time the order changes - our API will determine what changed and perform the appropriate action (e.g. approving points).
|
|
51
|
+
|
|
52
|
+
The first parameter should be the order's `merchant_id`, i.e. the id of the order in your system.
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
loyaltylion.orders.update('34b8c96a3b',
|
|
56
|
+
:payment_status => 'paid',
|
|
57
|
+
:cancellation_status => 'not_cancelled',
|
|
58
|
+
:refund_status => 'not_refunded',
|
|
59
|
+
:total_paid => '59.95',
|
|
60
|
+
:total_refunded => '0',
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Trigger an activity
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
loyaltylion.activities.create(
|
|
68
|
+
:name => 'signup',
|
|
69
|
+
:customer_id => '1001',
|
|
70
|
+
:customer_email => 'alice@example.com',
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Approve/decline an activity
|
|
75
|
+
|
|
76
|
+
If you've triggered a custom activity with a `merchant_id`, you can approve or decline the activity at a later date using the `activities.approve` and `activities.decline` methods.
|
|
77
|
+
|
|
78
|
+
These methods both expect the name of the custom activity (e.g. `review`) and the `merchant_id`.
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
loyaltylion.activities.approve('review', '1001')
|
|
82
|
+
# or...
|
|
83
|
+
loyaltylion.activities.decline('review', '1001')
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Changelog
|
|
87
|
+
|
|
88
|
+
* v1.0.0 - overhaul client API, bring in-line with v2 LoyaltyLion API
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/loyaltylion.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'httparty'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'loyaltylion/version'
|
|
4
|
+
require 'loyaltylion/errors'
|
|
5
|
+
|
|
6
|
+
module LoyaltyLion
|
|
7
|
+
class Client
|
|
8
|
+
include HTTParty
|
|
9
|
+
base_uri 'https://api.loyaltylion.com/v2'
|
|
10
|
+
|
|
11
|
+
attr_reader :token, :secret
|
|
12
|
+
|
|
13
|
+
def initialize(opts = {})
|
|
14
|
+
@token = opts[:token]
|
|
15
|
+
@secret = opts[:secret]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def orders
|
|
19
|
+
LoyaltyLion::Order.new(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def activities
|
|
23
|
+
LoyaltyLion::Activity.new(self)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def request(opts)
|
|
27
|
+
method = opts[:method] || :get
|
|
28
|
+
path = opts[:path]
|
|
29
|
+
body = opts[:body] || {}
|
|
30
|
+
headers = {
|
|
31
|
+
'user-agent' => "LoyaltyLion Ruby v#{LoyaltyLion::VERSION}",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
unless body.empty?
|
|
35
|
+
headers['content-type'] = 'application/json'
|
|
36
|
+
body = JSON.generate(body)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
res = self.class.send(method, path,
|
|
40
|
+
:basic_auth => {
|
|
41
|
+
:username => token,
|
|
42
|
+
:password => secret,
|
|
43
|
+
},
|
|
44
|
+
:headers => headers,
|
|
45
|
+
:body => body.empty? ? nil : body
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
if res.code >= 200 && res.code < 300
|
|
49
|
+
res.parsed_response
|
|
50
|
+
elsif res.code >= 400 && res.code < 500
|
|
51
|
+
raise LoyaltyLion::ClientError, res.parsed_response.inspect
|
|
52
|
+
else
|
|
53
|
+
raise LoyaltyLion::ServerError, res.parsed_response.inspect
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'loyaltylion/models/resource'
|
|
2
|
+
|
|
3
|
+
module LoyaltyLion
|
|
4
|
+
class Activity < Resource
|
|
5
|
+
def create(data)
|
|
6
|
+
client.request(
|
|
7
|
+
:method => :post,
|
|
8
|
+
:path => '/activities',
|
|
9
|
+
:body => data,
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def approve(name, merchant_id)
|
|
14
|
+
update(name, merchant_id, :state => 'approved')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def decline(name, merchant_id)
|
|
18
|
+
update(name, merchant_id, :state => 'declined')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def update(name, merchant_id, data)
|
|
22
|
+
client.request(
|
|
23
|
+
:method => :put,
|
|
24
|
+
:path => "/activities/#{name}/#{merchant_id}",
|
|
25
|
+
:body => data,
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'loyaltylion/models/resource'
|
|
2
|
+
|
|
3
|
+
module LoyaltyLion
|
|
4
|
+
class Order < Resource
|
|
5
|
+
def create(data)
|
|
6
|
+
client.request(
|
|
7
|
+
:method => :post,
|
|
8
|
+
:path => '/orders',
|
|
9
|
+
:body => data,
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def update(merchant_id, data)
|
|
14
|
+
client.request(
|
|
15
|
+
:method => :put,
|
|
16
|
+
:path => "/orders/#{merchant_id}",
|
|
17
|
+
:body => data,
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/loyaltylion.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
|
2
|
+
|
|
3
|
+
require 'loyaltylion/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.name = 'loyaltylion'
|
|
7
|
+
gem.version = LoyaltyLion::VERSION
|
|
8
|
+
gem.author = 'LoyaltyLion'
|
|
9
|
+
gem.email = 'support@loyaltylion.com'
|
|
10
|
+
gem.description = 'Interact with LoyaltyLion from Ruby. See https://loyaltylion.com/docs for more'
|
|
11
|
+
gem.summary = 'Ruby bindings for the LoyaltyLion API'
|
|
12
|
+
gem.homepage = 'https://loyaltylion.com/docs'
|
|
13
|
+
|
|
14
|
+
gem.add_dependency('httparty', '>= 0.8.1')
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
gem.require_paths = ['lib']
|
|
20
|
+
end
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe LoyaltyLion::Client do
|
|
4
|
+
describe '#initialize' do
|
|
5
|
+
it 'can create a new client with token/secret' do
|
|
6
|
+
client = LoyaltyLion::Client.new(:token => 'abc', :secret => '123')
|
|
7
|
+
|
|
8
|
+
expect(client.token).to eq('abc')
|
|
9
|
+
expect(client.secret).to eq('123')
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#request' do
|
|
14
|
+
let(:client) { LoyaltyLion::Client.new(:token => 'abc', :secret => '123') }
|
|
15
|
+
|
|
16
|
+
context 'any request' do
|
|
17
|
+
before do
|
|
18
|
+
stub_request(:get, 'https://api.loyaltylion.com/v2/orders')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'makes request to specified endpoint' do
|
|
22
|
+
client.request(:method => :get, :path => '/orders')
|
|
23
|
+
expect(WebMock).to have_requested(:get, 'https://api.loyaltylion.com/v2/orders')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'authenticates with token/secret' do
|
|
27
|
+
client.request(:method => :get, :path => '/orders')
|
|
28
|
+
expect(WebMock).to have_requested(:get, 'https://api.loyaltylion.com/v2/orders').with(
|
|
29
|
+
:basic_auth => %w(abc 123),
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'sets custom user agent' do
|
|
34
|
+
client.request(:method => :get, :path => '/orders')
|
|
35
|
+
expect(WebMock).to have_requested(:get, 'https://api.loyaltylion.com/v2/orders').with(
|
|
36
|
+
:headers => {
|
|
37
|
+
'user-agent' => 'LoyaltyLion Ruby v1.0.0',
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context 'when request has a body' do
|
|
44
|
+
it 'sends body as JSON' do
|
|
45
|
+
stub_request(:post, 'https://api.loyaltylion.com/v2/orders')
|
|
46
|
+
client.request(:method => :post, :path => '/orders', :body => {
|
|
47
|
+
:merchant_id => 'xe8ae3fe',
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
expect(WebMock).to have_requested(:post, 'https://api.loyaltylion.com/v2/orders').with(
|
|
51
|
+
:headers => {
|
|
52
|
+
'content-type' => 'application/json',
|
|
53
|
+
},
|
|
54
|
+
:body => JSON.generate(:merchant_id => 'xe8ae3fe'),
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context 'when API returns a 5xx response' do
|
|
60
|
+
it 'raises LoyaltyLion::ServerError' do
|
|
61
|
+
(500..510).each do |status|
|
|
62
|
+
stub_request(:get, 'https://api.loyaltylion.com/v2/orders').to_return(
|
|
63
|
+
:status => status,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
expect { client.request(:method => :get, :path => '/orders') }.
|
|
67
|
+
to raise_error(LoyaltyLion::ServerError)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'when API returns a 4xx response' do
|
|
73
|
+
it 'raises LoyaltyLion::ClientError' do
|
|
74
|
+
(400..430).each do |status|
|
|
75
|
+
stub_request(:get, 'https://api.loyaltylion.com/v2/orders').to_return(
|
|
76
|
+
:status => status,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
expect { client.request(:method => :get, :path => '/orders') }.
|
|
80
|
+
to raise_error(LoyaltyLion::ClientError)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'when API returns any other response' do
|
|
86
|
+
let(:body) do
|
|
87
|
+
{ 'customers' => [{ 'merchant_id' => '1001' }] }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'returns response body' do
|
|
91
|
+
stub_request(:get, 'https://api.loyaltylion.com/v2/orders').to_return(
|
|
92
|
+
:status => 200,
|
|
93
|
+
:headers => { 'content-type' => 'application/json' },
|
|
94
|
+
:body => JSON.generate(body),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
expect(
|
|
98
|
+
client.request(:method => :get, :path => '/orders'),
|
|
99
|
+
).to eql(body)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'resources' do
|
|
105
|
+
let(:client) { LoyaltyLion::Client.new(:token => 'abc', :secret => '123') }
|
|
106
|
+
|
|
107
|
+
describe '#orders' do
|
|
108
|
+
it 'returns an instance of LoyaltyLion::Order' do
|
|
109
|
+
expect(client.orders).to be_instance_of(LoyaltyLion::Order)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
describe '#create' do
|
|
113
|
+
it 'makes request with order data' do
|
|
114
|
+
stub_request(:post, 'https://api.loyaltylion.com/v2/orders')
|
|
115
|
+
client.orders.create(:merchant_id => 'xe8ae3fe')
|
|
116
|
+
|
|
117
|
+
expect(WebMock).to have_requested(:post, 'https://api.loyaltylion.com/v2/orders').with(
|
|
118
|
+
:body => JSON.generate(:merchant_id => 'xe8ae3fe'),
|
|
119
|
+
)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe '#update' do
|
|
124
|
+
it 'makes request with order merchant_id and data' do
|
|
125
|
+
stub_request(:put, 'https://api.loyaltylion.com/v2/orders/xe8ae3fe')
|
|
126
|
+
client.orders.update('xe8ae3fe', :total_paid => '69.99')
|
|
127
|
+
|
|
128
|
+
expect(WebMock).to have_requested(:put, 'https://api.loyaltylion.com/v2/orders/xe8ae3fe').
|
|
129
|
+
with(
|
|
130
|
+
:body => JSON.generate(:total_paid => '69.99'),
|
|
131
|
+
)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '#activities' do
|
|
137
|
+
it 'returns an instance of LoyaltyLion::Activity' do
|
|
138
|
+
expect(client.activities).to be_instance_of(LoyaltyLion::Activity)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
describe '#create' do
|
|
142
|
+
it 'makes POST request with activity data' do
|
|
143
|
+
stub_request(:post, 'https://api.loyaltylion.com/v2/activities')
|
|
144
|
+
client.activities.create(:name => 'review', :merchant_id => 'abc')
|
|
145
|
+
|
|
146
|
+
expect(WebMock).to have_requested(:post, 'https://api.loyaltylion.com/v2/activities').
|
|
147
|
+
with(
|
|
148
|
+
:body => JSON.generate(:name => 'review', :merchant_id => 'abc'),
|
|
149
|
+
)
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
describe '#update' do
|
|
154
|
+
it 'makes request with activity name, merchant_id and data' do
|
|
155
|
+
stub_request(:put, 'https://api.loyaltylion.com/v2/activities/review/abc1')
|
|
156
|
+
client.activities.update('review', 'abc1', :state => 'approved')
|
|
157
|
+
|
|
158
|
+
expect(WebMock).to have_requested(
|
|
159
|
+
:put,
|
|
160
|
+
'https://api.loyaltylion.com/v2/activities/review/abc1',
|
|
161
|
+
).with(
|
|
162
|
+
:body => JSON.generate(:state => 'approved'),
|
|
163
|
+
)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
describe '#approve' do
|
|
168
|
+
it 'makes PUT request to approve activity' do
|
|
169
|
+
stub_request(:put, 'https://api.loyaltylion.com/v2/activities/review/abc1')
|
|
170
|
+
client.activities.approve('review', 'abc1')
|
|
171
|
+
|
|
172
|
+
expect(WebMock).to have_requested(
|
|
173
|
+
:put,
|
|
174
|
+
'https://api.loyaltylion.com/v2/activities/review/abc1',
|
|
175
|
+
).with(
|
|
176
|
+
:body => JSON.generate(:state => 'approved'),
|
|
177
|
+
)
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
describe '#decline' do
|
|
182
|
+
it 'makes PUT request to decline activity' do
|
|
183
|
+
stub_request(:put, 'https://api.loyaltylion.com/v2/activities/review/abc1')
|
|
184
|
+
client.activities.decline('review', 'abc1')
|
|
185
|
+
|
|
186
|
+
expect(WebMock).to have_requested(
|
|
187
|
+
:put,
|
|
188
|
+
'https://api.loyaltylion.com/v2/activities/review/abc1',
|
|
189
|
+
).with(
|
|
190
|
+
:body => JSON.generate(:state => 'declined'),
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'loyaltylion'
|
|
2
|
+
require 'webmock/rspec'
|
|
3
|
+
|
|
4
|
+
RSpec.configure do |rspec|
|
|
5
|
+
rspec.color = true
|
|
6
|
+
rspec.tty = true
|
|
7
|
+
rspec.order = 'random'
|
|
8
|
+
rspec.backtrace_exclusion_patterns << /gems/
|
|
9
|
+
|
|
10
|
+
rspec.expect_with :rspec do |expectations|
|
|
11
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rspec.mock_with :rspec do |mocks|
|
|
15
|
+
mocks.verify_partial_doubles = true
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: loyaltylion
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- LoyaltyLion
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.8.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.8.1
|
|
27
|
+
description: Interact with LoyaltyLion from Ruby. See https://loyaltylion.com/docs
|
|
28
|
+
for more
|
|
29
|
+
email: support@loyaltylion.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- .gitignore
|
|
35
|
+
- .rubocop.yml
|
|
36
|
+
- Gemfile
|
|
37
|
+
- Gemfile.lock
|
|
38
|
+
- Guardfile
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
41
|
+
- Rakefile
|
|
42
|
+
- lib/loyaltylion.rb
|
|
43
|
+
- lib/loyaltylion/client.rb
|
|
44
|
+
- lib/loyaltylion/errors.rb
|
|
45
|
+
- lib/loyaltylion/models/activity.rb
|
|
46
|
+
- lib/loyaltylion/models/order.rb
|
|
47
|
+
- lib/loyaltylion/models/resource.rb
|
|
48
|
+
- lib/loyaltylion/version.rb
|
|
49
|
+
- loyaltylion.gemspec
|
|
50
|
+
- spec/loyaltylion/client_spec.rb
|
|
51
|
+
- spec/spec_helper.rb
|
|
52
|
+
homepage: https://loyaltylion.com/docs
|
|
53
|
+
licenses: []
|
|
54
|
+
metadata: {}
|
|
55
|
+
post_install_message:
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - '>='
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubyforge_project:
|
|
71
|
+
rubygems_version: 2.5.2
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 4
|
|
74
|
+
summary: Ruby bindings for the LoyaltyLion API
|
|
75
|
+
test_files:
|
|
76
|
+
- spec/loyaltylion/client_spec.rb
|
|
77
|
+
- spec/spec_helper.rb
|