Skip to content

Commit

Permalink
Now able to delete templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Parreira committed Jan 4, 2016
1 parent 9ae25c3 commit a6735dd
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
1 change: 1 addition & 0 deletions lib/passworks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/passworks/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/passworks/exceptions/invalid_uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'passworks/exception'

module Passworks
module Exceptions
class InvalidUUID < Exception
end
end
end
7 changes: 6 additions & 1 deletion lib/passworks/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def single_name
'asset'
when 'certificates'
'certificate'
when 'templates'
'template'
when 'boarding_passes'
'boarding_pass'
when 'coupons'
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/passworks/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/passworks/request_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lib/passworks/template_resource.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/passworks/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Passworks
VERSION = "2.0.6"
VERSION = "2.0.7"
end

0 comments on commit a6735dd

Please sign in to comment.