Class: Tikkie::Api::Request
- Inherits:
-
Object
- Object
- Tikkie::Api::Request
- Defined in:
- lib/tikkie/api/request.rb
Overview
Make authenticated HTTP requests to the Tikkie API.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(config) ⇒ Request
constructor
A new instance of Request.
- #post(path, params = {}) ⇒ Object
Constructor Details
#initialize(config) ⇒ Request
Returns a new instance of Request.
10 11 12 |
# File 'lib/tikkie/api/request.rb', line 10 def initialize(config) @config = config end |
Instance Method Details
#get(path, params = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tikkie/api/request.rb', line 14 def get(path, params = {}) uri = URI.parse(File.join(@config.api_url, path)) uri.query = URI.encode_www_form(params) unless params.empty? request = Net::HTTP::Get.new(uri) request["Api-Key"] = @config.api_key request["Authorization"] = "Bearer #{access_token}" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end response end |
#post(path, params = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tikkie/api/request.rb', line 29 def post(path, params = {}) uri = URI.parse(File.join(@config.api_url, path)) request = Net::HTTP::Post.new(uri) request["Api-Key"] = @config.api_key request["Authorization"] = "Bearer #{access_token}" request["Content-Type"] = "application/json" request.body = params.to_json response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end response end |