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



26
27
28
29
30
31
32
33
# File 'lib/aupost.rb', line 26

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_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