class BigShift::BaseCommand

Public Class Methods

execute(*args) click to toggle source
# File lib/big_shift/commands/base_command.rb, line 4
def execute(*args)
  self.new(*args).execute
end

Public Instance Methods

execute() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 9
def execute
  @access_token = AccessTokenService.retrieve_token
  @response = on_execute
  scrub @response
  @response
end

Private Instance Methods

base_url() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 34
def base_url
  'https://www.googleapis.com/bigquery/v2/projects/%s/datasets/%s' % [
    project_id,
    dataset_id,
  ]
end
connection() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 18
def connection
  Faraday.new(:url => base_url)
end
dataset_id() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 62
def dataset_id
  ENV['BIG_SHIFT_DATASET_ID']
end
headers() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 45
def headers
  {
    'Content-Type' => 'application/json',
    'Authorization' => "Bearer #{@access_token}",
  }
end
params() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 52
def params
  {
    :key => @access_token,
  }
end
patch() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 26
def patch
  connection.patch url, request_body, headers
end
post() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 22
def post
  connection.post url, request_body, headers
end
project_id() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 58
def project_id
  ENV['BIG_SHIFT_PROJECT_ID']
end
request_body() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 41
def request_body
  body.to_json
end
scrub(response) click to toggle source
# File lib/big_shift/commands/base_command.rb, line 66
def scrub(response)
  response.scrub @access_token, 'ACCESS_TOKEN'
  response.scrub project_id,   'PROJECT_ID'
  response.scrub dataset_id,   'DATASET_ID'
end
url() click to toggle source
# File lib/big_shift/commands/base_command.rb, line 30
def url
  connection.build_url endpoint, params
end