Class: DigitSend::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/digitsend/client.rb

Class Method Summary collapse

Class Method Details

.call(path, params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/digitsend/client.rb', line 8

def call(path, params)
  http = Net::HTTP.new(Config.host, Config.port)
  http.use_ssl = Config.use_ssl

  response = http.post path, params && params.to_json,
    'Content-Type' => 'application/json',
    'Accept' => 'application/vnd.digitsend.v1',
    'Authorization' => %Q[Token token="#{Config.api_token}"]

  hash = JSON.parse(response.body)

  if response.code != "200"
    raise exception_for_response(hash)
  else
    hash["data"]
  end
end

.stream_for_data(path, data) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/digitsend/client.rb', line 37

def stream_for_data(path, data)
  if data.nil?
    File.open(path, "r")
  elsif data.is_a?(String)
    StringIO.new(data)
  else
    data
  end
end

.upload_s3_file(path, data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/digitsend/client.rb', line 26

def upload_s3_file(path, data)
   response = create_s3_file(File.basename(path))

   upload_to_s3 \
     URI.parse(response["url"]),
     response["fields"],
     stream_for_data(path, data)

   response["uuid"]
end