Class: Button::Resource
- Inherits:
-
Object
- Object
- Button::Resource
- Defined in:
- lib/button/resources/resource.rb
Overview
Resource is a handy base class for making API requests. It includes serveral handy methods for making such requests:
api_get(path) api_post(path, body) api_delete(path)
## Usage
class Blorp < Button::Resource
def get(blorp_id)
api_get("/api/v1/blorps/#{blorp_id}")
end
end
Direct Known Subclasses
Constant Summary collapse
- HOST =
'api.usebutton.com'.freeze
- PORT =
443- USER_AGENT =
"Button/#{Button::VERSION} ruby/#{RUBY_VERSION}".freeze
Instance Method Summary collapse
-
#api_delete(path) ⇒ Button::Response
Performs an HTTP DELETE at the provided path.
-
#api_get(path) ⇒ Button::Response
Performs an HTTP GET at the provided path.
-
#api_post(path, body) ⇒ Button::Response
Performs an HTTP POST at the provided path.
-
#initialize(api_key) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(api_key) ⇒ Resource
Returns a new instance of Resource.
31 32 33 34 35 |
# File 'lib/button/resources/resource.rb', line 31 def initialize(api_key) @api_key = api_key @http = Net::HTTP.new(HOST, PORT) @http.use_ssl = true end |
Instance Method Details
#api_delete(path) ⇒ Button::Response
Performs an HTTP DELETE at the provided path.
61 62 63 |
# File 'lib/button/resources/resource.rb', line 61 def api_delete(path) api_request(Net::HTTP::Delete.new(path)) end |
#api_get(path) ⇒ Button::Response
Performs an HTTP GET at the provided path.
42 43 44 |
# File 'lib/button/resources/resource.rb', line 42 def api_get(path) api_request(Net::HTTP::Get.new(path)) end |
#api_post(path, body) ⇒ Button::Response
Performs an HTTP POST at the provided path.
52 53 54 |
# File 'lib/button/resources/resource.rb', line 52 def api_post(path, body) api_request(Net::HTTP::Post.new(path), body) end |