A simple Ruby client for the Roku Web Service Api.
Add this line to your application's Gemfile:
gem 'roku-iap'
And then execute:
$ bundle
Or install it yourself as:
$ gem install roku-iap
##Usage
Initialize a client with your Roku API key:
client = Roku::Iap::Client.new 'roku_api_key'
Call any of the following methods (outlined in the Roku sdk docs):
result = client.validate_transaction 'some-transaction-id'
result = client.validate_refund 'some-refund-id'
result = client.cancel_subscription 'some-tranasaction-id', 'cancellation_date', 'partner_ref_id'
result = client.refund_subscription 'some-transaction-id', 'amount', 'partner_ref_id', 'comments'
The returned Roku::Iap::Response object has underscored attributes correlating to the xml returned by the Roku API. successful?
can be called on the result to confirm that the response contains no errors.
result = client.validate_transaction 'some-transaction-id'
if result.successful?
puts result.amount #"9.99"
puts result.purchase_date #"2014-11-03T00:07:23"
else
puts result.error_message #"Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
end
Non-200 status code responses will raise a Roku::Iap::Exceptions::General exception, and are distinct from errors returned by the Roku API (which you may call result.error_message
to elaborate upon). A 404 can be presumed to be a nil devtoken parameter, and will raise a Roku::Iap::Exceptions::InvalidCredentials exception.
All defined exceptions inherit from Roku::Iap::Exceptions::Exception, and can be handled as:
begin
result = client.validate_transaction 'some-transaction-id'
rescue Roku::Iap::Exceptions::Exception => e
# enqueue to try again later
end
- Fork it
- Create your feature branch (
git checkout -b some-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin some-new-feature
) - Create new Pull Request