Class: Glassdoor::Utils::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/glassdoor/utils/api.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApi

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

.instanceObject



10
11
12
# File 'lib/glassdoor/utils/api.rb', line 10

def self.instance
  Glassdoor::Utils::Api.new
end

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(options={})
  uri = Addressable::URI.parse(Glassdoor.configuration.base_url)
  uri.query_values = options.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