Class: AppfiguresClient::Net::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/appfigures_client/net/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
# File 'lib/appfigures_client/net/request.rb', line 5

def initialize(options)
  @username = options[:username]
  @password = options[:password]
  @client_key = options[:client_key]
end

Instance Method Details

#make(path = '', params = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/appfigures_client/net/request.rb', line 11

def make(path = '', params = {})
  uri = ::URI.parse(Api::URL + path)
  http = ::Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request_params = params ? '?' + parameterize(params) : ''

  req = ::Net::HTTP::Get.new(uri.path + request_params)
  req.basic_auth @username, @password
  req['X-CLIENT-KEY'] = @client_key

  response = http.request req
  parsed = JSON.parse(response.body)
  parsed.kind_of?(Array) ? parsed.collect {|hash| hash.with_indifferent_access } : parsed.with_indifferent_access
end