Skip to content

Commit

Permalink
Treat referral as optional param, add new tracking method for events
Browse files Browse the repository at this point in the history
  • Loading branch information
lkulig committed Feb 19, 2019
1 parent 1618376 commit f0e21ae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ Methods are provided within `voucherify.events.*` namespace.
voucherify.events.track(event, metadata, customer, referral);
```

```ruby
voucherify.events.track_event(data);
```
---

### Migration from 0.x
Expand Down Expand Up @@ -577,6 +580,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
- **2019-02-19** - `2.1.1` - Treat `referral` as optional in custom events. Added new method for custom event tracking.
- **2019-02-19** - `2.1.0` - Handle `referral` in custom events tracking.
- **2018-12-27** - `2.0.0` - Business validation rules.
- **2018-09-05** - `1.6.1` - Request timeout settings
Expand Down
6 changes: 5 additions & 1 deletion lib/voucherify/service/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ def initialize(client)
@client = client
end

def track(event, metadata, customer, referral)
def track(event, metadata, customer, referral = nil)
@client.post('/events', {
:event => event,
:metadata => metadata,
:customer => customer,
:referral => referral
}.to_json)
end

def track_event(event)
@client.post('/events', event.to_json)
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 = '2.1.0'
VERSION = '2.1.1'
end
15 changes: 10 additions & 5 deletions spec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
:customer => {
:id => 'cust_test_id'
},
:referral => {
:code => "123",
:referrer_id => "referrer_id"
}
:referral => nil
}}

let(:custom_event_response) {{
Expand All @@ -38,7 +35,15 @@
.with(body: custom_event_payload.to_json, headers: headers)
.to_return(:status => 200, :body => custom_event_response.to_json, :headers => {})

voucherify.events.track('custom_event_name', { :test => true }, { :id => 'cust_test_id' }, { :code => "123", :referrer_id => "referrer_id" })
voucherify.events.track('custom_event_name', { :test => true }, { :id => 'cust_test_id' })
end

it 'should track custom event' do
stub_request(:post, 'https://api.voucherify.io/v1/events')
.with(body: custom_event_payload.to_json, headers: headers)
.to_return(:status => 200, :body => custom_event_response.to_json, :headers => {})

voucherify.events.track_event(custom_event_payload)
end

end

0 comments on commit f0e21ae

Please sign in to comment.