Class: SellsyV2::Request
- Inherits:
-
Object
- Object
- SellsyV2::Request
- Defined in:
- lib/sellsy_v2.rb
Overview
Your code goes hereā¦
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(verb:, path:, options:) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(verb:, path:, options:) ⇒ Request
Returns a new instance of Request.
15 16 17 18 |
# File 'lib/sellsy_v2.rb', line 15 def initialize(verb:, path:, options:) params = '?' + .map{|k,v| v.class == Array ? "#{k}[]=#{v.join(',')}" : "#{k}=#{v}"}.join('&') @url = URI("https://api.sellsy.com/v2#{path}#{params}") end |
Instance Method Details
#call ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sellsy_v2.rb', line 20 def call https = Net::HTTP.new(@url.host, @url.port) https.use_ssl = true request = Net::HTTP::Get.new(@url) # change to verb request["Authorization"] = ENV["SELLSY_TOKEN"] response = https.request(request) if response.is_a?(Net::HTTPOK) OpenStruct.new(success?: true, data: JSON.parse(response.read_body)) else OpenStruct.new(success?: false, data: response) end end |