Module: Passtools::Request
Instance Method Summary collapse
- #construct_url(path) ⇒ Object
- #delete_request(path, params = {}) ⇒ Object
- #download_file(path, filename) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #headers ⇒ Object
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
Instance Method Details
#construct_url(path) ⇒ Object
41 42 43 44 |
# File 'lib/passtools/request.rb', line 41 def construct_url(path) raise "You must configure API url before calling" if Passtools.url.to_s.empty? Passtools.url + path end |
#delete_request(path, params = {}) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/passtools/request.rb', line 34 def delete_request(path, params = {}) url = construct_url(path) params.merge!(:api_key => Passtools.api_key ) response = RestClient.delete(url, headers.merge(:params => params)) MultiJson.load(response) end |
#download_file(path, filename) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/passtools/request.rb', line 11 def download_file(path, filename) filepath = Pathname.new(Passtools.download_dir.to_s) raise "Download directory is not defined or does not exist" unless filepath.exist? url = construct_url(path) params = {:api_key => Passtools.api_key} response = RestClient.get(url, headers.merge(:params => params)) File.open(filepath.join(filename), 'w:ascii-8bit') {|f| f.write(response) } end |
#get(path, params = {}) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/passtools/request.rb', line 4 def get(path, params = {}) url = construct_url(path) params.merge!(:api_key => Passtools.api_key) response = RestClient.get(url, headers.merge(:params => params)) MultiJson.load(response) end |
#headers ⇒ Object
46 47 48 49 |
# File 'lib/passtools/request.rb', line 46 def headers { :user_agent => "passtools-gem-#{Passtools::VERSION}", :accept => :json } end |