Class: Embulk::Output::GoogleAnalytics::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk/output/google_analytics/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(task) ⇒ Client

Returns a new instance of Client.



7
8
9
# File 'lib/embulk/output/google_analytics/client.rb', line 7

def initialize(task)
  @task = task
end

Instance Method Details

#serviceObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/embulk/output/google_analytics/client.rb', line 23

def service
  analytics_service = ::Google::Apis::AnalyticsV3::AnalyticsService.new
  analytics_service.authorization = Signet::OAuth2::Client.new({
    :token_credential_uri => @task["token_credential_uri"],
    :audience => @task["audience"],
    :client_id => @task["client_id"],
    :client_secret => @task["client_secret"],
    :refresh_token => @task["refresh_token"],
    :scope => @task["scope"],
  })
  analytics_service.authorization.fetch_access_token!
  analytics_service
end

#upload(rows) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/embulk/output/google_analytics/client.rb', line 11

def upload(rows)
  self.service.upload_data(@task['account_id'], @task['webproperty_id'], @task['datasource_id'], {
    upload_source: make_upload_content(rows),
    content_type: 'application/octet-stream',
    options: {
      header: {
        'x-goog-upload-file-name' => @task['filename'],
      }
    }
  })
end