Module: ClickAndSend
- Defined in:
- lib/click_and_send.rb,
lib/click_and_send/xml.rb,
lib/click_and_send/request.rb,
lib/click_and_send/version.rb,
lib/click_and_send/encryption.rb,
lib/click_and_send/configuration.rb,
lib/click_and_send/request/print_item.rb,
lib/click_and_send/request/create_items.rb,
lib/click_and_send/request/delete_items.rb,
lib/click_and_send/request/item_summary.rb,
lib/click_and_send/request/check_services.rb,
lib/click_and_send/request/manifest_items.rb,
lib/click_and_send/request/print_manifest.rb
Defined Under Namespace
Modules: Errors, Request
Classes: Configuration, Encryption, XML
Constant Summary
collapse
- VERSION =
'0.2.5'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
18
19
20
|
# File 'lib/click_and_send.rb', line 18
def configuration
@configuration
end
|
Class Method Details
.check_services(options) ⇒ Object
33
34
35
36
|
# File 'lib/click_and_send.rb', line 33
def check_services(options)
ensure_keys_present(options, %w(Sender Receiver ItemDetails))
Request::CheckServices.new(options).result.fetch(:product_found)
end
|
Example use:
ClickAndSend.configure do |c|
c.account_number = '1234567'
c.api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
c.user_name = 'acme'
c.wsdl = 'https://auspost-staging.oss.neopost-id.com/modules/oss/api/ship/wsdl?sz_Client=AustraliaPost'
end
28
29
30
31
|
# File 'lib/click_and_send.rb', line 28
def configure
self.configuration ||= Configuration.new
yield(configuration)
end
|
.create_items(options) ⇒ Object
38
39
40
41
|
# File 'lib/click_and_send.rb', line 38
def create_items(options)
ensure_keys_present(options, %w(Transactions))
Request::CreateItems.new(options).result.fetch(:item_created)
end
|
.delete_items(options) ⇒ Object
57
58
59
60
|
# File 'lib/click_and_send.rb', line 57
def delete_items(options)
ensure_keys_present(options, %w(DeleteItems))
Request::DeleteItems.new(options).result
end
|
.delete_items_by_ref(refs) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/click_and_send.rb', line 43
def delete_items_by_ref(refs)
refs = refs.collect(&:to_s)
items = find_tracking_numbers(refs).inject([]) do |carrier, (ref, tracking_numbers)|
tracking_numbers.each do |tracking_number|
hash = ActiveSupport::OrderedHash.new
hash['CustTransactionID'] = ref
hash['TrackingNumber' ] = tracking_number
carrier << {'DeleteItem' => hash}
end
carrier
end
delete_items('DeleteItems' => items) if items.any?
end
|
.find_tracking_numbers(refs) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/click_and_send.rb', line 62
def find_tracking_numbers(refs)
refs = refs.collect(&:to_s)
item_summary.inject({}) do |hash,item|
if item.kind_of?(Hash) && refs.include?(item[:cust_transaction_id])
hash[item[:cust_transaction_id]] ||= []
hash[item[:cust_transaction_id]] << item[:tracking_number]
end
hash
end
end
|
.item_pdf_url(ref) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/click_and_send.rb', line 73
def item_pdf_url(ref)
ref = ref.to_s
tracking_numbers = find_tracking_numbers([ref])[ref] || {}
case tracking_numbers.length
when 0 then raise(Errors::APIError, "Not found: '#{ref}'")
when 1 then tracking_number = tracking_numbers.first
else
raise(Errors::APIError, "Expected 1 but found #{tracking_numbers.length} tracking numbers for '#{ref}': #{tracking_numbers.join(', ')}")
end
hash = ActiveSupport::OrderedHash.new
hash['PrintFormat' ] = 'LINK'
hash['CustTransactionID'] = ref
hash['TrackingNumber' ] = tracking_number
Request::PrintItem.new(hash).result
end
|
.item_summary ⇒ Object
89
90
91
|
# File 'lib/click_and_send.rb', line 89
def item_summary
Request::ItemSummary.new.result.fetch(:item_summary_transaction)
end
|
.logger ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/click_and_send.rb', line 93
def logger
@logger ||= begin
configuration.logger or if rails? && !configured_logfile
Rails.logger
else
Logger.new(logfile)
end
end
end
|
.manifest_items(options) ⇒ Object
103
104
105
106
|
# File 'lib/click_and_send.rb', line 103
def manifest_items(options)
ensure_keys_present(options, %w(ManifestItems))
ClickAndSend::Request::ManifestItems.new(options).result
end
|
.manifest_items_by_refs(refs) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/click_and_send.rb', line 108
def manifest_items_by_refs(refs)
tracking_numbers = find_tracking_numbers(refs)
options = {
'ManifestItems' => refs.collect do |ref|
{
'ManifestItem' => ActiveSupport::OrderedHash.new.tap do |hash|
hash['CustTransactionID'] = ref.to_s
hash['TrackingNumber' ] = tracking_numbers[ref.to_s].first
end
}
end
}
manifest_items(options)
end
|
.manifest_pdf_url(options) ⇒ Object
123
124
125
126
|
# File 'lib/click_and_send.rb', line 123
def manifest_pdf_url(options)
ensure_keys_present(options, %w(PrintFormat PrintDetails ManifestNumber))
ClickAndSend::Request::PrintManifest.new(options).result.fetch(:manifest_http_link)
end
|