Skip to content

Commit

Permalink
Merge branch 'master' of github.com:voucherifyio/voucherify-ruby-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
lkulig committed Nov 30, 2017
2 parents defa6d6 + ee61033 commit 3a70e03
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 4 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ API:
|
<a href="#segments-api">Segments</a>
|
<a href="#promotions-api">Promotions</a>
|
<a href="#events-api">Events</a>
|
<a href="#utils">Utils</a>
Expand Down Expand Up @@ -204,10 +206,20 @@ voucherify.distributions.delete_export(export_id)
Methods are provided within `voucherify.validations.*` namespace.

- [Validate Voucher](#validate-voucher)
- [Validate Promotion Campaign](#validate-promotion-campaign)

#### [Validate Voucher]
```ruby
voucherify.validations.validate_voucher(code, [context])

# or

voucherify.validations.validate(code, [context])
```

#### [Validate Promotion Campaign]
```ruby
voucherify.validations.validate(promo_validation_context)
```

---
Expand All @@ -223,8 +235,12 @@ Methods are provided within `voucherify.redemptions.*` namespace.

#### [Redeem Voucher]
```ruby
# Redeem voucher code
voucherify.redemptions.redeem(code, [params])

# Redeem promotion campaign
voucherify.redemptions.redeem(promotions_tier, [params])

# Removed!
voucherify.redemptions.redeem(code, tracking_id) # use: voucherify.redemptions.redeem(code, {:customer => {:source_id => 'source_id'}})
```
Expand Down Expand Up @@ -252,6 +268,50 @@ Check [redemption rollback object](https://docs.voucherify.io/reference?utm_sour

---

### Promotions API
Methods are provided within `voucherify.promotions.*` namespace.

- [Create Promotion Campaign](#create-promotion-campaign)
- [Validate Promotion Campaign](#validate-promotion-campaign)
- [List Promotion's Tiers](#list-promotions-tiers)
- [Create Promotion's Tier](#create-promotions-tier)
- [Redeem Promotion's Tier](#redeem-promotions-tier)
- [Update Promotion's Tier](#update-promotions-tier)
- [Delete Promotion's Tier](#delete-promotions-tier)

Check [promotion campaign object](http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-promotion-campaign).
#### [Create Promotion Campaign]
```ruby
voucherify.promotions.create(promotion_campaign)
```
#### [Validate Promotion Campaign]
```ruby
voucherify.promotions.validate(validation_context)
```
#### [List Promotion's Tiers]
```ruby
voucherify.promotions.tiers.list(promotion_campaign_id)
```
Check [promotion's tier object](http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#the-promotion-object)
#### [Create Promotion's Tier]
```ruby
voucherify.promotions.tiers.create(promotion_id, promotions_tier)
```
#### [Redeem Promotion's Tier]
```ruby
voucherify.promotions.tiers.redeem(promotions_tier_id, redemption_context)
```
#### [Update Promotion's Tier]
```ruby
voucherify.promotions.tiers.update(promotions_tier)
```
#### [Delete Promotion's Tier]
```ruby
voucherify.promotions.tiers.delete(promotions_tier_id)
```

---

### Customers API
Methods are provided within `voucherify.customers.*` namespace.

Expand Down Expand Up @@ -486,6 +546,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
Bug reports and pull requests are welcome on GitHub at https://github.com/rspective/voucherify-ruby-sdk.

## Changelog
- **2017-11-16** - `1.6.0` - Expose promotion API, Redemptions and Validations namespace update
- **2017-11-16** - `1.5.0` - Expose events API
- **2017-05-07** - `1.4.0` - Segments, Validation rules, API Versioning
- **2017-03-22** - `1.3.0` - improved error handling
Expand Down Expand Up @@ -542,6 +603,14 @@ The gem is available as open source under the terms of the [MIT License](http://
[Get Redemption]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-redemption
[Rollback Redemption]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#rollback-redemption

[Create Promotion Campaign]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-promotion-campaign
[Validate Promotion Campaign]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#validate-promotions-1
[List Promotion's Tiers]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-promotions
[Create Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#add-promotion-tier-to-campaign
[Redeem Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#redeem-promotion
[Update Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-promotion
[Delete Promotion's Tier]: http://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#delete-promotion

[Create Customer]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-customer
[Get Customer]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#read-customer
[Update Customer]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-customer
Expand Down
1 change: 1 addition & 0 deletions lib/voucherify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'voucherify/service/events'
require 'voucherify/service/products'
require 'voucherify/service/redemptions'
require 'voucherify/service/promotions'
require 'voucherify/service/segments'
require 'voucherify/service/segments'
require 'voucherify/service/validation_rules'
Expand Down
4 changes: 4 additions & 0 deletions lib/voucherify/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def events
Voucherify::Service::Events.new(self)
end

def promotions
Voucherify::Service::Promotions.new(self)
end

def get(path, params = {})
begin
url = @backend_url + path
Expand Down
54 changes: 54 additions & 0 deletions lib/voucherify/service/promotions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'uri'

module Voucherify
module Service
class Promotions
attr_reader :client

def initialize(client)
@client = client
end

def create(campaign)
@client.campaigns.create(campaign)
end

def validate(validation_context)
@client.post('/promotions/validation', validation_context.to_json)
end

def tiers
Voucherify::Service::PromotionTiers.new(@client)
end
end

class PromotionTiers
attr_reader :client

def initialize(client)
@client = client
end

def list(promotion_id)
@client.get("/promotions/#{URI.encode(promotion_id)}/tiers")
end

def create(promotion_id, promotion_tier)
@client.post("/promotions/#{URI.encode(promotion_id)}/tiers", promotion_tier.to_json)
end

def redeem(promotions_tier_id, redemption_context)
@client.post("/promotions/tiers/#{URI.encode(promotions_tier_id)}/redemption", redemption_context.to_json)
end

def update(promotions_tier)
@client.put("/promotions/tiers/#{URI.encode(promotions_tier['id'] || promotions_tier[:id])}", promotions_tier.to_json)
end

def delete(promotions_tier_id)
@client.delete("/promotions/tiers/#{URI.encode(promotions_tier_id)}")
nil
end
end
end
end
7 changes: 6 additions & 1 deletion lib/voucherify/service/redemptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def initialize(client)
end

def redeem(code, params = {})
@client.post("/vouchers/#{URI.encode(code)}/redemption", params.to_json)
if code.is_a? Hash
endpoint = "/promotions/tiers/#{URI.encode(code[:id] || code['id'])}/redemption"
else
endpoint = "/vouchers/#{URI.encode(code)}/redemption"
end
@client.post(endpoint, params.to_json)
end

def list(query = {})
Expand Down
10 changes: 9 additions & 1 deletion lib/voucherify/service/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ def initialize(client)
def validate_voucher(code, context = {})
@client.post("/vouchers/#{URI.encode(code)}/validate", context.to_json)
end


def validate(code, context = {})
if code.is_a? Hash
context = code
return @client.promotions.validate(context)
end
@client.validations.validate_voucher(code, context)
end

end
end
end
2 changes: 1 addition & 1 deletion lib/voucherify/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Voucherify
VERSION = '1.5.0'
VERSION = '1.6.0'
end
Loading

0 comments on commit 3a70e03

Please sign in to comment.