From 5238f9458b735dbbc871c096c6dda862378a2257 Mon Sep 17 00:00:00 2001 From: awilczek Date: Fri, 16 Jul 2021 16:19:43 +0200 Subject: [PATCH] Support for Async Actions --- .gitignore | 1 + README.md | 19 ++++++++++++ lib/voucherify.rb | 1 + lib/voucherify/client.rb | 4 +++ lib/voucherify/service/async_actions.rb | 22 ++++++++++++++ spec/async_actions_spec.rb | 39 +++++++++++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 lib/voucherify/service/async_actions.rb create mode 100644 spec/async_actions_spec.rb diff --git a/.gitignore b/.gitignore index ff7cc581..cd7b08eb 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ Gemfile.lock # Jetbrains temp .idea +*.iml .ruby-version .vscode/ diff --git a/README.md b/README.md index d580dc96..00b3ff7c 100644 --- a/README.md +++ b/README.md @@ -667,6 +667,22 @@ voucherify.events.track(event, metadata, customer, referral); ```ruby voucherify.events.track_event(data); ``` + +### Async Actions API +Methods are provided within `voucherify.async_actions.*` namespace. +- [Get Async Action](#get-async-action) +- [List Async Actions](#list-async-actions) + +#### [Get Async Action] +```java +voucherify.async_actions.get(id); +``` + +#### [List Async Actions] +```java +voucherify.async_actions.list(query); +``` + --- ### Migration from 0.x @@ -795,6 +811,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/rspect The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). +[Get Async Action]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#get-async-actions-1 +[List Async Actions]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#list-async-actions + [Create Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#create-voucher [Get Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#vouchers-get [Update Voucher]: https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#update-voucher diff --git a/lib/voucherify.rb b/lib/voucherify.rb index 621b9d7a..fab815f9 100644 --- a/lib/voucherify.rb +++ b/lib/voucherify.rb @@ -1,5 +1,6 @@ require 'voucherify/version' require 'voucherify/client' +require 'voucherify/service/async_actions' require 'voucherify/service/campaigns' require 'voucherify/service/customers' require 'voucherify/service/distributions' diff --git a/lib/voucherify/client.rb b/lib/voucherify/client.rb index 94f4761e..270c2c4b 100644 --- a/lib/voucherify/client.rb +++ b/lib/voucherify/client.rb @@ -20,6 +20,10 @@ def initialize (options) @timeout = @options[:timeout] || @options['timeout'] end + def async_actions + Voucherify::Service::AsyncActions.new(self) + end + def vouchers Voucherify::Service::Vouchers.new(self) end diff --git a/lib/voucherify/service/async_actions.rb b/lib/voucherify/service/async_actions.rb new file mode 100644 index 00000000..4e3956f9 --- /dev/null +++ b/lib/voucherify/service/async_actions.rb @@ -0,0 +1,22 @@ +require 'uri' + +module Voucherify + module Service + class AsyncActions + attr_reader :client + + def initialize(client) + @client = client + end + + def get(id) + @client.get("/async-actions/#{ERB::Util.url_encode(id)}") + end + + def list(query) + @client.get('/async-actions', query) + end + + end + end +end \ No newline at end of file diff --git a/spec/async_actions_spec.rb b/spec/async_actions_spec.rb new file mode 100644 index 00000000..05ffd6e3 --- /dev/null +++ b/spec/async_actions_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' +require 'rest-client' + +describe 'Async actions API' do + + let(:application_id) { 'application_id' } + let(:client_secret_key) { 'client_secret_key' } + let(:voucherify) { Voucherify::Client.new({:applicationId => application_id, :clientSecretKey => client_secret_key}) } + let(:headers) { { + 'X-App-Id' => application_id, + 'X-App-Token' => client_secret_key, + 'X-Voucherify-Channel' => 'Ruby-SDK', + :accept => 'application/json' + } } + + let(:id) { 'test-id' } + + it 'should get async action by id' do + stub_request(:get, "https://api.voucherify.io/v1/async-actions/#{id}") + .with(body: {}, headers: headers) + .to_return(:status => 200, :body => '{}', :headers => {}) + + voucherify.async_actions.get(id) + end + + it 'should list async actions' do + query = { + :limit => 10, + :end_date => '2021-07-16T13:58:45Z' + } + + stub_request(:get, "https://api.voucherify.io/v1/async-actions?limit=#{query[:limit]}&end_date=#{query[:end_date]}") + .with(body: {}, headers: headers) + .to_return(:status => 200, :body => '[]', :headers => {}) + + voucherify.async_actions.list query + end + +end