Module: EasyPost
- Defined in:
- lib/easypost.rb,
lib/easypost/address.rb,
lib/easypost/postage.rb,
lib/easypost/errors/easypost_error.rb,
lib/easypost/errors/authentication_error.rb
Defined Under Namespace
Classes: Address, AuthenticationError, EasyPostError, Postage
Constant Summary
collapse
- @@api_key =
"..."
- @@api_base =
'https://www.easypost.co/api/'
Class Method Summary
collapse
Class Method Details
.api_key ⇒ Object
17
18
19
|
# File 'lib/easypost.rb', line 17
def self.api_key
@@api_key
end
|
.api_key=(api_key) ⇒ Object
13
14
15
|
# File 'lib/easypost.rb', line 13
def self.api_key=(api_key)
@@api_key = api_key
end
|
.api_url(args = {}) ⇒ Object
8
9
10
11
|
# File 'lib/easypost.rb', line 8
def self.api_url(args={})
raise ArgumentError unless args.keys.eql?([:type, :action])
return "#{@@api_base}#{args[:type]}/#{args[:action]}"
end
|
.get(url, params = {}) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/easypost.rb', line 39
def self.get(url, params={})
params = {:userpwd => @@api_key, :params => params}
@response = Typhoeus::Request.get(url, params)
puts "EasyPost Response Body: "
puts @response.body
return EasyPost.symbolize_keys_recursive(JSON.parse(@response.body))
end
|
.post(url, params = {}) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/easypost.rb', line 47
def self.post(url, params={})
params = {:userpwd => @@api_key, :params => params}
@response = Typhoeus::Request.post(url, params)
puts "EasyPost Response Body: "
puts @response.body
return EasyPost.symbolize_keys_recursive(JSON.parse(@response.body))
end
|
.symbolize_keys(hash = {}) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/easypost.rb', line 21
def self.symbolize_keys(hash={})
hash.keys.each do |key|
hash[(key.to_sym rescue key) || key] = hash.delete(key)
end
return hash
end
|
.symbolize_keys_recursive(hash = {}) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/easypost.rb', line 28
def self.symbolize_keys_recursive(hash={})
hash.keys.each do |key|
keysym = (key.to_sym rescue key) || key
hash[keysym] = hash.delete(key)
if hash[keysym].is_a?(Hash)
hash[keysym] = symbolize_keys_recursive(hash[keysym])
end
end
return hash
end
|