Class: AccessGrid::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/accessgrid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id, api_secret, api_host = 'https://api.accessgrid.com') ⇒ Client

Returns a new instance of Client.



21
22
23
24
25
# File 'lib/accessgrid.rb', line 21

def initialize(, api_secret, api_host = 'https://api.accessgrid.com')
  @account_id = 
  @api_secret = api_secret
  @api_host = api_host
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



19
20
21
# File 'lib/accessgrid.rb', line 19

def 
  @account_id
end

#api_hostObject (readonly)

Returns the value of attribute api_host.



19
20
21
# File 'lib/accessgrid.rb', line 19

def api_host
  @api_host
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



19
20
21
# File 'lib/accessgrid.rb', line 19

def api_secret
  @api_secret
end

Instance Method Details

#access_cardsObject



27
28
29
# File 'lib/accessgrid.rb', line 27

def access_cards
  @access_cards ||= AccessCards.new(self)
end

#consoleObject



31
32
33
# File 'lib/accessgrid.rb', line 31

def console
  @console ||= Console.new(self)
end

#make_request(method, path, body = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/accessgrid.rb', line 35

def make_request(method, path, body = nil)
  uri = URI.parse("#{api_host}#{path}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'

  # Create request object based on method
  request = case method
  when :get
    Net::HTTP::Get.new(uri.request_uri)
  when :post
    Net::HTTP::Post.new(uri.request_uri)
  when :put
    Net::HTTP::Put.new(uri.request_uri)
  else
    raise ArgumentError, "Unsupported HTTP method: #{method}"
  end

  # Set headers
  request['Content-Type'] = 'application/json'
  request['X-ACCT-ID'] = 
  
  # Generate signature if body present
  if body
    json_body = body.to_json
    request['X-PAYLOAD-SIG'] = generate_signature(json_body)
    request.body = json_body
  end

  # Make request
  response = http.request(request)
  
  # Parse response
  handle_response(response)
end