Module: Uricp::CurlPrimitives

Included in:
Segmenter, Strategy::Common
Defined in:
lib/uricp/curl_primitives.rb

Constant Summary collapse

ORBIT_HOSTS =
%w[orbit.brightbox.com orbit.gb1s.brightbox.com]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/uricp/curl_primitives.rb', line 5

def options
  @options
end

Instance Method Details

#authenticationObject



27
28
29
# File 'lib/uricp/curl_primitives.rb', line 27

def authentication
  "-H 'X-Auth-Token:#{options['authenticator'].call}'" if http_authentication?
end

#curl_commandObject



23
24
25
# File 'lib/uricp/curl_primitives.rb', line 23

def curl_command
  'curl --fail --silent --location '
end

#curl_download_to_pipeObject



48
49
50
# File 'lib/uricp/curl_primitives.rb', line 48

def curl_download_to_pipe
  "#{curl_command} #{authentication if orbit?(from) && !temp_url?} '#{from}' |"
end

#curl_manifest(object_manifest, destination = to) ⇒ Object



52
53
54
# File 'lib/uricp/curl_primitives.rb', line 52

def curl_manifest(object_manifest, destination = to)
  "#{curl_command} #{authentication} -X PUT -H 'Content-Type: application/octet-stream' -H 'X-Object-Manifest: #{object_manifest}' '#{destination}' --data-binary ''"
end

#curl_upload_from(source, destination = to) ⇒ Object



44
45
46
# File 'lib/uricp/curl_primitives.rb', line 44

def curl_upload_from(source, destination = to)
  "#{curl_command} #{authentication} -H 'Content-Type: application/octet-stream' -T '#{source}' '#{destination}';"
end

#fromObject



7
8
9
# File 'lib/uricp/curl_primitives.rb', line 7

def from
  options['from_uri']
end

#from=(target) ⇒ Object



11
12
13
# File 'lib/uricp/curl_primitives.rb', line 11

def from=(target)
  options['from_uri'] = target
end

#http_authentication?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/uricp/curl_primitives.rb', line 31

def http_authentication?
  options['authenticator']
end

#orbit?(source) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/uricp/curl_primitives.rb', line 35

def orbit?(source)
  return unless source.respond_to?(:host)
  ORBIT_HOSTS.include?(source.host)
end

#temp_url?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/uricp/curl_primitives.rb', line 40

def temp_url?
  from && from.query.to_s.include?('temp_url')
end

#toObject



15
16
17
# File 'lib/uricp/curl_primitives.rb', line 15

def to
  options['to_uri']
end

#to=(target) ⇒ Object



19
20
21
# File 'lib/uricp/curl_primitives.rb', line 19

def to=(target)
  options['to_uri'] = target
end