Class: Datashake::ReviewScraper::V2

Inherits:
Object
  • Object
show all
Defined in:
lib/datashake-ruby-sdk/review_scraper/v2.rb,
lib/datashake-ruby-sdk/review_scraper/v2/error.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles.rb,
lib/datashake-ruby-sdk/review_scraper/v2/response.rb,
lib/datashake-ruby-sdk/review_scraper/v2/job_instance.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/add.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/job.rb,
lib/datashake-ruby-sdk/review_scraper/v2/bulk_response.rb,
lib/datashake-ruby-sdk/review_scraper/v2/jobs_instance.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/info.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/jobs.rb,
lib/datashake-ruby-sdk/review_scraper/v2/review_instance.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profile_instance.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/reviews.rb,
lib/datashake-ruby-sdk/review_scraper/v2/profiles/add_bulk.rb,
lib/datashake-ruby-sdk/review_scraper/v2/review_response_instance.rb

Defined Under Namespace

Classes: BulkResponse, Error, JobInstance, JobsInstance, ProfileInstance, Profiles, Response, ReviewInstance, ReviewResponseInstance

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ V2

Returns a new instance of V2.



16
17
18
# File 'lib/datashake-ruby-sdk/review_scraper/v2.rb', line 16

def initialize(client)
  @client = client
end

Instance Method Details

#connectionObject



24
25
26
# File 'lib/datashake-ruby-sdk/review_scraper/v2.rb', line 24

def connection
  client.connection
end

#fetch(method:, path:, params: {}, body: {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/datashake-ruby-sdk/review_scraper/v2.rb', line 28

def fetch(method:, path:, params: {}, body: {})
  response = connection.public_send(method, path) do |request|
    request.params = params
    request.body = body.to_json
  end

  body = response.body

  raise Datashake::ReviewScraper::V2::Error.new("Server error", 500) if response.status >= 500

  return body if body.is_a?(Array)
  return body if body["status"].is_a?(String)
  return body if body["jobs"]
  return body if body["status"] == 200

  raise Datashake::ReviewScraper::V2::Error.new(
    body["message"],
    body.fetch("status", response.status)
  )
end

#profilesObject



20
21
22
# File 'lib/datashake-ruby-sdk/review_scraper/v2.rb', line 20

def profiles
  @profiles ||= Profiles.new(self)
end