Class: Stannp::Resource

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Resource

Returns a new instance of Resource.



5
6
7
# File 'lib/stannp/resource.rb', line 5

def initialize(client:)
  @client = client
end

Instance Method Details

#get_request(url, params: {}, headers: {}) ⇒ Object



9
10
11
# File 'lib/stannp/resource.rb', line 9

def get_request(url, params: {}, headers: {})
  handle_response(client.connection.get(url, params, headers))
end

#post_request(url, body:, headers: {}) ⇒ Object



13
14
15
# File 'lib/stannp/resource.rb', line 13

def post_request(url, body:, headers: {})
  handle_response client.connection.post(url, body, headers)
end

#url_for(path:, params: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/stannp/resource.rb', line 17

def url_for(path:, params: nil)
  url = "#{path}?api_key=#{client.api_key}"
  params&.each do |k, v|
    next unless v

    url += "&#{k}=#{v}"
  end
  url
end