Class: AnswersEngine::Client::Base
- Inherits:
-
Object
- Object
- AnswersEngine::Client::Base
show all
- Includes:
- HTTParty
- Defined in:
- lib/answersengine/client/base.rb
Direct Known Subclasses
AuthToken, DeployKey, EnvVar, Export, GlobalPage, Job, JobExport, JobLog, JobOutput, JobPage, JobStat, Scraper, ScraperDeployment, ScraperExport, ScraperExporter, ScraperFinisher, ScraperJob, ScraperJobOutput, ScraperJobPage, ScraperJobVar, ScraperVar
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
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
51
|
# File 'lib/answersengine/client/base.rb', line 24
def initialize(opts={})
self.class.base_uri(env_api_url)
self.auth_token = opts[:auth_token] unless opts[:auth_token].nil?
@options = { headers: {
"Authorization" => "Bearer #{auth_token}",
"Content-Type" => "application/json",
}}
query = {}
query[:p] = opts[:page] if opts[:page]
query[:pp] = opts[:per_page] if opts[:per_page]
query[:fetchfail] = opts[:fetch_fail] if opts[:fetch_fail]
query[:parsefail] = opts[:parse_fail] if opts[:parse_fail]
query[:page_type] = opts[:page_type] if opts[:page_type]
query[:gid] = opts[:gid] if opts[:gid]
if opts[:query]
if opts[:query].is_a?(Hash)
query[:q] = opts[:query].to_json
elsif opts[:query].is_a?(String)
query[:q] = JSON.parse(opts[:query]).to_json
end
end
unless query.empty?
@options.merge!(query: query)
end
end
|
Class Method Details
.env_auth_token ⇒ Object
8
9
10
|
# File 'lib/answersengine/client/base.rb', line 8
def self.env_auth_token
ENV['ANSWERSENGINE_TOKEN']
end
|
Instance Method Details
#auth_token ⇒ Object
16
17
18
|
# File 'lib/answersengine/client/base.rb', line 16
def auth_token
@auth_token ||= self.class.env_auth_token
end
|
#auth_token=(value) ⇒ Object
20
21
22
|
# File 'lib/answersengine/client/base.rb', line 20
def auth_token= value
@auth_token = value
end
|
#env_api_url ⇒ Object
12
13
14
|
# File 'lib/answersengine/client/base.rb', line 12
def env_api_url
ENV['ANSWERSENGINE_API_URL'].nil? ? 'https://fetch.answersengine.com/api/v1' : ENV['ANSWERSENGINE_API_URL']
end
|