Class: AppfiguresClient::Net::Request
- Inherits:
-
Object
- Object
- AppfiguresClient::Net::Request
- Defined in:
- lib/appfigures_client/net/request.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Request
constructor
A new instance of Request.
- #make(path = '', params = {}) ⇒ Object
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() @username = [:username] @password = [:password] @client_key = [: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 |