Class: CueCloudRequest

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cuecloud/cuecloud_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_pass, base_url = nil) ⇒ CueCloudRequest

base_uri CueCloudApi::DEFAULT_BASE_URL + CueCloudApi::API_VERSION



12
13
14
15
16
17
18
19
20
21
# File 'lib/cuecloud/cuecloud_request.rb', line 12

def initialize(api_key, api_pass,base_url=nil)
  @api_key = api_key.to_s
  @api_pass = api_pass.to_s
  @auth_key = {username: api_key, password: api_pass}
  if base_url
    @base_url = base_url
  else
    @base_url = CueCloudApi::DEFAULT_BASE_URL + CueCloudApi::API_VERSION
  end
end

Instance Attribute Details

#api_keyObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def api_key
  @api_key
end

#api_passObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def api_pass
  @api_pass
end

#auth_keyObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def auth_key
  @auth_key
end

#base_urlObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def base_url
  @base_url
end

#bodyObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def body
  @body
end

#loggerObject (readonly)

uncomment the following line to debug the entire http party and have fun ! debug_output $stdout



8
9
10
# File 'lib/cuecloud/cuecloud_request.rb', line 8

def logger
  @logger
end

Instance Method Details

#build_request(resource, method, data = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cuecloud/cuecloud_request.rb', line 23

def build_request(resource, method, data=nil)

  url = build_url(resource)
  body = prepare_body(method, data)
  nonce = generate_nonce

  message = nonce + url + body

  headers = {
      'Access-Key' => api_key,
      'Access-Signature' => signature(message),
      'Access-Nonce' => nonce,
      'Content-Type' => 'application/json',
  }

  request_call(method, url, auth_key, headers, data)

end