Class: Gemnasium::Connection
- Inherits:
-
Object
- Object
- Gemnasium::Connection
- Defined in:
- lib/gemnasium/connection.rb
Instance Method Summary collapse
-
#api_path_for(item) ⇒ String
Set the API path for a specific item.
- #get(path, headers = {}) ⇒ Object
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #post(path, body, headers = {}) ⇒ Object
Constructor Details
Instance Method Details
#api_path_for(item) ⇒ String
Set the API path for a specific item
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gemnasium/connection.rb', line 27 def api_path_for item base = "/api/#{Gemnasium.config.api_version}" case item when 'base' base when 'projects' "#{base}/projects" when 'dependency_files' "#{base}/projects/#{Gemnasium.config.project_slug}/dependency_files" else raise "No API path found for #{item}" end end |
#get(path, headers = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/gemnasium/connection.rb', line 17 def get(path, headers = {}) request = Net::HTTP::Get.new(path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json')) request.basic_auth('X', Gemnasium.config.api_key) @connection.request(request) end |
#post(path, body, headers = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/gemnasium/connection.rb', line 10 def post(path, body, headers = {}) request = Net::HTTP::Post.new(path, headers.merge('Accept' => 'application/json', 'Content-Type' => 'application/json')) request.basic_auth('X', Gemnasium.config.api_key) request.body = body @connection.request(request) end |