Class: OmniAuth::FortnoxOAuth2::API

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/fortnox_oauth2/api.rb

Overview

API

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ API

Returns a new instance of API.



13
14
15
16
# File 'lib/omniauth/fortnox_oauth2/api.rb', line 13

def initialize(token)
  @access_token = token
  @base_uri = 'https://api.fortnox.se/3'
end

Instance Method Details

#get(url) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/omniauth/fortnox_oauth2/api.rb', line 18

def get(url)
  uri = URI([@base_uri, url].join(''))
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = build_request(uri)
  response = http.request(request)
  raise Error, "#{response.code}: #{response.body}" unless response.code == '200'

  JSON.parse(response.body)
end