Class: Catchpoint
- Inherits:
-
Object
- Object
- Catchpoint
- Defined in:
- lib/catchpoint.rb
Instance Method Summary collapse
- #delete(endpoint, opts = {}) ⇒ Object
- #fetch_token ⇒ Object
- #get(endpoint, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Catchpoint
constructor
A new instance of Catchpoint.
- #post(endpoint, opts = {}) ⇒ Object
- #put(endpoint, opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Catchpoint
17 18 19 20 21 22 23 24 25 |
# File 'lib/catchpoint.rb', line 17 def initialize opts={} @key = opts["key"] || ENV['CATCHPOINT_KEY'] @secret = opts["secret"] || ENV['CATCHPOINT_SECRET'] @token_url = '/ui/api/token' @prefix = '/ui/api/v1' @host = 'https://io.catchpoint.com' @version = 1 @token = nil end |
Instance Method Details
#delete(endpoint, opts = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/catchpoint.rb', line 48 def delete endpoint,opts={} fetch_token unless @token res = @token.delete("#{@prefix}#{endpoint}",opts) JSON.parse(res.body) end |
#fetch_token ⇒ Object
27 28 29 30 |
# File 'lib/catchpoint.rb', line 27 def fetch_token client = OAuth2::Client.new(@key,@secret, site: @host, :token_url => @token_url) @token = client.client_credentials.get_token() end |
#get(endpoint, opts = {}) ⇒ Object
32 33 34 35 36 |
# File 'lib/catchpoint.rb', line 32 def get endpoint,opts={} fetch_token unless @token res = @token.get("#{@prefix}#{endpoint}",opts) JSON.parse(res.body) end |
#post(endpoint, opts = {}) ⇒ Object
38 39 40 41 42 |
# File 'lib/catchpoint.rb', line 38 def post endpoint,opts={} fetch_token unless @token res = @token.post("#{@prefix}#{endpoint}",opts) JSON.parse(res.body) end |
#put(endpoint, opts = {}) ⇒ Object
43 44 45 46 47 |
# File 'lib/catchpoint.rb', line 43 def put endpoint,opts={} fetch_token unless @token res = @token.put("#{@prefix}#{endpoint}",opts) JSON.parse(res.body) end |