Class: Biffbot::Bulk
- Includes:
- Hashie::Extensions::Coercion
- Defined in:
- lib/biffbot/bulk.rb
Instance Method Summary collapse
-
#create_job(name, api_type, urls = [], options = {}) ⇒ Hash
create a bulk job.
-
#generate_post_body(name, api_url, urls = [], options = {}) ⇒ Hash
generate the POST body required for bulk job creation.
-
#initialize(token = Biffbot.token) ⇒ Bulk
constructor
a new instance of Biffbot::Bulk.
-
#retrieve_data(jobName, _options = {}) ⇒ Hash
retrieve data per given jobName.
Methods inherited from Base
#generate_url, #parse, #parse_options
Constructor Details
Instance Method Details
#create_job(name, api_type, urls = [], options = {}) ⇒ Hash
create a bulk job
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/biffbot/bulk.rb', line 22 def create_job name, api_type, urls = [], = {} api_url = "http://api.diffbot.com/v2/#{api_type}" api_url = "http://api.diffbot.com/#{[:version]}/#{api_type}" if [:version] == 'v2' || [:version] == 'v3' api_url = (, api_url) endpoint = 'http://api.diffbot.com/v3/bulk' post_body = generate_post_body(name, api_url, urls, ) JSON.parse(HTTParty.post(endpoint, body: post_body.to_json, headers: {'Content-Type' => 'application/json'}).body).each_pair do |k, v| self[k] = v end end |
#generate_post_body(name, api_url, urls = [], options = {}) ⇒ Hash
generate the POST body required for bulk job creation
40 41 42 43 44 45 46 47 |
# File 'lib/biffbot/bulk.rb', line 40 def generate_post_body name, api_url, urls = [], = {} post_body = {token: @token, name: name, apiUrl: api_url, urls: urls} .each do |key, value| next unless %w(notifyEmail maxRounds notifyWebHook pageProcessPattern).include?(key.to_s) post_body[key] = value end post_body end |
#retrieve_data(jobName, _options = {}) ⇒ Hash
retrieve data per given jobName
71 72 73 74 75 76 77 |
# File 'lib/biffbot/bulk.rb', line 71 def retrieve_data jobName, = {} # TODO: add support for csv endpoint = "http://api.diffbot.com/v3/bulk/download/#{@token}-#{jobName}_data.json" JSON.parse(HTTParty.get(endpoint).body).each_pair do |key, value| self[key] = value end end |