Class: Aupost::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aupost.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aupost_key) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/aupost.rb', line 11

def initialize(aupost_key)
  self.aupost_key = aupost_key
end

Instance Attribute Details

#aupost_keyObject

Returns the value of attribute aupost_key.



10
11
12
# File 'lib/aupost.rb', line 10

def aupost_key
  @aupost_key
end

Instance Method Details

#call(uri) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/aupost.rb', line 64

def call(uri)
	req = Net::HTTP::Get.new(uri)
			req['AUTH-KEY'] = @aupost_key
			Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
return JSON.load(http.request(req).read_body)
	end
	
end

#country(format = "json") ⇒ Object



22
23
24
# File 'lib/aupost.rb', line 22

def country(format = "json")
   	call URI("#{Aupost::AUPOST_URL}/postage/country.json")
end

#domestic_letter_sizeObject



34
35
36
# File 'lib/aupost.rb', line 34

def domestic_letter_size
	call URI("#{Aupost::AUPOST_URL}/postage/letter/domestic/size.json")
end

#domestic_letter_thicknessObject



26
27
28
# File 'lib/aupost.rb', line 26

def domestic_letter_thickness
	call URI("#{Aupost::AUPOST_URL}/postage/letter/domestic/thickness.json")
end

#domestic_letter_weightObject



30
31
32
# File 'lib/aupost.rb', line 30

def domestic_letter_weight
	call URI("#{Aupost::AUPOST_URL}/postage/letter/domestic/weight.json")
end

#domestic_parcel_typeObject



50
51
52
# File 'lib/aupost.rb', line 50

def domestic_parcel_type
	call URI("#{Aupost::AUPOST_URL}/postage/parcel/domestic/type.json")
end

#domestic_parcel_weightObject



46
47
48
# File 'lib/aupost.rb', line 46

def domestic_parcel_weight
	call URI("#{Aupost::AUPOST_URL}/postage/parcel/domestic/weight.json")
end

#domestic_postcode_search(text, state = "") ⇒ Object



15
16
17
18
# File 'lib/aupost.rb', line 15

def domestic_postcode_search(text, state = "")

	call URI("#{Aupost::AUPOST_URL}/postcode/search.json?q=#{CGI.escape(text)}&state=#{CGI.escape(state)}")
end

#international_letter_weightObject



38
39
40
# File 'lib/aupost.rb', line 38

def international_letter_weight
	call URI("#{Aupost::AUPOST_URL}/postage/letter/international/weight.json")
end

#international_parcel_weightObject



42
43
44
# File 'lib/aupost.rb', line 42

def international_parcel_weight
	call URI("#{Aupost::AUPOST_URL}/postage/parcel/international/size.json")
end

#postage_letter_domestic_serviceObject



58
59
60
# File 'lib/aupost.rb', line 58

def postage_letter_domestic_service
	call URI("#{Aupost::AUPOST_URL}/postage/parcel/domestic/size.json")
end