stash-rewards 0.0.1.alpha5 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +30 -0
- data/Gemfile.lock +7 -4
- data/README.md +3 -3
- data/lib/stash/rewards/api_wrapper.rb +2 -5
- data/lib/stash/rewards/create_user.rb +4 -4
- data/lib/stash/rewards/enrol_user_in_campaign.rb +4 -4
- data/lib/stash/rewards/get_reward.rb +19 -0
- data/lib/stash/rewards/get_rewards.rb +4 -5
- data/lib/stash/rewards/issue_voucher.rb +20 -9
- data/lib/stash/rewards/response.rb +48 -0
- data/lib/stash/rewards/stash_reward.rb +16 -0
- data/lib/stash/rewards/version.rb +1 -1
- data/lib/stash/rewards.rb +3 -0
- data/stash-rewards.gemspec +3 -3
- metadata +13 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c6a8ba357b79f85fd23167ffdb6f8d1f306b001cca8a91711b5d8ce96f90d90
|
4
|
+
data.tar.gz: 4528c55f7730654f3af5dabd7be153d0397d81a9492c172ca630d85d07945636
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b25467f2784b0a27f1a9e8a00cb39f7832bab3c22274e4a698534c91d1e15b68e40dd75bb9eb09df14b669d7990515f0b47871e22377622a995e0577d31f7b2f
|
7
|
+
data.tar.gz: 0b4b5b1db5e410f89c0599387fad5515fff07ca6441cf298712e4fd1b8c60ccc3b7482e76b8f77d2842b297dcf68df96cbfb61d1a51618b1d7640cc79a2538cf
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
rspec:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
container:
|
9
|
+
image: ruby:2.6.5
|
10
|
+
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v1
|
13
|
+
|
14
|
+
- name: Gem cache
|
15
|
+
id: cache-bundle
|
16
|
+
uses: actions/cache@v1
|
17
|
+
with:
|
18
|
+
path: vendor/bundle
|
19
|
+
key: bundle-${{ hashFiles('**/Gemfile.lock') }}
|
20
|
+
|
21
|
+
- name: Bundle install
|
22
|
+
env:
|
23
|
+
RAILS_ENV: test
|
24
|
+
run: |
|
25
|
+
gem install bundler
|
26
|
+
bundle install --jobs 4 --retry 3 --path vendor/bundle
|
27
|
+
|
28
|
+
- name: Run tests
|
29
|
+
run: |
|
30
|
+
bundle exec rspec
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stash-rewards (0.0.
|
4
|
+
stash-rewards (0.0.3)
|
5
5
|
faraday (~> 1)
|
6
|
-
|
6
|
+
typhoeus (~> 1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -13,6 +13,8 @@ GEM
|
|
13
13
|
crack (0.4.5)
|
14
14
|
rexml
|
15
15
|
diff-lcs (1.5.0)
|
16
|
+
ethon (0.15.0)
|
17
|
+
ffi (>= 1.15.0)
|
16
18
|
faraday (1.10.0)
|
17
19
|
faraday-em_http (~> 1.0)
|
18
20
|
faraday-em_synchrony (~> 1.0)
|
@@ -36,8 +38,7 @@ GEM
|
|
36
38
|
faraday-patron (1.0.0)
|
37
39
|
faraday-rack (1.0.0)
|
38
40
|
faraday-retry (1.0.3)
|
39
|
-
|
40
|
-
faraday (>= 0.9.0)
|
41
|
+
ffi (1.15.5)
|
41
42
|
hashdiff (1.0.1)
|
42
43
|
multipart-post (2.2.3)
|
43
44
|
public_suffix (4.0.7)
|
@@ -59,6 +60,8 @@ GEM
|
|
59
60
|
rspec-support (~> 3.11.0)
|
60
61
|
rspec-support (3.11.0)
|
61
62
|
ruby2_keywords (0.0.5)
|
63
|
+
typhoeus (1.4.0)
|
64
|
+
ethon (>= 0.9.0)
|
62
65
|
webmock (3.14.0)
|
63
66
|
addressable (>= 2.8.0)
|
64
67
|
crack (>= 0.3.2)
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ And then execute:
|
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
$ gem install stash-rewards
|
21
|
+
$ gem install stash-rewards
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
@@ -52,7 +52,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
52
52
|
|
53
53
|
## Contributing
|
54
54
|
|
55
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/PerxTech/stash-rewards. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/PerxTech/stash-rewards/blob/master/CODE_OF_CONDUCT.md).
|
56
56
|
|
57
57
|
|
58
58
|
## License
|
@@ -61,4 +61,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
61
61
|
|
62
62
|
## Code of Conduct
|
63
63
|
|
64
|
-
Everyone interacting in the Stash::Rewards project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
64
|
+
Everyone interacting in the Stash::Rewards project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/PerxTech/stash-rewards/blob/master/CODE_OF_CONDUCT.md).
|
@@ -3,8 +3,6 @@
|
|
3
3
|
require_relative '../rewards'
|
4
4
|
|
5
5
|
require 'faraday'
|
6
|
-
require 'faraday_curl'
|
7
|
-
require 'logger'
|
8
6
|
require 'json'
|
9
7
|
|
10
8
|
module Stash
|
@@ -26,10 +24,9 @@ module Stash
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def api_wrapper
|
29
|
-
logger = Logger.new(STDOUT)
|
30
27
|
@api_wrapper ||= Faraday.new(url: @config.api_domain, headers: headers) do |f|
|
31
|
-
f.
|
32
|
-
f.request :
|
28
|
+
f.adapter :typhoeus
|
29
|
+
f.request :url_encoded
|
33
30
|
end
|
34
31
|
end
|
35
32
|
end
|
@@ -6,14 +6,14 @@ module Stash
|
|
6
6
|
module Rewards
|
7
7
|
class CreateUser < ApiWrapper
|
8
8
|
def call(user_identifier:)
|
9
|
-
|
9
|
+
api_response = api_wrapper.post('users') do |req|
|
10
10
|
req.body = user_payload(user_identifier)
|
11
11
|
end
|
12
|
-
parsed_response = JSON.parse(response.body)
|
13
12
|
|
14
|
-
|
13
|
+
response = Stash::Rewards::Response.new(api_response)
|
14
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
15
15
|
|
16
|
-
|
16
|
+
response
|
17
17
|
rescue Faraday::Error => e
|
18
18
|
raise Stash::Rewards::Error, e.message
|
19
19
|
end
|
@@ -6,14 +6,14 @@ module Stash
|
|
6
6
|
module Rewards
|
7
7
|
class EnrolUserInCampaign < ApiWrapper
|
8
8
|
def call(campaign_id:, user_identifier:)
|
9
|
-
|
9
|
+
api_response = api_wrapper.post("campaigns/#{campaign_id}/users") do |req|
|
10
10
|
req.body = user_payload(user_identifier)
|
11
11
|
end
|
12
|
-
parsed_response = JSON.parse(response.body)
|
13
12
|
|
14
|
-
|
13
|
+
response = Stash::Rewards::Response.new(api_response)
|
14
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
15
15
|
|
16
|
-
|
16
|
+
response
|
17
17
|
rescue Faraday::Error => e
|
18
18
|
raise Stash::Rewards::Error, e.message
|
19
19
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'api_wrapper'
|
4
|
+
|
5
|
+
module Stash
|
6
|
+
module Rewards
|
7
|
+
class GetReward < ApiWrapper
|
8
|
+
def call(campaign_id:, reward_id:)
|
9
|
+
api_response = api_wrapper.get("campaigns/#{campaign_id}/rewards/#{reward_id}")
|
10
|
+
response = Stash::Rewards::Response.new(api_response)
|
11
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
12
|
+
|
13
|
+
response
|
14
|
+
rescue Faraday::Error => e
|
15
|
+
raise Stash::Rewards::Error, e.message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -6,14 +6,13 @@ module Stash
|
|
6
6
|
module Rewards
|
7
7
|
class GetRewards < ApiWrapper
|
8
8
|
def call(campaign_id:, page_no: 0, page_size: 500)
|
9
|
-
|
9
|
+
api_response = api_wrapper.get("campaigns/#{campaign_id}/rewards") do |req|
|
10
10
|
req.params = query_params(page_no, page_size)
|
11
11
|
end
|
12
|
-
|
12
|
+
response = Stash::Rewards::Response.new(api_response)
|
13
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
parsed_response
|
15
|
+
response
|
17
16
|
rescue Faraday::Error => e
|
18
17
|
raise Stash::Rewards::Error, e.message
|
19
18
|
end
|
@@ -5,28 +5,39 @@ require_relative 'api_wrapper'
|
|
5
5
|
module Stash
|
6
6
|
module Rewards
|
7
7
|
class IssueVoucher < ApiWrapper
|
8
|
-
def call(campaign_id:, user_identifier:, reward_id:)
|
9
|
-
|
10
|
-
|
8
|
+
def call(campaign_id:, user_identifier:, reward_id:, quantity: 1)
|
9
|
+
price = reward_price(reward_id, campaign_id)
|
10
|
+
|
11
|
+
api_response = api_wrapper.post("campaigns/#{campaign_id}/users/refId_#{user_identifier}/rewards/order") do |req|
|
12
|
+
req.body = order_payload(reward_id, quantity, price)
|
11
13
|
end
|
12
|
-
|
13
|
-
raise Stash::Rewards::Error,
|
14
|
+
response = Stash::Rewards::Response.new(api_response)
|
15
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
14
16
|
|
15
|
-
|
17
|
+
response
|
16
18
|
rescue Faraday::Error => e
|
17
19
|
raise Stash::Rewards::Error, e.message
|
18
20
|
end
|
19
21
|
|
20
22
|
private
|
21
23
|
|
22
|
-
def
|
24
|
+
def reward_price(reward_id, campaign_id)
|
25
|
+
get_reward_api = ::Stash::Rewards::GetReward.new(@config)
|
26
|
+
response = get_reward_api.call(reward_id: reward_id, campaign_id: campaign_id)
|
27
|
+
raise Stash::Rewards::Error, response.error_message if response.error?
|
28
|
+
|
29
|
+
reward = Stash::Rewards::StashReward.new(response.payload)
|
30
|
+
reward.prices[0]['price'] || 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def order_payload(reward_id, quantity, price)
|
23
34
|
{
|
24
35
|
"userInformation": {},
|
25
36
|
"products": [
|
26
37
|
{
|
27
38
|
"rewardId": reward_id,
|
28
|
-
"price":
|
29
|
-
"quantity":
|
39
|
+
"price": price,
|
40
|
+
"quantity": quantity
|
30
41
|
}
|
31
42
|
]
|
32
43
|
}.to_json
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Rewards
|
5
|
+
class Response
|
6
|
+
def initialize(faraday_response)
|
7
|
+
@response = faraday_response
|
8
|
+
end
|
9
|
+
|
10
|
+
def error?
|
11
|
+
!@response.success? || (error_code != 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload
|
15
|
+
@payload ||= JSON.parse(body)
|
16
|
+
end
|
17
|
+
|
18
|
+
def status
|
19
|
+
@status ||= @response.status
|
20
|
+
end
|
21
|
+
|
22
|
+
def body
|
23
|
+
@body ||= @response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
def error_code
|
27
|
+
@error_code ||= payload.dig('error', 'code').to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_message
|
31
|
+
api_error_message || error_payload
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def error_payload
|
37
|
+
error_data = payload.dig('error', 'data')
|
38
|
+
return nil if error_data.empty?
|
39
|
+
|
40
|
+
error_data.map { |error| error['message'] }.join(', ')
|
41
|
+
end
|
42
|
+
|
43
|
+
def api_error_message
|
44
|
+
payload['message']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stash
|
4
|
+
module Rewards
|
5
|
+
class StashReward
|
6
|
+
attr_reader :reward_name, :reward_id, :description, :prices
|
7
|
+
|
8
|
+
def initialize(reward_payload)
|
9
|
+
@reward_name = reward_payload['rewardName']
|
10
|
+
@reward_id = reward_payload['rewardId']
|
11
|
+
@description = reward_payload['description']
|
12
|
+
@prices = reward_payload['denominations'] || []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/stash/rewards.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require_relative 'rewards/version'
|
2
2
|
require_relative 'rewards/api_wrapper'
|
3
|
+
require_relative 'rewards/response'
|
3
4
|
require_relative 'rewards/config'
|
4
5
|
require_relative 'rewards/create_user'
|
5
6
|
require_relative 'rewards/enrol_user_in_campaign'
|
6
7
|
require_relative 'rewards/get_rewards'
|
8
|
+
require_relative 'rewards/get_reward'
|
7
9
|
require_relative 'rewards/issue_voucher'
|
10
|
+
require_relative 'rewards/stash_reward'
|
8
11
|
|
9
12
|
module Stash
|
10
13
|
module Rewards
|
data/stash-rewards.gemspec
CHANGED
@@ -3,8 +3,8 @@ require_relative 'lib/stash/rewards/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'stash-rewards'
|
5
5
|
spec.version = Stash::Rewards::VERSION
|
6
|
-
spec.authors = ['Rui Baltazar']
|
7
|
-
spec.email = ['rui.p.baltazar@gmail.com']
|
6
|
+
spec.authors = ['Rui Baltazar', 'Aayush Jain']
|
7
|
+
spec.email = ['rui.p.baltazar@gmail.com', 'aayush@perxtech.com']
|
8
8
|
|
9
9
|
spec.summary = 'Gem with API wrapper for Stash Rewards'
|
10
10
|
spec.description = 'Helper Library to make api calls to stash rewards'
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
28
|
spec.add_runtime_dependency 'faraday', '~> 1'
|
29
|
-
spec.add_runtime_dependency '
|
29
|
+
spec.add_runtime_dependency 'typhoeus', '~> 1'
|
30
30
|
|
31
31
|
spec.add_development_dependency 'rspec', '~> 3'
|
32
32
|
spec.add_development_dependency 'rspec-file_fixtures', '~> 0'
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stash-rewards
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rui Baltazar
|
8
|
+
- Aayush Jain
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
12
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: faraday
|
@@ -25,19 +26,19 @@ dependencies:
|
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '1'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: typhoeus
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '1'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '1'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,10 +84,12 @@ dependencies:
|
|
83
84
|
description: Helper Library to make api calls to stash rewards
|
84
85
|
email:
|
85
86
|
- rui.p.baltazar@gmail.com
|
87
|
+
- aayush@perxtech.com
|
86
88
|
executables: []
|
87
89
|
extensions: []
|
88
90
|
extra_rdoc_files: []
|
89
91
|
files:
|
92
|
+
- ".github/workflows/test.yml"
|
90
93
|
- ".gitignore"
|
91
94
|
- ".travis.yml"
|
92
95
|
- CODE_OF_CONDUCT.md
|
@@ -103,8 +106,11 @@ files:
|
|
103
106
|
- lib/stash/rewards/config.rb
|
104
107
|
- lib/stash/rewards/create_user.rb
|
105
108
|
- lib/stash/rewards/enrol_user_in_campaign.rb
|
109
|
+
- lib/stash/rewards/get_reward.rb
|
106
110
|
- lib/stash/rewards/get_rewards.rb
|
107
111
|
- lib/stash/rewards/issue_voucher.rb
|
112
|
+
- lib/stash/rewards/response.rb
|
113
|
+
- lib/stash/rewards/stash_reward.rb
|
108
114
|
- lib/stash/rewards/version.rb
|
109
115
|
- stash-rewards.gemspec
|
110
116
|
homepage: https://github.com/PerxTech/stash-rewards
|
@@ -125,9 +131,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
131
|
version: 2.3.0
|
126
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
133
|
requirements:
|
128
|
-
- - "
|
134
|
+
- - ">="
|
129
135
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
136
|
+
version: '0'
|
131
137
|
requirements: []
|
132
138
|
rubygems_version: 3.1.6
|
133
139
|
signing_key:
|