Class: Chimps::Workflows::Upload::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/chimps/workflows/upload/notifier.rb

Overview

Encapsulates the process of notifying Infochimps of new data that’s already been uploaded.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, bundler) ⇒ Notifier

Returns a new instance of Notifier.



19
20
21
22
# File 'lib/chimps/workflows/upload/notifier.rb', line 19

def initialize token, bundler
  self.token   = token
  self.bundler = bundler
end

Instance Attribute Details

#bundlerObject

The bundler responsible for the upload.



17
18
19
# File 'lib/chimps/workflows/upload/notifier.rb', line 17

def bundler
  @bundler
end

#responseObject

The response from Infochimps to the request to create a package.



11
12
13
# File 'lib/chimps/workflows/upload/notifier.rb', line 11

def response
  @response
end

#tokenObject

The upload token used for the upload.



14
15
16
# File 'lib/chimps/workflows/upload/notifier.rb', line 14

def token
  @token
end

Instance Method Details

#dataHash

Information about the uplaoded data to pass to Infochimps when notifying.

Returns:



36
37
38
# File 'lib/chimps/workflows/upload/notifier.rb', line 36

def data
  { :package => {:fmt => token['fmt'], :pkg_size => bundler.size, :pkg_fmt => bundler.pkg_fmt, :summary => bundler.summary, :token_timestamp => token['timestamp'] } }
end

#pathString

The path on Infochimps to submit package creation requests to.

Returns:



28
29
30
# File 'lib/chimps/workflows/upload/notifier.rb', line 28

def path
  "/datasets/#{bundler.dataset}/packages.json"
end

#postChimps::Response

Make a request to notify Infochimps of the new data.

Returns:



43
44
45
46
47
48
49
50
# File 'lib/chimps/workflows/upload/notifier.rb', line 43

def post
  @response = Request.new(path, :signed => true, :data => data).post
  if response.error?
    response.print
    raise UploadError.new("Unable to notify Infochimps of newly uploaded data.")
  end
  response
end