Module: IdealPostcodes
- Defined in:
- lib/idealpostcodes.rb,
lib/idealpostcodes/key.rb,
lib/idealpostcodes/util.rb,
lib/idealpostcodes/errors.rb,
lib/idealpostcodes/address.rb,
lib/idealpostcodes/version.rb,
lib/idealpostcodes/postcode.rb
Defined Under Namespace
Modules: Address, Key, Postcode Classes: AuthenticationError, IdealPostcodesError, LimitReachedError, ResourceNotFoundError, TokenExhaustedError, Util
Constant Summary collapse
- VERSION =
'2.0.0'
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.base_url ⇒ Object
Returns the value of attribute base_url.
-
.secret ⇒ Object
Returns the value of attribute secret.
-
.version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .apply_secret(secret) ⇒ Object
- .key_available ⇒ Object
- .key_details ⇒ Object
- .request(method, path, params = {}) ⇒ Object
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
21 22 23 |
# File 'lib/idealpostcodes.rb', line 21 def api_key @api_key end |
.base_url ⇒ Object
Returns the value of attribute base_url.
21 22 23 |
# File 'lib/idealpostcodes.rb', line 21 def base_url @base_url end |
.secret ⇒ Object
Returns the value of attribute secret.
21 22 23 |
# File 'lib/idealpostcodes.rb', line 21 def secret @secret end |
.version ⇒ Object
Returns the value of attribute version.
21 22 23 |
# File 'lib/idealpostcodes.rb', line 21 def version @version end |
Class Method Details
.apply_secret(secret) ⇒ Object
52 53 54 |
# File 'lib/idealpostcodes.rb', line 52 def self.apply_secret(secret) @secret = secret end |
.key_available ⇒ Object
56 57 58 59 |
# File 'lib/idealpostcodes.rb', line 56 def self.key_available response = Key.lookup @api_key response[:available] end |
.key_details ⇒ Object
61 62 63 64 65 |
# File 'lib/idealpostcodes.rb', line 61 def self.key_details raise IdealPostcodes::AuthenticationError.new('No Secret Key provided. ' + 'Set your secret key with IdealPostcodes.apply_secret #your_key') if @secret.nil? response = Key.lookup_details @api_key, @secret end |
.request(method, path, params = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/idealpostcodes.rb', line 24 def self.request(method, path, params = {}) unless @api_key raise IdealPostcodes::AuthenticationError.new('No API Key provided. ' + 'Set your key with IdealPostcodes.api_key = #your_key') end url = URI.parse(resource_url(path)) params.merge! api_key: @api_key url.query = Util.merge_params(params) = { method: method.downcase.to_sym, url: url.to_s } begin response = generate_request() rescue RestClient::ExceptionWithResponse => error if rcode = error.http_code && rbody = error.http_body handle_error(rcode, rbody) else handle_client_error(error) end rescue RestClient::Exception, Errno::ECONNREFUSED => error handle_client_error(error) end parse response.body end |