diff --git a/CHANGELOG.md b/CHANGELOG.md index b939671..c572568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ This file is a manually maintained list of changes for each release. Feel free to add your changes here when sending pull requests. Also send corrections if you spot any mistakes. +## v2.0.7 (2016-01-05) +* Now able to delete assets and templates. + ## v2.0.6 (2015-12-22) * Fixed JSON errors when displaying attributes with a single error (non-array-format). diff --git a/lib/passworks.rb b/lib/passworks.rb index a6b1a6c..e1ea369 100644 --- a/lib/passworks.rb +++ b/lib/passworks.rb @@ -17,6 +17,7 @@ require 'passworks/campaign_resource' require 'passworks/asset_resource' require 'passworks/certificate_resource' +require 'passworks/template_resource' require 'passworks/pass_resource' # Passworks diff --git a/lib/passworks/client.rb b/lib/passworks/client.rb index 0545f62..c266e2a 100644 --- a/lib/passworks/client.rb +++ b/lib/passworks/client.rb @@ -35,7 +35,7 @@ def same_options?(options) # @!method generics # Allows to to access the Generic API # @return [Passworks::RequestProxy] - %w(certificates assets boarding_passes store_cards coupons event_tickets generics).each do |collection_name| + %w(certificates assets templates boarding_passes store_cards coupons event_tickets generics).each do |collection_name| define_method(collection_name) do Passworks::RequestProxy.new(self, collection_name, nil) end diff --git a/lib/passworks/exceptions/invalid_uuid.rb b/lib/passworks/exceptions/invalid_uuid.rb new file mode 100644 index 0000000..1650633 --- /dev/null +++ b/lib/passworks/exceptions/invalid_uuid.rb @@ -0,0 +1,8 @@ +require 'passworks/exception' + +module Passworks + module Exceptions + class InvalidUUID < Exception + end + end +end \ No newline at end of file diff --git a/lib/passworks/inflector.rb b/lib/passworks/inflector.rb index 8bc9481..19f0d4e 100644 --- a/lib/passworks/inflector.rb +++ b/lib/passworks/inflector.rb @@ -9,6 +9,8 @@ def single_name 'asset' when 'certificates' 'certificate' + when 'templates' + 'template' when 'boarding_passes' 'boarding_pass' when 'coupons' @@ -31,10 +33,13 @@ def resource_class return Passworks::AssetResource if collection_name == 'assets' # CertificateResource has no overrides, but follow along the normal flow. return Passworks::CertificateResource if collection_name == 'certificates' + return Passworks::TemplateResource if collection_name == 'templates' if collection_uuid Passworks::PassResource - else + elsif ['boarding_passes', 'coupons', 'store_cards', 'event_tickets', 'generics'].include?(collection_name) Passworks::CampaignResource + else + raise 'Invalid Resource Class' end end diff --git a/lib/passworks/request.rb b/lib/passworks/request.rb index 3d9679a..2ebc59e 100644 --- a/lib/passworks/request.rb +++ b/lib/passworks/request.rb @@ -4,9 +4,9 @@ module Request def request(method, path, options={}) response = agent.send(method) do |request| case method - when :get, :delete + when :get request.url(path, options[:query]) - when :post, :put, :patch + when :post, :put, :patch, :delete request.path = path request.body = options.fetch(:body, {}) end diff --git a/lib/passworks/request_proxy.rb b/lib/passworks/request_proxy.rb index 2bd7c7c..c37c23e 100644 --- a/lib/passworks/request_proxy.rb +++ b/lib/passworks/request_proxy.rb @@ -14,7 +14,7 @@ class RequestProxy # @return [String] Collection UUID attr_reader :collection_uuid - def initialize(client, collection_name, collection_uuid=nil, options={}) + def initialize(client, collection_name, collection_uuid = nil, options = {}) @collection_name = collection_name @collection_uuid = collection_uuid @client = client @@ -30,7 +30,7 @@ def initialize(client, collection_name, collection_uuid=nil, options={}) # @example Fetching the very first coupon pass from the first coupon (campaign) without having to pull all the elements first from the server # client.coupons.all(per_page: 1).first.passes.all(per_page: 1).first # @return [Passworks::CollectionProxy] - def all(options={}) + def all(options = {}) options = { query: options } unless options.empty? CollectionProxy.new(client, collection_name, collection_uuid, options) end @@ -44,6 +44,8 @@ def all(options={}) # pass = client.coupons.all(per_page: 1).first.passes.find('c3d5fc64-3a43-4d3a-a167-473dfeb1edd3') # @return [PassResource.new or CampaignResource] def find(uuid) + # TODO @tparreira add a validation for UUID. + raise Passworks::Exceptions::InvalidUUID.new("The UUID supplied is invalid.") if uuid.empty? if collection_uuid fetch_url = "#{collection_name}/#{collection_uuid}/passes/#{uuid}" else diff --git a/lib/passworks/template_resource.rb b/lib/passworks/template_resource.rb new file mode 100644 index 0000000..307d828 --- /dev/null +++ b/lib/passworks/template_resource.rb @@ -0,0 +1,19 @@ +module Passworks + class TemplateResource < Resource + + # Deletes the current Template + # @return [Boolean] + def delete(delete_assets = true) + content = { + body: { + single_name.to_sym => { + delete_assets: delete_assets + } + } + } + response = client.delete("#{collection_name}/#{id}", content) + end + alias_method :destroy, :delete + + end +end \ No newline at end of file diff --git a/lib/passworks/version.rb b/lib/passworks/version.rb index 9e10d96..acdad1a 100644 --- a/lib/passworks/version.rb +++ b/lib/passworks/version.rb @@ -1,3 +1,3 @@ module Passworks - VERSION = "2.0.6" + VERSION = "2.0.7" end \ No newline at end of file