Class: Glassdoor::Utils::Api
- Inherits:
-
Object
- Object
- Glassdoor::Utils::Api
- Defined in:
- lib/glassdoor/utils/api.rb
Class Method Summary collapse
Instance Method Summary collapse
- #gd_get(options = {}) ⇒ Object
-
#initialize ⇒ Api
constructor
A new instance of Api.
- #validate_response(response_hash) ⇒ Object
Constructor Details
#initialize ⇒ Api
Returns a new instance of Api.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/glassdoor/utils/api.rb', line 14 def initialize @default_params = { 't.p' => Glassdoor.configuration.partner_id, 't.k' => Glassdoor.configuration.partner_key, userip: '0.0.0.0', useragent: '', v: Glassdoor.configuration.version_api, format: 'json', page: '' } end |
Class Method Details
Instance Method Details
#gd_get(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/glassdoor/utils/api.rb', line 26 def gd_get(={}) uri = Addressable::URI.parse(Glassdoor.configuration.base_url) uri.query_values = .merge(@default_params) response = RestClient::Request.execute(method: :get, url: uri.to_s, timeout: Glassdoor.configuration.time_out) response_hash = MultiJson.load(response) validate_response(response_hash) end |
#validate_response(response_hash) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/glassdoor/utils/api.rb', line 35 def validate_response(response_hash) unless response_hash['success'] raise ResponseUnsuccessError.new response_hash['status'] end response_hash['response'] end |